rustc_data_structures::sorted_map

Struct SortedIndexMultiMap

Source
pub struct SortedIndexMultiMap<I: Idx, K, V> {
    items: IndexVec<I, (K, V)>,
    idx_sorted_by_item_key: Vec<I>,
}
Expand description

An indexed multi-map that preserves insertion order while permitting both O(log n) lookup of an item by key and O(1) lookup by index.

This data structure is a hybrid of an [IndexVec] and a SortedMap. Like IndexVec, SortedIndexMultiMap assigns a typed index to each item while preserving insertion order. Like SortedMap, SortedIndexMultiMap has efficient lookup of items by key. However, this is accomplished by sorting an array of item indices instead of the items themselves.

Unlike SortedMap, this data structure can hold multiple equivalent items at once, so the get_by_key method and its variants return an iterator instead of an Option. Equivalent items will be yielded in insertion order.

Unlike a general-purpose map like BTreeSet or HashSet, SortedMap and SortedIndexMultiMap require O(n) time to insert a single item. This is because we may need to insert into the middle of the sorted array. Users should avoid mutating this data structure in-place.

Fields§

§items: IndexVec<I, (K, V)>

The elements of the map in insertion order.

§idx_sorted_by_item_key: Vec<I>

Indices of the items in the set, sorted by the item’s key.

Implementations§

Source§

impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V>

Source

pub fn new() -> Self

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn into_iter(self) -> impl DoubleEndedIterator<Item = (K, V)>

Returns an iterator over the items in the map in insertion order.

Source

pub fn into_iter_enumerated( self, ) -> impl DoubleEndedIterator<Item = (I, (K, V))>

Returns an iterator over the items in the map in insertion order along with their indices.

Source

pub fn iter(&self) -> impl '_ + DoubleEndedIterator<Item = (&K, &V)>

Returns an iterator over the items in the map in insertion order.

Source

pub fn iter_enumerated( &self, ) -> impl '_ + DoubleEndedIterator<Item = (I, (&K, &V))>

Returns an iterator over the items in the map in insertion order along with their indices.

Source

pub fn get(&self, idx: I) -> Option<&(K, V)>

Returns the item in the map with the given index.

Source

pub fn get_by_key(&self, key: K) -> impl Iterator<Item = &V> + '_

Returns an iterator over the items in the map that are equal to key.

If there are multiple items that are equivalent to key, they will be yielded in insertion order.

Source

pub fn get_by_key_enumerated( &self, key: K, ) -> impl Iterator<Item = (I, &V)> + '_

Returns an iterator over the items in the map that are equal to key along with their indices.

If there are multiple items that are equivalent to key, they will be yielded in insertion order.

Source

pub fn contains_key(&self, key: K) -> bool

Trait Implementations§

Source§

impl<I: Clone + Idx, K: Clone, V: Clone> Clone for SortedIndexMultiMap<I, K, V>

Source§

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

Returns a copy 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<I: Debug + Idx, K: Debug, V: Debug> Debug for SortedIndexMultiMap<I, K, V>

Source§

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

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

impl<I: Idx, K: Ord, V> FromIterator<(K, V)> for SortedIndexMultiMap<I, K, V>

Source§

fn from_iter<J>(iter: J) -> Self
where J: IntoIterator<Item = (K, V)>,

Creates a value from an iterator. Read more
Source§

impl<I: Idx, K, V> Hash for SortedIndexMultiMap<I, K, V>
where K: Hash, V: Hash,

Source§

fn hash<H: Hasher>(&self, hasher: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<I: Idx, K, V, C> HashStable<C> for SortedIndexMultiMap<I, K, V>
where K: HashStable<C>, V: HashStable<C>,

Source§

fn hash_stable(&self, ctx: &mut C, hasher: &mut StableHasher)

Source§

impl<I: Idx, K, V> Index<I> for SortedIndexMultiMap<I, K, V>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, idx: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<I: Idx, K: PartialEq, V: PartialEq> PartialEq for SortedIndexMultiMap<I, K, V>

Source§

fn eq(&self, other: &Self) -> 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<I: Idx, K: Eq, V: Eq> Eq for SortedIndexMultiMap<I, K, V>

Auto Trait Implementations§

§

impl<I, K, V> DynSend for SortedIndexMultiMap<I, K, V>
where I: DynSend, K: DynSend, V: DynSend,

§

impl<I, K, V> DynSync for SortedIndexMultiMap<I, K, V>
where I: DynSync, K: DynSync, V: DynSync,

§

impl<I, K, V> Freeze for SortedIndexMultiMap<I, K, V>

§

impl<I, K, V> RefUnwindSafe for SortedIndexMultiMap<I, K, V>

§

impl<I, K, V> Send for SortedIndexMultiMap<I, K, V>
where K: Send, V: Send, I: Send,

§

impl<I, K, V> Sync for SortedIndexMultiMap<I, K, V>
where I: Sync, K: Sync, V: Sync,

§

impl<I, K, V> Unpin for SortedIndexMultiMap<I, K, V>
where I: Unpin, K: Unpin, V: Unpin,

§

impl<I, K, V> UnwindSafe for SortedIndexMultiMap<I, K, V>
where I: UnwindSafe, K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Aligned for T

Source§

const ALIGN: Alignment = const ALIGN: Alignment = Alignment::of::<Self>();

Alignment of Self.
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, dst: *mut T)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 48 bytes