Skip to main content

DefaultHashTable

Struct DefaultHashTable 

Source
pub struct DefaultHashTable<TKey, TValue, TAllocator>
where TKey: Eq + Hash, TAllocator: Allocator,
{ /* private fields */ }
Expand description

Represents the default hash table.

§Notes

At the moment it uses BytellHashTable as the underlying implementation. This can change in the future though.

Implementations§

Source§

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

Source

pub fn new() -> Self

Creates a new, empty DefaultHashTable with the default allocator.

Source

pub fn with_allocator(allocator: TAllocator) -> Self

Creates a new, empty DefaultHashTable with the specified allocator.

Source

pub fn with_capacity(capacity: Length) -> Result<Self, DefaultHashTableError>

Creates a new DefaultHashTable with the specified capacity and the default allocator.

This likely will (over)allocate memory.

§Errors

See DefaultHashTableError for details.

Source

pub fn with_capacity_and_allocator( capacity: Length, allocator: TAllocator, ) -> Result<Self, DefaultHashTableError>

Creates a new DefaultHashTable with the specified capacity and the specified allocator.

This likely will (over)allocate memory.

§Errors

See DefaultHashTableError for details.

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> DefaultHashTable<TKey, TValue, TAllocator>

Returns a duplicate 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<TKey, TValue, TAllocator> Default for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: Eq + Hash, TAllocator: Allocator,

Source§

fn default() -> Self

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

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

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

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

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. Read more
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. Read more
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. Read more
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. Read more
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.
Source§

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

Source§

fn insert(&mut self, key: TKey, value: TValue) -> Option<TValue>

Inserts given (TKey, TValue) pair into the table. Read more
Source§

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

Removes entire entry from the table. Returns (TKey, TValue) pair for the matching key or None if there is no match. Read more
Source§

fn insert_or_update_with<FAdd, FUpdate>( &mut self, key: TKey, adder: FAdd, updater: FUpdate, ) -> &mut TValue
where FAdd: FnOnce() -> TValue, FUpdate: FnOnce(&mut TValue),

Searches the table for a given key. If the table contains it, then it runs updater on the corresponding TValue. Otherwise runs adder to add a new TValue to the table. Returns the mutable reference to the final TValue. Read more
Source§

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

Returns a mutable iterator over the key-value pairs in the table. Read more
Source§

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

Removes entire entry from the table. Similar to MutableHashTable::remove_entry, but returns TValue only for the matching key or None if there is no match. Read more
Source§

fn get_or_insert_default(&mut self, key: TKey) -> &mut TValue
where TValue: Default,

Retrieves an existing TValue, or inserts a default one. Read more
Source§

fn get_or_insert(&mut self, key: TKey, value: TValue) -> &mut TValue

Retrieves an existing TValue, or inserts the passed one. Read more
Source§

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

Source§

fn eq(&self, other: &DefaultHashTable<TKey, TValue, TAllocator>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

const CHECK: ()

This field is used for const checks only.
Source§

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

Source§

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

Auto Trait Implementations§

§

impl<TKey, TValue, TAllocator> Freeze for DefaultHashTable<TKey, TValue, TAllocator>
where TAllocator: Freeze,

§

impl<TKey, TValue, TAllocator> RefUnwindSafe for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: RefUnwindSafe, TValue: RefUnwindSafe, TAllocator: RefUnwindSafe,

§

impl<TKey, TValue, TAllocator> Send for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: Send, TValue: Send,

§

impl<TKey, TValue, TAllocator> Sync for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: Sync, TValue: Sync,

§

impl<TKey, TValue, TAllocator> Unpin for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: Unpin, TValue: Unpin, TAllocator: Unpin,

§

impl<TKey, TValue, TAllocator> UnsafeUnpin for DefaultHashTable<TKey, TValue, TAllocator>
where TAllocator: UnsafeUnpin,

§

impl<TKey, TValue, TAllocator> UnwindSafe for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: UnwindSafe, TValue: UnwindSafe, TAllocator: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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