3 stable releases
new 1.1.0 | Feb 11, 2025 |
---|---|
1.0.1 | Feb 9, 2025 |
#688 in Data structures
73 downloads per month
120KB
2.5K
SLoC
Closed interval set: disjoint unions of closed intervals
Real documentation on docs.rs.
There's a plethora of crates that manipulate sets of values represented as sets of intervals. This crate targets what appears to be a gap in the current (February 2025) offering:
- Support for all standard machine integer (include 128-bit integers) as endpoints
- Ability to represent the universe
[T::MIN, T::MAX
] - No unchecked overflow
The closed-interval-set
crate offers all that, for arbitrary types
that implement its Endpoint
trait, and comes with an implementation
of that trait for the 12 standard integer types, as well as for 32 and
64 -bit floats.
The crate is designed for usage patterns where sets are constructed
ahead of time (perhaps by combining different sets together), then
frozen (as SmallVec<[(T, T); 2]>
, internally) for read-only access.
However, its iterator implementations of set complementation, union,
and intersection are closed over the NormalizedRangeIter
trait, so
it's feasible to build up a complex expression (not so complex to need
type erasure though) before materializing the result to a RangeVec
.
Related crates
normalize_interval : same idea of normalizing integer ranges to closed intervals.
Many crates can handle the more complex case where we wish to track overlapping ranges individually (e.g., iset, or nested_intervals).
The range-set-blaze is similar to this crate, and intervallum even closer, but neither handles the full range of u128 or i128.
Dependencies
~66KB