pub struct RawTable<T, A: Allocator + Clone = Global> { /* private fields */ }
Expand description
A raw hash table with an unsafe API.
Implementations
sourceimpl<T> RawTable<T, Global>
impl<T> RawTable<T, Global>
sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new empty hash table without allocating any memory.
In effect this returns a table with exactly 1 bucket. However we can leave the data pointer dangling since that bucket is never written to due to our load factor forcing us to always have at least 1 free bucket.
sourcepub fn try_with_capacity(capacity: usize) -> Result<Self, TryReserveError>
pub fn try_with_capacity(capacity: usize) -> Result<Self, TryReserveError>
Attempts to allocate a new hash table with at least enough capacity for inserting the given number of elements without reallocating.
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Allocates a new hash table with at least enough capacity for inserting the given number of elements without reallocating.
sourceimpl<T, A: Allocator + Clone> RawTable<T, A>
impl<T, A: Allocator + Clone> RawTable<T, A>
sourcepub fn new_in(alloc: A) -> Self
pub fn new_in(alloc: A) -> Self
Creates a new empty hash table without allocating any memory, using the given allocator.
In effect this returns a table with exactly 1 bucket. However we can leave the data pointer dangling since that bucket is never written to due to our load factor forcing us to always have at least 1 free bucket.
sourcepub fn try_with_capacity_in(
capacity: usize,
alloc: A
) -> Result<Self, TryReserveError>
pub fn try_with_capacity_in(
capacity: usize,
alloc: A
) -> Result<Self, TryReserveError>
Attempts to allocate a new hash table using the given allocator, with at least enough capacity for inserting the given number of elements without reallocating.
sourcepub fn with_capacity_in(capacity: usize, alloc: A) -> Self
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self
Allocates a new hash table using the given allocator, with at least enough capacity for inserting the given number of elements without reallocating.
sourcepub unsafe fn data_end(&self) -> NonNull<T>
pub unsafe fn data_end(&self) -> NonNull<T>
Returns pointer to one past last element of data table.
sourcepub unsafe fn bucket_index(&self, bucket: &Bucket<T>) -> usize
pub unsafe fn bucket_index(&self, bucket: &Bucket<T>) -> usize
Returns the index of a bucket from a Bucket
.
sourcepub unsafe fn bucket(&self, index: usize) -> Bucket<T>
pub unsafe fn bucket(&self, index: usize) -> Bucket<T>
Returns a pointer to an element in the table.
sourcepub unsafe fn erase_no_drop(&mut self, item: &Bucket<T>)
👎 Deprecated since 0.8.1: use erase or remove instead
pub unsafe fn erase_no_drop(&mut self, item: &Bucket<T>)
use erase or remove instead
Erases an element from the table without dropping it.
sourcepub unsafe fn erase(&mut self, item: Bucket<T>)
pub unsafe fn erase(&mut self, item: Bucket<T>)
Erases an element from the table, dropping it in place.
sourcepub fn erase_entry(&mut self, hash: u64, eq: impl FnMut(&T) -> bool) -> bool
pub fn erase_entry(&mut self, hash: u64, eq: impl FnMut(&T) -> bool) -> bool
Finds and erases an element from the table, dropping it in place. Returns true if an element was found.
sourcepub unsafe fn remove(&mut self, item: Bucket<T>) -> T
pub unsafe fn remove(&mut self, item: Bucket<T>) -> T
Removes an element from the table, returning it.
sourcepub fn remove_entry(
&mut self,
hash: u64,
eq: impl FnMut(&T) -> bool
) -> Option<T>
pub fn remove_entry(
&mut self,
hash: u64,
eq: impl FnMut(&T) -> bool
) -> Option<T>
Finds and removes an element from the table, returning it.
sourcepub fn clear_no_drop(&mut self)
pub fn clear_no_drop(&mut self)
Marks all table buckets as empty without dropping their contents.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all elements from the table without freeing the backing memory.
sourcepub fn shrink_to(&mut self, min_size: usize, hasher: impl Fn(&T) -> u64)
pub fn shrink_to(&mut self, min_size: usize, hasher: impl Fn(&T) -> u64)
Shrinks the table to fit max(self.len(), min_size)
elements.
sourcepub fn reserve(&mut self, additional: usize, hasher: impl Fn(&T) -> u64)
pub fn reserve(&mut self, additional: usize, hasher: impl Fn(&T) -> u64)
Ensures that at least additional
items can be inserted into the table
without reallocation.
sourcepub fn try_reserve(
&mut self,
additional: usize,
hasher: impl Fn(&T) -> u64
) -> Result<(), TryReserveError>
pub fn try_reserve(
&mut self,
additional: usize,
hasher: impl Fn(&T) -> u64
) -> Result<(), TryReserveError>
Tries to ensure that at least additional
items can be inserted into
the table without reallocation.
sourcepub fn insert(
&mut self,
hash: u64,
value: T,
hasher: impl Fn(&T) -> u64
) -> Bucket<T>
pub fn insert(
&mut self,
hash: u64,
value: T,
hasher: impl Fn(&T) -> u64
) -> Bucket<T>
Inserts a new element into the table, and returns its raw bucket.
This does not check if the given element already exists in the table.
sourcepub fn try_insert_no_grow(
&mut self,
hash: u64,
value: T
) -> Result<Bucket<T>, T>
pub fn try_insert_no_grow(
&mut self,
hash: u64,
value: T
) -> Result<Bucket<T>, T>
Attempts to insert a new element without growing the table and return its raw bucket.
Returns an Err
containing the given element if inserting it would require growing the
table.
This does not check if the given element already exists in the table.
sourcepub fn insert_entry(
&mut self,
hash: u64,
value: T,
hasher: impl Fn(&T) -> u64
) -> &mut T
pub fn insert_entry(
&mut self,
hash: u64,
value: T,
hasher: impl Fn(&T) -> u64
) -> &mut T
Inserts a new element into the table, and returns a mutable reference to it.
This does not check if the given element already exists in the table.
sourcepub fn insert_no_grow(&mut self, hash: u64, value: T) -> Bucket<T>
pub fn insert_no_grow(&mut self, hash: u64, value: T) -> Bucket<T>
Inserts a new element into the table, without growing the table.
There must be enough space in the table to insert the new element.
This does not check if the given element already exists in the table.
sourcepub unsafe fn replace_bucket_with<F>(&mut self, bucket: Bucket<T>, f: F) -> bool where
F: FnOnce(T) -> Option<T>,
pub unsafe fn replace_bucket_with<F>(&mut self, bucket: Bucket<T>, f: F) -> bool where
F: FnOnce(T) -> Option<T>,
Temporary removes a bucket, applying the given function to the removed element and optionally put back the returned value in the same bucket.
Returns true
if the bucket still contains an element
This does not check if the given bucket is actually occupied.
sourcepub fn find(&self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option<Bucket<T>>
pub fn find(&self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option<Bucket<T>>
Searches for an element in the table.
sourcepub fn get(&self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option<&T>
pub fn get(&self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option<&T>
Gets a reference to an element in the table.
sourcepub fn get_mut(
&mut self,
hash: u64,
eq: impl FnMut(&T) -> bool
) -> Option<&mut T>
pub fn get_mut(
&mut self,
hash: u64,
eq: impl FnMut(&T) -> bool
) -> Option<&mut T>
Gets a mutable reference to an element in the table.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
This number is a lower bound; the table might be able to hold more, but is guaranteed to be able to hold at least this many.
sourcepub unsafe fn iter(&self) -> RawIter<T>ⓘNotable traits for RawIter<T>impl<T> Iterator for RawIter<T> type Item = Bucket<T>;
pub unsafe fn iter(&self) -> RawIter<T>ⓘNotable traits for RawIter<T>impl<T> Iterator for RawIter<T> type Item = Bucket<T>;
Returns an iterator over every element in the table. It is up to
the caller to ensure that the RawTable
outlives the RawIter
.
Because we cannot make the next
method unsafe on the RawIter
struct, we have to make the iter
method unsafe.
sourcepub unsafe fn iter_hash(&self, hash: u64) -> RawIterHash<'_, T, A>ⓘNotable traits for RawIterHash<'a, T, A>impl<'a, T, A: Allocator + Clone> Iterator for RawIterHash<'a, T, A> type Item = Bucket<T>;
pub unsafe fn iter_hash(&self, hash: u64) -> RawIterHash<'_, T, A>ⓘNotable traits for RawIterHash<'a, T, A>impl<'a, T, A: Allocator + Clone> Iterator for RawIterHash<'a, T, A> type Item = Bucket<T>;
Returns an iterator over occupied buckets that could match a given hash.
In rare cases, the iterator may return a bucket with a different hash.
It is up to the caller to ensure that the RawTable
outlives the
RawIterHash
. Because we cannot make the next
method unsafe on the
RawIterHash
struct, we have to make the iter_hash
method unsafe.
sourcepub fn drain(&mut self) -> RawDrain<'_, T, A>ⓘNotable traits for RawDrain<'_, T, A>impl<T, A: Allocator + Clone> Iterator for RawDrain<'_, T, A> type Item = T;
pub fn drain(&mut self) -> RawDrain<'_, T, A>ⓘNotable traits for RawDrain<'_, T, A>impl<T, A: Allocator + Clone> Iterator for RawDrain<'_, T, A> type Item = T;
Returns an iterator which removes all elements from the table without freeing the memory.
sourcepub unsafe fn drain_iter_from(&mut self, iter: RawIter<T>) -> RawDrain<'_, T, A>ⓘNotable traits for RawDrain<'_, T, A>impl<T, A: Allocator + Clone> Iterator for RawDrain<'_, T, A> type Item = T;
pub unsafe fn drain_iter_from(&mut self, iter: RawIter<T>) -> RawDrain<'_, T, A>ⓘNotable traits for RawDrain<'_, T, A>impl<T, A: Allocator + Clone> Iterator for RawDrain<'_, T, A> type Item = T;
Returns an iterator which removes all elements from the table without freeing the memory.
Iteration starts at the provided iterator’s current location.
It is up to the caller to ensure that the iterator is valid for this
RawTable
and covers all items that remain in the table.
sourcepub unsafe fn into_iter_from(self, iter: RawIter<T>) -> RawIntoIter<T, A>ⓘNotable traits for RawIntoIter<T, A>impl<T, A: Allocator + Clone> Iterator for RawIntoIter<T, A> type Item = T;
pub unsafe fn into_iter_from(self, iter: RawIter<T>) -> RawIntoIter<T, A>ⓘNotable traits for RawIntoIter<T, A>impl<T, A: Allocator + Clone> Iterator for RawIntoIter<T, A> type Item = T;
Returns an iterator which consumes all elements from the table.
Iteration starts at the provided iterator’s current location.
It is up to the caller to ensure that the iterator is valid for this
RawTable
and covers all items that remain in the table.
Trait Implementations
sourceimpl<T, A: Allocator + Clone> IntoIterator for RawTable<T, A>
impl<T, A: Allocator + Clone> IntoIterator for RawTable<T, A>
type Item = T
type Item = T
The type of the elements being iterated over.
type IntoIter = RawIntoIter<T, A>
type IntoIter = RawIntoIter<T, A>
Which kind of iterator are we turning this into?
sourcefn into_iter(self) -> RawIntoIter<T, A>ⓘNotable traits for RawIntoIter<T, A>impl<T, A: Allocator + Clone> Iterator for RawIntoIter<T, A> type Item = T;
fn into_iter(self) -> RawIntoIter<T, A>ⓘNotable traits for RawIntoIter<T, A>impl<T, A: Allocator + Clone> Iterator for RawIntoIter<T, A> type Item = T;
Creates an iterator from a value. Read more
impl<T, A: Allocator + Clone> Send for RawTable<T, A> where
T: Send,
impl<T, A: Allocator + Clone> Sync for RawTable<T, A> where
T: Sync,
Auto Trait Implementations
impl<T, A> RefUnwindSafe for RawTable<T, A> where
A: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, A> Unpin for RawTable<T, A> where
A: Unpin,
T: Unpin,
impl<T, A> UnwindSafe for RawTable<T, A> where
A: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more