cairo_lang_utils::ordered_hash_map

Struct OrderedHashMap

source
pub struct OrderedHashMap<Key, Value, BH = RandomState>(/* private fields */);

Implementations§

source§

impl<Key, Value, BH> OrderedHashMap<Key, Value, BH>

source

pub fn iter(&self) -> Iter<'_, Key, Value>

Returns an iterator over the key-value pairs of the map, in their order.

source

pub fn iter_mut(&mut self) -> IterMut<'_, Key, Value>

Returns a mutable iterator over the key-value pairs of the map, in their order.

source

pub fn keys(&self) -> Keys<'_, Key, Value>

Returns an iterator over the keys of the map, in their order.

source

pub fn into_keys(self) -> IntoKeys<Key, Value>

Returns a consuming iterator over the keys of the map, in their order.

source

pub fn values(&self) -> Values<'_, Key, Value>

Returns an iterator over the values of the map, in their order.

source

pub fn len(&self) -> usize

Returns the number of key-value pairs in the map.

source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

source

pub fn clear(&mut self)

Removes all the entries for the map.

source

pub fn shift_remove_index(&mut self, index: usize) -> Option<(Key, Value)>

Removes the entry at the given index.

Returns the key-value pair at the given index (if present).

source§

impl<Key: Eq + Hash, Value, BH: BuildHasher> OrderedHashMap<Key, Value, BH>

source

pub fn get<Q: ?Sized + Hash + Equivalent<Key>>(&self, key: &Q) -> Option<&Value>

Returns a reference to the value stored for key, if it is present, else None.

Computes in O(1) time (average).

source

pub fn get_mut<Q: ?Sized + Hash + Equivalent<Key>>( &mut self, key: &Q, ) -> Option<&mut Value>

Returns a mutable reference to the value stored for key, if it is present, else None.

Computes in O(1) time (average).

source

pub fn entry(&mut self, key: Key) -> Entry<'_, Key, Value>

Gets the given key’s corresponding entry in the map for insertion and/or in-place manipulation.

Computes in O(1) time (amortized average).

source

pub fn insert(&mut self, key: Key, value: Value) -> Option<Value>

Insert a key-value pair in the map.

If an equivalent key already exists in the map: the key remains and retains in its place in the order, its corresponding value is updated with value and the older value is returned inside Some(_).

If no equivalent key existed in the map: the new key-value pair is inserted, last in order, and None is returned.

Computes in O(1) time (amortized average).

See also entry if you you want to insert or modify or if you need to get the index of the corresponding key-value pair.

source

pub fn extend<I: IntoIterator<Item = (Key, Value)>>(&mut self, iter: I)

Extends the map with the content of the given iterator.

source

pub fn contains_key<Q: ?Sized + Hash + Equivalent<Key>>(&self, key: &Q) -> bool

Returns true if an equivalent to key exists in the map.

source

pub fn shift_remove<Q: ?Sized + Hash + Equivalent<Key>>( &mut self, key: &Q, ) -> Option<Value>

Removes the entry for the given key, preserving the order of entries.

Returns the value associated with the key (if present).

source

pub fn swap_remove<Q: ?Sized + Hash + Equivalent<Key>>( &mut self, key: &Q, ) -> Option<Value>

Removes the entry for the given key by swapping it with the last element. Thus the order of elements is not preserved, but the resulting order is still deterministic.

Returns the value associated with the key (if present).

source

pub fn retain(&mut self, keep: impl FnMut(&Key, &mut Value) -> bool)

Scan through each key-value pair in the map and keep those where the closure keep returns true.

The elements are visited in order, and remaining elements keep their order.

Computes in O(n) time (average).

source

pub fn eq_unordered(&self, other: &Self) -> bool
where Value: Eq,

Returns true if the maps are equal, ignoring the order of the entries.

Trait Implementations§

source§

impl<Key: Clone, Value: Clone, BH: Clone> Clone for OrderedHashMap<Key, Value, BH>

source§

fn clone(&self) -> OrderedHashMap<Key, Value, BH>

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<Key: Debug, Value: Debug, BH: Debug> Debug for OrderedHashMap<Key, Value, BH>

source§

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

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

impl<Key, Value, BH: Default> Default for OrderedHashMap<Key, Value, BH>

source§

fn default() -> Self

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

impl<Key: Hash + Eq, Value, BH: BuildHasher + Default, const N: usize> From<[(Key, Value); N]> for OrderedHashMap<Key, Value, BH>

source§

fn from(init_map: [(Key, Value); N]) -> Self

Converts to this type from the input type.
source§

impl<Key: Hash + Eq, Value, BH: BuildHasher + Default> FromIterator<(Key, Value)> for OrderedHashMap<Key, Value, BH>

source§

fn from_iter<T: IntoIterator<Item = (Key, Value)>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<Key, Value, Q, BH> Index<&Q> for OrderedHashMap<Key, Value, BH>
where Q: Hash + Equivalent<Key> + ?Sized, Key: Hash + Eq, BH: BuildHasher,

source§

type Output = Value

The returned type after indexing.
source§

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

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

impl<Key, Value, Q, BH> IndexMut<&Q> for OrderedHashMap<Key, Value, BH>
where Q: Hash + Equivalent<Key> + ?Sized, Key: Hash + Eq, BH: BuildHasher,

source§

fn index_mut(&mut self, index: &Q) -> &mut Value

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

impl<Key, Value, BH> IntoIterator for OrderedHashMap<Key, Value, BH>

source§

type Item = (Key, Value)

The type of the elements being iterated over.
source§

type IntoIter = IntoIter<Key, Value>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<Key: Eq, Value: Eq, BH> PartialEq for OrderedHashMap<Key, Value, BH>

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<Key: Hash + Eq, Value: Eq, BH: BuildHasher> Eq for OrderedHashMap<Key, Value, BH>

Auto Trait Implementations§

§

impl<Key, Value, BH> Freeze for OrderedHashMap<Key, Value, BH>
where BH: Freeze,

§

impl<Key, Value, BH> RefUnwindSafe for OrderedHashMap<Key, Value, BH>
where BH: RefUnwindSafe, Key: RefUnwindSafe, Value: RefUnwindSafe,

§

impl<Key, Value, BH> Send for OrderedHashMap<Key, Value, BH>
where BH: Send, Key: Send, Value: Send,

§

impl<Key, Value, BH> Sync for OrderedHashMap<Key, Value, BH>
where BH: Sync, Key: Sync, Value: Sync,

§

impl<Key, Value, BH> Unpin for OrderedHashMap<Key, Value, BH>
where BH: Unpin, Key: Unpin, Value: Unpin,

§

impl<Key, Value, BH> UnwindSafe for OrderedHashMap<Key, Value, BH>
where BH: UnwindSafe, Key: UnwindSafe, Value: UnwindSafe,

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, 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

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, 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> 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> Upcast<T> for T
where T: ?Sized,

source§

fn upcast(&self) -> &T

source§

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

source§

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