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 u8)

🔬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