RawTable

Struct RawTable 

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

Source

pub fn new() -> Self

Create a new HashTable with zero capacity

Source

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>

Source

pub fn len(&self) -> usize

Get the number of elements stored in the table

Source

pub fn is_empty(&self) -> bool

Returns true iff no elements are stored in the table

Source

pub fn capacity(&self) -> usize

Get the capacity (excluding spare slots)

Source

pub fn slots(&self) -> usize

Get the number of slots (i.e. Self::capacity() plus spare slots)

Source

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.

Source

pub fn clear(&mut self)

Clear the table

This does not change the table’s capacity.

Source

pub fn clear_no_drop(&mut self)

Self::clear() but without dropping any entry

Source

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.

Source

pub unsafe fn is_slot_occupied_unchecked(&self, slot: usize) -> bool

Returns true iff there is an entry at slot

§Safety

slot must be less than self.slots()

Source

pub fn find(&self, hash: u64, eq: impl Fn(&T) -> bool) -> Option<usize>

Find the index of an element or a slot

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Get an immutable iterator over the entries of the table

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T, S>

Get a mutable iterator over the entries of the table

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: Clone, S: Status, A: Clone + Allocator> Clone for RawTable<T, S, A>

Source§

fn clone(&self) -> Self

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<T, S: Status, A: Clone + Default + Allocator> Default for RawTable<T, S, A>

Source§

fn default() -> Self

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

impl<T, S: Status, A: Clone + Allocator> Drop for RawTable<T, S, A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, S: Status, A: Clone + Allocator> IntoIterator for RawTable<T, S, A>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, S, A>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, S, A> Freeze for RawTable<T, S, A>

§

impl<T, S, A> RefUnwindSafe for RawTable<T, S, A>

§

impl<T, S, A> Send for RawTable<T, S, A>
where A: Send, S: Send, T: Send,

§

impl<T, S, A> Sync for RawTable<T, S, A>
where A: Sync, S: Sync, T: Sync,

§

impl<T, S, A> Unpin for RawTable<T, S, A>
where A: Unpin,

§

impl<T, S, A> UnwindSafe for RawTable<T, S, A>
where A: UnwindSafe, S: UnwindSafe, T: 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.