Skip to main content

Crate odsek

Crate odsek 

Source
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

  • EndpointOC supports explicitly open or closed boundaries.
  • EndpointSymmetric represents 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§

EndpointSymmetric
An endpoint without an explicit open/closed tag.
Interval
A range between two endpoints carrying an attached value.
IntervalShift
Translate an Intervals stream by a constant offset.
IntervalStretch
Scale an Intervals stream by a constant multiplicative factor.
IntervalsAnd
Intersection of two Intervals streams.
IntervalsCache
Memoizes the most recent Intervals::head call.
IntervalsEndpointMap
An Intervals stream produced by transforming the endpoint values of an inner stream through a forward / inverse function pair.
IntervalsFromArray
An Intervals stream backed by a borrowed slice of pre-sorted Intervals.
IntervalsIntoIter
Forward Iterator over an Intervals stream, produced by IntoIntervals::into_iter.
IntervalsMap
An Intervals stream whose values are produced by applying a function to the values of an inner stream.
IntervalsOr
Union of two Intervals streams.
IntervalsSingle
An Intervals stream containing a single Interval.
IntervalsWrap
A passthrough wrapper used as the result type of the and and or free functions.

Enums§

EndpointOC
An endpoint that is explicitly tagged as either Open (exclusive) or Closed (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§

EndpointMap
Apply an in-place transform to the underlying endpoint value, preserving the open/closed flavor.
EndpointMapInto
Like EndpointMap, but allows the underlying value type to change (e.g. i32i64).
EndpointToggle
Toggle the open/closed flavor of an endpoint value.
InIntervalsMap
Adapter trait providing the .map(fun) builder method on any Intervals.
InIntervalsMapEndpoints
Adapter trait providing the .map_endpoints(forward, inverse) builder method on any Intervals.
Intervals
An ordered, non-overlapping stream of intervals queried by position.
IntoIntervals
Adapter that turns any Intervals stream into a standard Iterator.

Functions§

and
Compose two Intervals into their intersection.
and_cached
Like and, but wraps the result in an IntervalsCache.
endpoint_symmetric
Convenience constructor for EndpointSymmetric.
or
Compose two Intervals into their union.
or_cached
Like or, but wraps the result in an IntervalsCache.