pub struct BudMap<Key, Value, HashBuilder = RandomState> { /* private fields */ }
Expand description
A std::collections::HashMap
alternative that provides some guarantees on
entry order.
This implementation preserves insert order until an operation that removes a key occurs. To keep this implementation efficient, when a removal occurs, the order is updated by moving the last key inserted to replace the entry being removed.
The benefit of keeping the order is that an iterator can be made against this collection that doesn’t require borrowing the original value. Additionally, methods can be used to retrieve entries by index instead of just by key.
Implementations§
source§impl<Key, Value> BudMap<Key, Value, RandomState>where
Key: Eq + Hash + Debug,
impl<Key, Value> BudMap<Key, Value, RandomState>where Key: Eq + Hash + Debug,
sourcepub fn with_capacity(minimum_capacity: usize) -> Self
pub fn with_capacity(minimum_capacity: usize) -> Self
Returns an empty map with enough room for minimum_capacity
elements to
be inserted without allocations (assuming no hash collisions).
source§impl<Key, Value, HashBuilder> BudMap<Key, Value, HashBuilder>where
Key: Eq + Hash + Debug,
HashBuilder: BuildHasher,
impl<Key, Value, HashBuilder> BudMap<Key, Value, HashBuilder>where Key: Eq + Hash + Debug, HashBuilder: BuildHasher,
sourcepub fn with_capacity_and_hasher(
minimum_capacity: usize,
hash_builder: HashBuilder
) -> Self
pub fn with_capacity_and_hasher( minimum_capacity: usize, hash_builder: HashBuilder ) -> Self
Returns an empty map with enough room for minimum_capacity
elements to
be inserted without allocations (assuming no hash collisions). Keys are
hashed using hash_builder
.
sourcepub const fn with_hasher(hash_builder: HashBuilder) -> Self
pub const fn with_hasher(hash_builder: HashBuilder) -> Self
Returns an empty map whose keys are hashed using hash_builder
.
sourcepub fn entry(&mut self, key: Key) -> Entry<'_, Key, Value, HashBuilder>
pub fn entry(&mut self, key: Key) -> Entry<'_, Key, Value, HashBuilder>
Looks up an entry for key
. If one is found, Entry::Occupied
will
be returned. If one is not found, Entry::Vacant
will be returned.
sourcepub fn insert(&mut self, key: Key, value: Value) -> Option<Value>
pub fn insert(&mut self, key: Key, value: Value) -> Option<Value>
Inserts the key-value pair into the map. If an existing value was stored for the given key, it will be returned.
sourcepub fn remove(&mut self, key: &Key) -> Option<Value>
pub fn remove(&mut self, key: &Key) -> Option<Value>
Removes a key from the map. If the key was found, the value stored will be returned.
sourcepub fn get_by_index(&self, index: usize) -> Option<&Value>
pub fn get_by_index(&self, index: usize) -> Option<&Value>
Returns a value for a given 0-based index.