Struct hashbrown::raw::RawTable[][src]

pub struct RawTable<T, A: Allocator + Clone = Global> { /* fields omitted */ }

A raw hash table with an unsafe API.

Implementations

impl<T> RawTable<T, Global>[src]

pub const fn new() -> Self[src]

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.

pub fn try_with_capacity(capacity: usize) -> Result<Self, TryReserveError>[src]

Attempts to allocate a new hash table with at least enough capacity for inserting the given number of elements without reallocating.

pub fn with_capacity(capacity: usize) -> Self[src]

Allocates a new hash table with at least enough capacity for inserting the given number of elements without reallocating.

impl<T, A: Allocator + Clone> RawTable<T, A>[src]

pub fn new_in(alloc: A) -> Self[src]

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.

pub fn try_with_capacity_in(
    capacity: usize,
    alloc: A
) -> Result<Self, TryReserveError>
[src]

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.

pub fn with_capacity_in(capacity: usize, alloc: A) -> Self[src]

Allocates a new hash table using the given allocator, with at least enough capacity for inserting the given number of elements without reallocating.

pub fn allocator(&self) -> &A[src]

Returns a reference to the underlying allocator.

pub unsafe fn data_end(&self) -> NonNull<T>[src]

Returns pointer to one past last element of data table.

pub unsafe fn data_start(&self) -> *mut T[src]

Returns pointer to start of data table.

pub unsafe fn bucket_index(&self, bucket: &Bucket<T>) -> usize[src]

Returns the index of a bucket from a Bucket.

pub unsafe fn bucket(&self, index: usize) -> Bucket<T>[src]

Returns a pointer to an element in the table.

pub unsafe fn erase_no_drop(&mut self, item: &Bucket<T>)[src]

👎 Deprecated since 0.8.1:

use erase or remove instead

Erases an element from the table without dropping it.

pub unsafe fn erase(&mut self, item: Bucket<T>)[src]

Erases an element from the table, dropping it in place.

pub fn erase_entry(&mut self, hash: u64, eq: impl FnMut(&T) -> bool) -> bool[src]

Finds and erases an element from the table, dropping it in place. Returns true if an element was found.

pub unsafe fn remove(&mut self, item: Bucket<T>) -> T[src]

Removes an element from the table, returning it.

pub fn remove_entry(
    &mut self,
    hash: u64,
    eq: impl FnMut(&T) -> bool
) -> Option<T>
[src]

Finds and removes an element from the table, returning it.

pub fn clear_no_drop(&mut self)[src]

Marks all table buckets as empty without dropping their contents.

pub fn clear(&mut self)[src]

Removes all elements from the table without freeing the backing memory.

pub fn shrink_to(&mut self, min_size: usize, hasher: impl Fn(&T) -> u64)[src]

Shrinks the table to fit max(self.len(), min_size) elements.

pub fn reserve(&mut self, additional: usize, hasher: impl Fn(&T) -> u64)[src]

Ensures that at least additional items can be inserted into the table without reallocation.

pub fn try_reserve(
    &mut self,
    additional: usize,
    hasher: impl Fn(&T) -> u64
) -> Result<(), TryReserveError>
[src]

Tries to ensure that at least additional items can be inserted into the table without reallocation.

pub fn insert(
    &mut self,
    hash: u64,
    value: T,
    hasher: impl Fn(&T) -> u64
) -> Bucket<T>
[src]

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.

pub fn try_insert_no_grow(
    &mut self,
    hash: u64,
    value: T
) -> Result<Bucket<T>, T>
[src]

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.

pub fn insert_entry(
    &mut self,
    hash: u64,
    value: T,
    hasher: impl Fn(&T) -> u64
) -> &mut T
[src]

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.

pub unsafe fn insert_no_grow(&mut self, hash: u64, value: T) -> Bucket<T>[src]

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.

pub unsafe fn replace_bucket_with<F>(&mut self, bucket: Bucket<T>, f: F) -> bool where
    F: FnOnce(T) -> Option<T>, 
[src]

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.

pub fn find(&self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option<Bucket<T>>[src]

Searches for an element in the table.

pub fn get(&self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option<&T>[src]

Gets a reference to an element in the table.

pub fn get_mut(
    &mut self,
    hash: u64,
    eq: impl FnMut(&T) -> bool
) -> Option<&mut T>
[src]

Gets a mutable reference to an element in the table.

pub fn get_each_mut<const N: usize>(
    &mut self,
    hashes: [u64; N],
    eq: impl FnMut(usize, &T) -> bool
) -> [Result<&mut T, UnavailableMutError>; N]
[src]

Attempts to get mutable references to N entries in the table at once.

Returns an array of length N with the results of each query. For soundness, at most one mutable reference will be returned to any entry. An Err(UnavailableMutError::Duplicate(i)) in the returned array indicates that a suitable entry exists, but a mutable reference to it already occurs at index i in the returned array.

The eq argument should be a closure such that eq(i, k) returns true if k is equal to the ith key to be looked up.

This method is available only if the nightly feature is enabled.

pub fn capacity(&self) -> usize[src]

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.

pub fn len(&self) -> usize[src]

Returns the number of elements in the table.

pub fn buckets(&self) -> usize[src]

Returns the number of buckets in the table.

pub unsafe fn iter(&self) -> RawIter<T>

Notable traits for RawIter<T>

impl<T> Iterator for RawIter<T> type Item = Bucket<T>;
[src]

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.

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>;
[src]

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.

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;
[src]

Returns an iterator which removes all elements from the table without freeing the memory.

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;
[src]

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.

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;
[src]

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.

impl<T: Clone, A: Allocator + Clone> RawTable<T, A>[src]

pub fn clone_from_with_hasher(
    &mut self,
    source: &Self,
    hasher: impl Fn(&T) -> u64
)
[src]

Variant of clone_from to use when a hasher is available.

impl<T, A: Allocator + Clone> RawTable<T, A>[src]

pub unsafe fn par_iter(&self) -> RawParIter<T>[src]

Returns a parallel iterator over the elements in a RawTable.

pub fn into_par_iter(self) -> RawIntoParIter<T, A>[src]

Returns a parallel iterator over the elements in a RawTable.

pub fn par_drain(&mut self) -> RawParDrain<'_, T, A>[src]

Returns a parallel iterator which consumes all elements of a RawTable without freeing its memory allocation.

Trait Implementations

impl<T: Clone, A: Allocator + Clone> Clone for RawTable<T, A>[src]

impl<T, A: Allocator + Clone + Default> Default for RawTable<T, A>[src]

impl<T, A: Allocator + Clone> Drop for RawTable<T, A>[src]

impl<T, A: Allocator + Clone> IntoIterator for RawTable<T, A>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = RawIntoIter<T, A>

Which kind of iterator are we turning this into?

impl<T, A: Allocator + Clone> Send for RawTable<T, A> where
    T: Send
[src]

impl<T, A: Allocator + Clone> Sync for RawTable<T, A> where
    T: Sync
[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.