SlotOrderMap
struct · ferroui-system · v0.5.0
struct SlotOrderMap<K, V>
A map from keys to values that enumerates its entries in the order of the slots of .NET's
Dictionary<TKey, TValue>: in the order they were added, except that an entry added after a
removal takes the slot of the entry removed last (the free list of .NET), and clear starts
over.
Code ported from .NET that enumerates a dictionary (its keys, values, or a Select over it)
produces the same sequence with this type. HashMap gives an arbitrary order, and
indexmap::IndexMap the order of addition, which differs from this one after a removal (with
shift_remove and with swap_remove): use HashMap where nothing enumerates the map,
IndexMap where the order of addition is what is observed, and this type only where the exact
.NET sequence after removals is (the caches of DynamicData, whose change sets list their items
in it).
Members
iteriter_mutkeysvaluesnewwith_capacitylenis_emptycontains_keygetget_mutinserttry_addaddremoveclear
iter
fn iter(self: &Self) -> impl Iterator<Item = (&K, &V)>
The entries in the order of enumeration.
iter_mut
fn iter_mut(self: &mut Self) -> impl Iterator<Item = (&K, &mut V)>
The entries in the order of enumeration, with their values to change.
keys
fn keys(self: &Self) -> impl Iterator<Item = &K>
The keys in the order of enumeration (Keys).
values
fn values(self: &Self) -> impl Iterator<Item = &V>
The values in the order of enumeration (Values).
new
fn new() -> Self
An empty map.
with_capacity
fn with_capacity(capacity: usize) -> Self
An empty map with room for capacity entries.
len
fn len(self: &Self) -> usize
The number of entries (Count).
is_empty
fn is_empty(self: &Self) -> bool
contains_key
fn contains_key<Q: Hash + Eq + ?Sized>(self: &Self, key: &Q) -> bool
where K: Borrow<Q>
Whether the map has key (ContainsKey).
get
fn get<Q: Hash + Eq + ?Sized>(self: &Self, key: &Q) -> Option<&V>
where K: Borrow<Q>
The value of key (TryGetValue).
get_mut
fn get_mut<Q: Hash + Eq + ?Sized>(self: &mut Self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>
The value of key, to change.
insert
fn insert(self: &mut Self, key: K, value: V) -> Option<V>
Sets the value of key (the indexer's setter, this[key] = value): an existing entry keeps
its place; the previous value is returned.
try_add
fn try_add(self: &mut Self, key: K, value: V) -> bool
Adds an entry unless the key is there already (TryAdd); false when it is.
add
fn add(self: &mut Self, key: K, value: V)
Adds an entry (Add).
Panics
When the key is there already (ArgumentException).
remove
fn remove<Q: Hash + Eq + ?Sized>(self: &mut Self, key: &Q) -> Option<V>
where K: Borrow<Q>
Removes the entry of key and gives its value (Remove(TKey, out TValue)).
clear
fn clear(self: &mut Self)
Removes every entry (Clear); the next entry is the first again.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedCloneDefaultDebugFromIterator<(K, V)>IntoIteratorExtend<(K, V)>PartialEq
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.