intervalsets
intervalsets
is a family of crates for working with intervals and numeric sets.
intervalsets-core
no-std, no-alloc functionality.intervalsets
extended functionality requiring allocation.
This guide is intended to cover information applicable to the family of crates.
For specifics see the intervalsets-core
or intervalsets
api documentation.
Version
Limitations
This family of crates is intended to provide robust, general implementations
of intervals with a convenient Set
based api, and support pluggable
user provided data-types. While attention has been given to performance,
there are many optimizations that can not be included without a loss of generality.
Currently interval arithmetic is not supported, and while it may be in the future, it will never be as performant as a specialized library like inari.
Contributing
Contributions are welcome.
License
intervalsets
is released under the MIT license
.
api
types
Case | Core Implementation | Main Implementation |
---|---|---|
Empty Set | FiniteInterval | Interval |
Fully Bounded | FiniteInterval | Interval |
Left Bounded | HalfInterval | Interval |
Right Bounded | HalfInterval | Interval |
Unbounded | EnumInterval | Interval |
Disjoint | — | IntervalSet |
operations
Most operations are provided via traits in order to present a consistent, easy to use API for each type.
Operation | Op Type | Core | Main | Description |
---|---|---|---|---|
Contains | predicate | ✓ | ✓ | Test if A is a superset of B |
Intersects | predicate | ✓ | ✓ | Test for some shared element of A and B |
Connects | predicate | ✓ | ✓ | Test if sets are connected |
Width | measure | ✓ | ✓ | Find the width/diameter/length of a set |
Count | measure | ✓ | ✓ | Count the elements of a set |
Intersection | binary | ✓ | ✓ | The intersection set of two sets |
TryMerge | binary | ✓ | ✓ | The union of two connected sets |
Split | function | ✓ | ✓ | Two sets partitioned by some element |
IntoFinite | unary | ✓ | ✓ | Convert to a finite interval limited by element type |
Complement | unary | — | ✓ | The (possibly disjoint) complement of a set |
Union | binary | — | ✓ | The (possibly disjoint) union of two sets |
Difference | binary | — | ✓ | The (possibly disjoint) difference of set A from B |
SymDifference | binary | — | ✓ | The (possibly disjoint) symmetric difference of two sets |
Examples
Filter overlapping intervals
Goals
intervalsets
intends to provide flexible, reliable tools
for working with intervals and numeric sets.
Correctness
None of the other goals matter if the results can't be trusted.
There is an extensive test suite to ensure that operations produce the intended results.
Generality
All set and interval types provided are generic over the type of element in the set.
Portability
These are low level abstractions which should be deployable in almost any environment.
intervalsets-core
, by default, should be usable in any embedded environment - with or
without an allocator. The crate does provide some optional features for externally defined
element-types
that require allocation. These must live in intervalsets-core
due to rust's
orphan rule since the required traits
are defined there.
intervalsets
should be usable in a no-std environment but does require an allocator to
support collections of intervals.
Robustness
Fault tolerance is critical, especially in embedded environments.
Performance
todo:
Ease of use
todo:
Types
Errors
Footguns
Normalized Conversions
Most of the time normalization is transparent to the user, but it is a potential source of error, particularly when converting types that have implicit open bounds.
Floating Point Types
Making Ord
a trait bound for most APIs would eliminate a whole class of errors
(TotalOrderError), but floats come with a whole host of complexities regardless.
NAN
is not part of the default ordering, though there is atotal_cmp
available now.- rounding error can cause issues with testing values near a finite bound.
FiniteBound(f32::INFINITY)
andFiniteBound(f32::NEG_INFINITY)
are both valid syntax, though all manner of headache inducing semantically speaking.
Sometimes, floats are still the right tool for the job, and it is left to the
user to choose the right approach for the given problem. Fixed precision
decimal types like rust_decimal
do side step some pitfalls.
Fallibility
Silent failures can make it difficult to isolate logic errors as they are able to propogate further from their source before detection.