pub struct SpanMap<K, V>{ /* private fields */ }Expand description
A map that associates spans (ranges) with sets of values.
SpanMap maintains a mapping between spans and sets of values, where:
- Each span represents a continuous range with well-defined boundaries
- Multiple values can be associated with the same span
- Spans can overlap, resulting in points that contain multiple values
- Queries at any point return all values associated with spans containing that point
The implementation uses a B-tree based data structure for efficient operations.
§Type Parameters
K: The type of the keys defining span boundaries. Must implementCloneandOrd.V: The type of values stored in the sets. Must implementCloneandOrd.
Implementations§
Source§impl<K, V> SpanMap<K, V>
impl<K, V> SpanMap<K, V>
Sourcepub fn get(&self, key: &K) -> impl Iterator<Item = &V>
pub fn get(&self, key: &K) -> impl Iterator<Item = &V>
Returns an iterator over all values associated with spans containing the given key.
Sourcepub fn values<R>(&self, range: R) -> BTreeSet<&V>where
R: RangeBounds<K>,
pub fn values<R>(&self, range: R) -> BTreeSet<&V>where
R: RangeBounds<K>,
Returns all unique values associated with spans that overlap the given range.
This method collects all values from sets that are associated with spans intersecting the input range. Values are deduplicated and returned in sorted order.
§Examples
use span_map::SpanMap;
let mut map = SpanMap::new();
map.insert(0..10, "a");
map.insert(5..15, "b");
map.insert(12..20, "c");
let values: Vec<_> = map.values(5..12).into_iter().collect();
assert_eq!(values, vec![&"a", &"b"]);Sourcepub fn insert<R>(&mut self, range: R, value: V)where
R: RangeBounds<K>,
pub fn insert<R>(&mut self, range: R, value: V)where
R: RangeBounds<K>,
Inserts a value into all sets associated with spans overlapping the given range.
Adjacent ranges with the same value are merged into a single range.
Sourcepub fn remove<R>(&mut self, range: R, value: V)where
R: RangeBounds<K>,
pub fn remove<R>(&mut self, range: R, value: V)where
R: RangeBounds<K>,
Removes a value from all sets associated with spans overlapping the given range.
Adjacent ranges with the same value are merged into a single range.