HashMap

Struct HashMap 

Source
pub struct HashMap<K: 'static, V: 'static, S = FixedState> { /* private fields */ }
Expand description

High-Performance Lock-Free Map.

Implementations§

Source§

impl<K, V> HashMap<K, V, FixedState>
where K: Hash + Eq + Clone + 'static, V: Clone + 'static,

Source

pub fn new() -> Self

Creates a new empty hash map with FoldHash (FixedState).

Source§

impl<K, V, S> HashMap<K, V, S>
where K: Hash + Eq + Clone + 'static, V: Clone + 'static, S: BuildHasher,

Source

pub fn with_hasher(hasher: S) -> Self

Creates a new hash map with custom hasher.

Source

pub fn get<Q>(&self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Optimized get operation.

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Checks if the key exists.

Source

pub fn insert(&self, key: K, value: V) -> Option<V>

Insert a key-value pair.

Source

pub fn insert_if_absent(&self, key: K, value: V) -> Option<V>

Insert a key-value pair only if the key does not exist. Returns None if inserted, Some(existing_value) if the key already exists.

Source

pub fn remove<Q>(&self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Remove a key-value pair.

Source

pub fn clear(&self)

Clear the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map is empty.

Source

pub fn len(&self) -> usize

Returns the number of elements in the map. Note: This is an O(N) operation as it scans all buckets.

Source

pub fn iter(&self) -> Iter<'_, K, V, S>

Returns an iterator over the map entries. Yields (K, V) clones.

Source

pub fn keys(&self) -> Keys<'_, K, V, S>

Returns an iterator over the map keys. Yields K clones.

Source

pub fn hasher(&self) -> &S

Get the underlying hasher itself.

Trait Implementations§

Source§

impl<K, V> Default for HashMap<K, V, FixedState>
where K: Hash + Eq + Clone + 'static, V: Clone + 'static,

Available on crate feature std only.
Source§

fn default() -> Self

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

impl<K, V, S> Drop for HashMap<K, V, S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S>
where K: Hash + Eq + Clone + 'static, V: Clone + 'static, S: BuildHasher,

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, V, S>

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<K: Send, V: Send, S: Send> Send for HashMap<K, V, S>

Source§

impl<K: Sync, V: Sync, S: Sync> Sync for HashMap<K, V, S>

Auto Trait Implementations§

§

impl<K, V, S> Freeze for HashMap<K, V, S>
where S: Freeze,

§

impl<K, V, S> RefUnwindSafe for HashMap<K, V, S>

§

impl<K, V, S> Unpin for HashMap<K, V, S>
where S: Unpin,

§

impl<K, V, S> UnwindSafe for HashMap<K, V, S>

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