Expand description
§Lazy interval-set composition
odsek provides allocation-free, pull-based composition of ordered,
non-overlapping mathematical interval sets. Each Interval carries a
value, so intersections and unions can also be read as joins over tagged
segments.
The core API is no_std and does not allocate. Streams are queried through
Intervals::head, which returns the next interval after a requested
position; iteration and combinators are layered on top of that primitive.
§Endpoint flavors
EndpointOCsupports explicitly open or closed boundaries.EndpointSymmetricrepresents the common[a, b)convention: closed on the left, open on the right.
§Composition
With the default operators feature, & computes intersection and |
computes union. Disable default features to use the explicit and and
or functions instead.
§Examples
use odsek::*;
let ia = Interval::new(EndpointOC::Closed(1), EndpointOC::Closed(3), "A");
let ib = Interval::new(EndpointOC::Open(2), EndpointOC::Open(4), "B");
let isa = IntervalsSingle::new(ia);
let isb = IntervalsSingle::new(ib);
let and_ab = and(isa, isb);
let and_ab_vec = and_ab.into_iter().collect::<Vec<_>>();
assert_eq!(and_ab_vec.len(), 1);
assert_eq!(and_ab_vec[0], Interval::new(EndpointOC::Open(2), EndpointOC::Closed(3), ("A","B")));Structs§
- Endpoint
Symmetric - An endpoint without an explicit open/closed tag.
- Interval
- A range between two endpoints carrying an attached
value. - Interval
Shift - Translate an
Intervalsstream by a constant offset. - Interval
Stretch - Scale an
Intervalsstream by a constant multiplicative factor. - Intervals
And - Intersection of two
Intervalsstreams. - Intervals
Cache - Memoizes the most recent
Intervals::headcall. - Intervals
Endpoint Map - An
Intervalsstream produced by transforming the endpoint values of an inner stream through a forward / inverse function pair. - Intervals
From Array - An
Intervalsstream backed by a borrowed slice of pre-sortedIntervals. - Intervals
Into Iter - Forward
Iteratorover anIntervalsstream, produced byIntoIntervals::into_iter. - Intervals
Map - An
Intervalsstream whose values are produced by applying a function to the values of an inner stream. - Intervals
Or - Union of two
Intervalsstreams. - Intervals
Single - An
Intervalsstream containing a singleInterval. - Intervals
Wrap - A passthrough wrapper used as the result type of the
andandorfree functions.
Enums§
- EndpointOC
- An endpoint that is explicitly tagged as either
Open(exclusive) orClosed(inclusive). - LeftT
- Wraps an endpoint to mark it as the left (lower) side of an interval.
- RightT
- Wraps an endpoint to mark it as the right (upper) side of an interval.
Traits§
- Endpoint
Map - Apply an in-place transform to the underlying endpoint value, preserving the open/closed flavor.
- Endpoint
MapInto - Like
EndpointMap, but allows the underlying value type to change (e.g.i32→i64). - Endpoint
Toggle - Toggle the open/closed flavor of an endpoint value.
- InIntervals
Map - Adapter trait providing the
.map(fun)builder method on anyIntervals. - InIntervals
MapEndpoints - Adapter trait providing the
.map_endpoints(forward, inverse)builder method on anyIntervals. - Intervals
- An ordered, non-overlapping stream of intervals queried by position.
- Into
Intervals - Adapter that turns any
Intervalsstream into a standardIterator.
Functions§
- and
- Compose two
Intervalsinto their intersection. - and_
cached - Like
and, but wraps the result in anIntervalsCache. - endpoint_
symmetric - Convenience constructor for
EndpointSymmetric. - or
- Compose two
Intervalsinto their union. - or_
cached - Like
or, but wraps the result in anIntervalsCache.