Struct budvm::budmap::BudMap

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

source

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,

source

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.

source

pub const fn with_hasher(hash_builder: HashBuilder) -> Self

Returns an empty map whose keys are hashed using hash_builder.

source

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.

source

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.

source

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.

source

pub fn len(&self) -> usize

Returns the number of entries contained in this map.

source

pub fn is_empty(&self) -> bool

Returns true if no entries are contained in this map.

source

pub fn get(&self, key: &Key) -> Option<&Value>

Returns a value for a given key.

source

pub fn get_by_index(&self, index: usize) -> Option<&Value>

Returns a value for a given 0-based index.

source

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

Returns an interator for this map.

Trait Implementations§

source§

impl<Key: Clone, Value: Clone, HashBuilder: Clone> Clone for BudMap<Key, Value, HashBuilder>

source§

fn clone(&self) -> BudMap<Key, Value, HashBuilder>

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, HashBuilder: Debug> Debug for BudMap<Key, Value, HashBuilder>

source§

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

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

impl<Key, Value> Default for BudMap<Key, Value, RandomState>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<Key, Value, HashBuilder> RefUnwindSafe for BudMap<Key, Value, HashBuilder>where HashBuilder: RefUnwindSafe, Key: RefUnwindSafe, Value: RefUnwindSafe,

§

impl<Key, Value, HashBuilder> Send for BudMap<Key, Value, HashBuilder>where HashBuilder: Send, Key: Send, Value: Send,

§

impl<Key, Value, HashBuilder> Sync for BudMap<Key, Value, HashBuilder>where HashBuilder: Sync, Key: Sync, Value: Sync,

§

impl<Key, Value, HashBuilder> Unpin for BudMap<Key, Value, HashBuilder>where HashBuilder: Unpin, Key: Unpin, Value: Unpin,

§

impl<Key, Value, HashBuilder> UnwindSafe for BudMap<Key, Value, HashBuilder>where HashBuilder: UnwindSafe, Key: UnwindSafe, Value: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.