pub struct RawTable<T, S: Status = usize, A: Allocator + Clone = Global> { /* private fields */ }Expand description
Raw hash table with a (partially) unsafe API
Implementations§
Source§impl<T, S: Status> RawTable<T, S>
impl<T, S: Status> RawTable<T, S>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new HashTable with capacity for at least capacity elements
Source§impl<T, S: Status, A: Clone + Allocator> RawTable<T, S, A>
impl<T, S: Status, A: Clone + Allocator> RawTable<T, S, A>
Sourcepub fn slots(&self) -> usize
pub fn slots(&self) -> usize
Get the number of slots (i.e. Self::capacity() plus spare slots)
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserve space for additional elements
If there are no other modifying operations in between, the next
additional insertions are guaranteed to not cause a rehash (or resize)
of the table.
Sourcepub fn clear_no_drop(&mut self)
pub fn clear_no_drop(&mut self)
Self::clear() but without dropping any entry
Sourcepub fn reset_no_drop(&mut self)
pub fn reset_no_drop(&mut self)
Like Self::clear_no_drop(), but also sets the capacity to 0
If the space is not needed anymore, this should generally be faster than
Self::clear_no_drop(), since we do not need to mark every slot as
free.
Sourcepub unsafe fn is_slot_occupied_unchecked(&self, slot: usize) -> bool
pub unsafe fn is_slot_occupied_unchecked(&self, slot: usize) -> bool
Sourcepub fn find(&self, hash: u64, eq: impl Fn(&T) -> bool) -> Option<usize>
pub fn find(&self, hash: u64, eq: impl Fn(&T) -> bool) -> Option<usize>
Find the index of an element or a slot
Sourcepub fn find_or_find_insert_slot(
&mut self,
hash: u64,
eq: impl Fn(&T) -> bool,
) -> Result<usize, usize>
pub fn find_or_find_insert_slot( &mut self, hash: u64, eq: impl Fn(&T) -> bool, ) -> Result<usize, usize>
Find the index of an element or a slot to insert it
Returns Ok(index) if the element was found and Err(index) for an
insertion slot.
eq is guaranteed to only be called for entries that are present in the
table.
Sourcepub fn get(&self, hash: u64, eq: impl Fn(&T) -> bool) -> Option<&T>
pub fn get(&self, hash: u64, eq: impl Fn(&T) -> bool) -> Option<&T>
Get a reference to an entry in the table
hash is the entry’s hash value and eq returns true if the given
element is the searched one.
Sourcepub fn get_mut(&mut self, hash: u64, eq: impl Fn(&T) -> bool) -> Option<&mut T>
pub fn get_mut(&mut self, hash: u64, eq: impl Fn(&T) -> bool) -> Option<&mut T>
Get a mutable reference to an entry in the table
hash is the entry’s hash value and eq returns true if the given
element is the searched one.
Sourcepub unsafe fn get_at_slot_unchecked(&self, slot: usize) -> &T
pub unsafe fn get_at_slot_unchecked(&self, slot: usize) -> &T
Get a reference to the entry at slot
§Safety
slot must be the index of an occupied slot. This is the case if slot
has been returned by RawTable::find() or
RawTable::find_or_find_insert_slot() in the Ok case, and no
modifications happened in between.
Sourcepub unsafe fn get_at_slot_unchecked_mut(&mut self, slot: usize) -> &mut T
pub unsafe fn get_at_slot_unchecked_mut(&mut self, slot: usize) -> &mut T
Get a mutable reference to the entry entry at slot
§Safety
slot must be the index of an occupied slot. This is the case if slot
has been returned by RawTable::find() or
RawTable::find_or_find_insert_slot() in the Ok case, and no
modifications happened in between.
Sourcepub unsafe fn insert_in_slot_unchecked(
&mut self,
hash: u64,
slot: usize,
val: T,
) -> &mut T
pub unsafe fn insert_in_slot_unchecked( &mut self, hash: u64, slot: usize, val: T, ) -> &mut T
Insert val in slot
hash is the hash value of val. Returns a mutable reference to the
inserted value.
§Safety
slot must be the index of an empty slot. This is the case if slot
has been returned by RawTable::find_or_find_insert_slot() in the
Err case, and no modifications happened in between.
Sourcepub fn remove_entry(&mut self, hash: u64, eq: impl Fn(&T) -> bool) -> Option<T>
pub fn remove_entry(&mut self, hash: u64, eq: impl Fn(&T) -> bool) -> Option<T>
Find and remove an entry from the table, returning it
hash is the entry’s hash value and eq returns true if the given
element is the searched one.
Sourcepub unsafe fn remove_at_slot_unchecked(&mut self, slot: usize) -> T
pub unsafe fn remove_at_slot_unchecked(&mut self, slot: usize) -> T
Remove the entry at slot
Returns the entry value.
§Safety
slot must be the index of an occupied slot. This is the case if slot
has been returned by RawTable::find() or
RawTable::find_or_find_insert_slot() in the Ok case, and no
modifications happened in between.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T, S> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T, S> ⓘ
Get a mutable iterator over the entries of the table
Sourcepub fn drain(&mut self) -> Drain<'_, T, S> ⓘ
pub fn drain(&mut self) -> Drain<'_, T, S> ⓘ
Get a draining iterator over the entries of the table
A draining iterator removes all elements from the table but does not change the table’s capacity.
Note: Forgetting the returned Drain (e.g., via
core::mem::forget()) and using the table afterwards is a very
bad idea. It is not unsafe but it causes correctness issues since
there exist non-empty slots while the length is already set to 0.
Sourcepub fn retain(
&mut self,
predicate: impl FnMut(&mut T) -> bool,
drop: impl FnMut(T),
)
pub fn retain( &mut self, predicate: impl FnMut(&mut T) -> bool, drop: impl FnMut(T), )
Retain only the elements for which predicate returns true
predicate is guaranteed to only be called for entries that are present
in the table.
drop is called for every element that is removed from the table.