pub struct RawTable<T, A: Allocator = Global> { /* private fields */ }
Expand description

A raw hash table with an unsafe API.

Implementations

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.

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

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

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.

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.

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

Returns a reference to the underlying allocator.

Returns pointer to one past last data element in the the table as viewed from the start point of the allocation.

The caller must ensure that the RawTable outlives the returned NonNull<T>, otherwise using it may result in undefined behavior.

Returns pointer to start of data table.

Return the information about memory allocated by the table.

RawTable allocates single memory block to store both data and metadata. This function returns allocation size and alignment and the beginning of the area. These are the arguments which will be passed to dealloc when the table is dropped.

This function might be useful for memory profiling.

Returns the index of a bucket from a Bucket.

Returns a pointer to an element in the table.

The caller must ensure that the RawTable outlives the returned Bucket<T>, otherwise using it may result in undefined behavior.

Safety

If mem::size_of::<T>() != 0, then the caller of this function must observe the following safety rules:

  • The table must already be allocated;

  • The index must not be greater than the number returned by the RawTable::buckets function, i.e. (index + 1) <= self.buckets().

It is safe to call this function with index of zero (index == 0) on a table that has not been allocated, but using the returned Bucket results in undefined behavior.

If mem::size_of::<T>() == 0, then the only requirement is that the index must not be greater than the number returned by the RawTable::buckets function, i.e. (index + 1) <= self.buckets().

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

source

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.

Removes an element from the table, returning it.

This also returns an InsertSlot pointing to the newly free bucket.

source

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.

Marks all table buckets as empty without dropping their contents.

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

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

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

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

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.

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.

source

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.

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.

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.

Searches for an element in the table. If the element is not found, returns Err with the position of a slot where an element with the same hash could be inserted.

This function may resize the table if additional space is required for inserting an element.

Inserts a new element into the table in the given slot, and returns its raw bucket.

Safety

slot must point to a slot previously returned by find_or_find_insert_slot, and no mutation of the table must have occurred since that call.

Searches for an element in the table.

Gets a reference to an element in the table.

Gets a mutable reference to an element in the table.

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.

At most one mutable reference will be returned to any entry. None will be returned if any of the hashes are duplicates. None will be returned if the hash is not found.

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.

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.

Returns the number of elements in the table.

Returns true if the table contains no elements.

Returns the number of buckets in the table.

Checks whether the bucket at index is full.

Safety

The caller must ensure index is less than the number of buckets.

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.

Returns an iterator over occupied buckets that could match a given hash.

RawTable only stores 7 bits of the hash value, so this iterator may return items that have a hash value different than the one provided. You should always validate the returned values before using them.

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.

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

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.

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.

Variant of clone_from to use when a hasher is available.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns the “default value” for a type. Read more
Executes the destructor for this type. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.