Struct iset::IntervalMap[][src]

pub struct IntervalMap<T: PartialOrd + Copy, V, Ix: IndexType = DefaultIx> { /* fields omitted */ }
Expand description

Map with interval keys (ranges x..y).

Range bounds should implement PartialOrd and Copy, for example any integer or float types. However, you cannot use values that cannot be used in comparison (such as NAN). There are no restrictions on values.

let mut map = iset::IntervalMap::new();
map.insert(20..30, "a");
map.insert(15..25, "b");
map.insert(10..20, "c");

let a: Vec<_> = map.iter(..).collect();
assert_eq!(a, &[(10..20, &"c"), (15..25, &"b"), (20..30, &"a")]);

// Iterate over intervals that overlap query (..20 here). Output is sorted.
let b: Vec<_> = map.intervals(..20).collect();
assert_eq!(b, &[10..20, 15..25]);

// Iterate over values that overlap query (20.. here). Output is sorted by intervals.
let c: Vec<_> = map.values(20..).collect();
assert_eq!(c, &[&"b", &"a"]);

Insertion takes O(log N) and search takes O(log N + K) where K is the size of the output.

You can use insert only intervals of type x..y but you can search using any query that implements RangeBounds, for example (x..y, x..=y, x.., ..=y and so on). Functions overlap, intervals_overlap and values_overlap allow to search for intervals/values that overlap a single point (same as x..=x).

Additionally, you can use mutable iterators iter_mut, values_mut as well as overlap_mut and values_overlap_mut.

You can get a value that corresponds to the smallest or largest interval in O(log N).

You can construct IntervalMap using collect():

let map: iset::IntervalMap<_, _> = vec![(10..20, "a"), (0..20, "b")]
                                       .into_iter().collect();

You can also construct IntervalMap using interval_map macro:

#[macro_use] extern crate iset;

let map = interval_map!{ 0..10 => "a", 5..15 => "b", -5..20 => "c" };
let a: Vec<_> = map.iter(..).collect();
assert_eq!(a, &[(-5..20, &"c"), (0..10, &"a"), (5..15, &"b")]);

Index types:

You can specify index type (for example u32 and u64) used in the inner representation of IntervalMap.

Method new, macro interval_map or function collect() create IntervalMap with index type u32. If you wish to use another index type you can use methods default or with_capacity. For example:

let mut map: iset::IntervalMap<_, _, u64> = iset::IntervalMap::default();
map.insert(10..20, "a");

See IndexType for details.

Implementations

Creates an empty IntervalMap.

Creates an empty IntervalMap with capacity.

Shrinks inner contents.

Inserts an interval x..y and its value. Takes O(log N).

Panics if interval is empty (start >= end) or contains a value that cannot be compared (such as NAN).

Iterates over pairs (x..y, &value) that overlap the query. Takes O(log N + K) where K is the size of the output. Output is sorted by intervals, but not by values.

Panics if interval is empty or contains a value that cannot be compared (such as NAN).

Iterates over intervals x..y that overlap the query. See iter for more details.

Iterates over values that overlap the query. See iter for more details.

Iterator over pairs (x..y, &mut value) that overlap the query. See iter for more details.

Iterator over mutable values that overlap the query. See iter for more details.

Consumes IntervalMap and iterates over pairs (x..y, value) that overlap the query. See iter for more details.

Iterates over pairs (x..y, &value) that overlap the point. See iter for more details.

Iterates over intervals x..y that overlap the point. See iter for more details.

Iterates over values that overlap the point. See iter for more details.

Iterator over pairs (x..y, &mut value) that overlap the point. See iter for more details.

Iterates over mutable values that overlap the point. See iter for more details.

Returns the pair (x..y, &value) with the smallest x..y (intervals are sorted lexicographically). Takes O(log N). Returns None if the map is empty.

Returns the pair (x..y, &mut value) with the smallest x..y (intervals are sorted lexicographically). Takes O(log N). Returns None if the map is empty.

Returns the pair (x..y, &value) with the largest x..y (intervals are sorted lexicographically). Takes O(log N). Returns None if the map is empty.

Returns the pair (x..y, &mut value) with the largest x..y (intervals are sorted lexicographically). Takes O(log N). Returns None if the map is empty.

Write dot file to writer. T and V should implement Display.

Write dot file to writer without values. T should implement Display.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Construct IntervalMap from pairs (x..y, value).

Creates a value from an iterator. Read more

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.