Struct bevy::utils::hashbrown::raw::RawTable

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

A raw hash table with an unsafe API.

Implementations§

§

impl<T> RawTable<T, Global>

pub const fn new() -> RawTable<T, Global>

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<RawTable<T, Global>, TryReserveError>

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) -> RawTable<T, Global>

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

§

impl<T, A> RawTable<T, A>where A: Allocator + Clone,

pub fn new_in(alloc: A) -> RawTable<T, A>

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<RawTable<T, A>, 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.

pub fn with_capacity_in(capacity: usize, alloc: A) -> RawTable<T, A>

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

Returns a reference to the underlying allocator.

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

Returns pointer to one past last element of data table.

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

Returns the index of a bucket from a Bucket.

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

Returns a pointer to an element in the table.

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

👎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>)

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

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.

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

Removes an element from the table, returning it.

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.

pub fn clear_no_drop(&mut self)

Marks all table buckets as empty without dropping their contents.

pub fn clear(&mut self)

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)

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

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.

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.

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.

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.

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.

pub unsafe 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.

pub unsafe fn replace_bucket_with<F>(&mut self, bucket: Bucket<T>, f: F) -> boolwhere 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.

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

Searches for an element in the table.

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

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>

Gets a mutable reference to an element in the table.

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

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.

pub unsafe fn get_many_unchecked_mut<const N: usize>( &mut self, hashes: [u64; N], eq: impl FnMut(usize, &T) -> bool ) -> Option<[&mut T; N]>

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.

pub fn len(&self) -> usize

Returns the number of elements in the table.

pub fn is_empty(&self) -> bool

Returns true if the table contains no elements.

pub fn buckets(&self) -> usize

Returns the number of buckets in the table.

pub unsafe fn iter(&self) -> RawIter<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.

pub unsafe fn iter_hash(&self, hash: u64) -> RawIterHash<'_, T, A>

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.

pub fn drain(&mut self) -> RawDrain<'_, T, A>

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>

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>

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, A> RawTable<T, A>where T: Clone, A: Allocator + Clone,

pub fn clone_from_with_hasher( &mut self, source: &RawTable<T, A>, hasher: impl Fn(&T) -> u64 )

Variant of clone_from to use when a hasher is available.

Trait Implementations§

§

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

§

fn clone(&self) -> RawTable<T, A>

Returns a copy of the value. Read more
§

fn clone_from(&mut self, source: &RawTable<T, A>)

Performs copy-assignment from source. Read more
§

impl<T, A> Default for RawTable<T, A>where A: Allocator + Clone + Default,

§

fn default() -> RawTable<T, A>

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

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

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

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

§

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?
§

fn into_iter(self) -> RawIntoIter<T, A>

Creates an iterator from a value. Read more
§

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

§

impl<T, A> Sync for RawTable<T, A>where A: Allocator + Clone + Sync, 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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,

§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for Twhere T: Any,

§

fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync + 'static>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> FromWorld for Twhere T: Default,

§

fn from_world(_world: &mut World) -> T

Creates Self using data from the given World
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere T: Clone,

§

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
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> TypeData for Twhere T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData + 'static, Global>

§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,

§

impl<T> Event for Twhere T: Send + Sync + 'static,