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 the AbseilHashTable 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
where TAllocator: Default,

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, HashTableError>
where TAllocator: Default,

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

This likely will (over)allocate memory.

§Errors

See HashTableError for details.

Source

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

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

This likely will (over)allocate memory.

§Errors

See HashTableError for details.

Trait Implementations§

Source§

impl<TKey, TValue, TAllocator> Clone for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: Eq + Hash, TAllocator: Allocator, AbseilHashTable<TKey, TValue, DefaultAbseilConfig<TAllocator>>: TryClone<Error = TryCloneHashTableError>,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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

Source§

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

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

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

Source§

fn default() -> Self

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

impl<'de, TKey, TValue, TAllocator> Deserialize<'de> for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: Eq + Hash + Deserialize<'de>, TValue: Deserialize<'de>, TAllocator: Allocator + Default,

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

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

Source§

impl<TKey, TValue, TAllocator> Hash for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: Eq + Hash, TAllocator: Allocator, AbseilHashTable<TKey, TValue, DefaultAbseilConfig<TAllocator>>: 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, AbseilHashTable<TKey, TValue, DefaultAbseilConfig<TAllocator>>: ImmutableHashTable<TKey, TValue>,

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<KVP<&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 = KVP<&'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, AbseilHashTable<TKey, TValue, DefaultAbseilConfig<TAllocator>>: MutableHashTable<TKey, TValue>,

Source§

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

Checks if the table contains the corresponding key, and if so then returns a mutable reference to the TValue, or None otherwise. Read more
Source§

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

Checks if the table contains the corresponding key, and if so then returns a mutable reference to the TValue, or None otherwise. Read more
Source§

fn remove_entry<Q>(&mut self, key: &Q) -> Option<KVP<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 iter_mut<'a>( &'a mut self, ) -> impl Iterator<Item = KVP<&'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 try_insert_or_update_with<FAdd, FUpdate>( &mut self, key: TKey, adder: FAdd, updater: FUpdate, ) -> Result<&mut TValue, HashTableError>
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 insert(&mut self, key: TKey, value: TValue) -> Option<TValue>

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

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

Tries to insert given (TKey, TValue) pair into the table. 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 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 try_get_or_insert_default( &mut self, key: TKey, ) -> Result<&mut TValue, HashTableError>
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§

fn try_get_or_insert( &mut self, key: TKey, value: TValue, ) -> Result<&mut TValue, HashTableError>

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

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

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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, AbseilHashTable<TKey, TValue, DefaultAbseilConfig<TAllocator>>: ReprC,

Source§

const CHECK: ()

This field is used for const checks only.
Source§

impl<TKey, TValue, TAllocator> Send for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: Send + Eq + Hash, TValue: Send, TAllocator: Allocator + Send, AbseilHashTable<TKey, TValue, DefaultAbseilConfig<TAllocator>>: Sync,

Source§

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

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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

Source§

impl<TKey, TValue, TAllocator> TryClone for DefaultHashTable<TKey, TValue, TAllocator>
where TKey: Eq + Hash, TAllocator: Allocator, AbseilHashTable<TKey, TValue, DefaultAbseilConfig<TAllocator>>: TryClone<Error = TryCloneHashTableError>,

Source§

type Error = TryCloneHashTableError

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Tries to clone the type. Read more

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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.