Skip to main content

ImmutableHashTable

Trait ImmutableHashTable 

Source
pub trait ImmutableHashTable<TKey, TValue>
where TKey: Hash + Eq,
{ // Required methods fn length(&self) -> Length; fn contains<Q>(&self, key: &Q) -> bool where TKey: Borrow<Q>, Q: Eq + Hash + ?Sized; fn get<Q>(&self, key: &Q) -> Option<&TValue> where TKey: Borrow<Q>, Q: Eq + Hash + ?Sized; fn get_key_value<Q>(&self, key: &Q) -> Option<(&TKey, &TValue)> where TKey: Borrow<Q>, Q: Eq + Hash + ?Sized; fn iter<'a>(&'a self) -> impl Iterator<Item = (&'a TKey, &'a TValue)> where TKey: 'a, TValue: 'a, Self: 'a; // Provided method fn is_empty(&self) -> bool { ... } }
Expand description

Represents an immutable hash table.

Required Methods§

Source

fn length(&self) -> Length

Returns the number of (TKey, TValue) pairs the table contains. This typically does not correspond to the actual size of the table in bytes.

Source

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

Checks if the table contains the corresponding key.

§Notes

The borrowed Q type’s Hash and Eq must match those for TKey.

Source

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

Checks if the table contains the corresponding key, and if so then returns the reference to the TValue, or None otherwise.

§Notes

The borrowed Q type’s Hash and Eq must match those for TKey.

Source

fn get_key_value<Q>(&self, key: &Q) -> Option<(&TKey, &TValue)>
where TKey: Borrow<Q>, Q: Eq + Hash + ?Sized,

Checks if the table contains the corresponding key, and if so then returns the (&TKey, &TValue) pair or None otherwise.

§Notes

The borrowed Q type’s Hash and Eq must match those for TKey.

Source

fn iter<'a>(&'a self) -> impl Iterator<Item = (&'a TKey, &'a TValue)>
where TKey: 'a, TValue: 'a, Self: 'a,

Returns an iterator over the key-value pairs in the table.

§Notes

The iterator yields (&TKey, &TValue) tuples representing each key-value pair in the hash table.

Provided Methods§

Source

fn is_empty(&self) -> bool

Checks if the table is empty. This does not mean that it doesn’t take space in memory. Equivalent to self.length() == 0 check.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<TKey, TValue> ImmutableHashTable<TKey, TValue> for HashMap<TKey, TValue>
where TKey: Hash + Eq,

Available on crate feature std only.
Source§

fn length(&self) -> Length

Source§

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

Source§

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

Source§

fn get_key_value<Q>(&self, key: &Q) -> Option<(&TKey, &TValue)>
where TKey: Borrow<Q>, Q: Eq + Hash + ?Sized,

Source§

fn iter<'a>(&'a self) -> impl Iterator<Item = (&'a TKey, &'a TValue)>
where TKey: 'a, TValue: 'a, Self: 'a,

Implementors§

Source§

impl<TKey, TValue, TAllocator> ImmutableHashTable<TKey, TValue> for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: Eq + Hash, TAllocator: Allocator,

Source§

impl<TKey, TValue, TConfig> ImmutableHashTable<TKey, TValue> for BytellHashTable<TKey, TValue, TConfig>
where TKey: Eq + Hash, TConfig: BytellConfig,