SpanMap

Struct SpanMap 

Source
pub struct SpanMap<K, V>
where K: Clone + Ord, V: Clone + Ord,
{ /* 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 implement Clone and Ord.
  • V: The type of values stored in the sets. Must implement Clone and Ord.

Implementations§

Source§

impl<K, V> SpanMap<K, V>
where K: Clone + Ord, V: Clone + Ord,

Source

pub fn new() -> Self

Creates a new, empty SpanMap.

The new map is initialized with an unbounded span containing an empty set.

Source§

impl<K, V> SpanMap<K, V>
where K: Clone + Ord, V: Clone + Ord,

Source

pub fn get(&self, key: &K) -> impl Iterator<Item = &V>

Returns an iterator over all values associated with spans containing the given key.

Source

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"]);
Source

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.

Source

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.

Trait Implementations§

Source§

impl<K, V> Clone for SpanMap<K, V>
where K: Clone + Ord + Clone, V: Clone + Ord + Clone,

Source§

fn clone(&self) -> SpanMap<K, V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V> Debug for SpanMap<K, V>
where K: Clone + Ord + Debug, V: Clone + Ord + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V> Default for SpanMap<K, V>
where K: Clone + Ord, V: Clone + Ord,

Source§

fn default() -> Self

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

impl<K, V> PartialEq for SpanMap<K, V>
where K: Clone + Ord + PartialEq, V: Clone + Ord + PartialEq,

Source§

fn eq(&self, other: &SpanMap<K, V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, V> Eq for SpanMap<K, V>
where K: Clone + Ord + Eq, V: Clone + Ord + Eq,

Source§

impl<K, V> StructuralPartialEq for SpanMap<K, V>
where K: Clone + Ord, V: Clone + Ord,

Auto Trait Implementations§

§

impl<K, V> Freeze for SpanMap<K, V>

§

impl<K, V> RefUnwindSafe for SpanMap<K, V>

§

impl<K, V> Send for SpanMap<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for SpanMap<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for SpanMap<K, V>

§

impl<K, V> UnwindSafe for SpanMap<K, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.