Giter Site home page Giter Site logo

zyigh / holedrange Goto Github PK

View Code? Open in Web Editor NEW

This project forked from krugazor/holedrange

0.0 1.0 0.0 25 KB

HoledRange is a class / collection of tools that allow you to deal with ranges that have holes in them

License: Apache License 2.0

Swift 100.00%

holedrange's Introduction

HoledRange

Motivation

I needed a way to have ranges with holes in them for another project. It's not exactly boilerplate code, but there were multiple instances where I had to deal with data matching and needed such a tool (especially on the union/intersection/symmetric difference side)

HoledRange works by being essentially a collection of ranges and as such tries to be as compatible as possible with general uses of regular ranges.

Usage

Like Range<T>, HoledRange<T> works with a Bound type in mind:

let h = HoledRange(1.2...7.3) or let h = HoledRange(42)

Bear in mind that Bound needs to conform to Comparable (for obvious reasons) and Hashable (for equality purposes).

If it also conforms to the custom protocol Randomizable (some obvious types have already been extended), you get the opportunity to grab samples from your range.

Union, Intersection, Symmetric Difference

There are two ways to use those operations:

  • in a mutable manner by calling the function -- it then modifies the callee
  • in an immutable way, by using the operators -- the original ranges aren't modified
var h = HoledRange(1...1)
h.union(HoledRange(2...2)) // h is modified

let o = h โŠ– HoledRange(2...2) // h is not modified

Set management

Adding, and removing, values or ranges is essential to the utility of this class. Be careful as it almost always calls optimizeStorage, which will rearrange the internal ranges as needed

Excluded values are stored separately to provide support for open ranges (this implementation uses ClosedRange<T> as storage)

Contributions

Feel free to report issues, submit PRs, etc.

As of this writing, I am the sole user of this package and as long as the unit tests pass, anything you deem useful to add or modify for your own needs is unlikely to cause any major issue.

holedrange's People

Contributors

krugazor avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.