pub unsafe trait Status: Copy + Eq {
const FREE: Self;
const TOMBSTONE: Self;
// Required methods
fn from_hash(hash: u64) -> Self;
fn check_capacity(capacity: usize);
fn is_hash(self) -> bool;
fn hash_as_usize(self) -> usize;
}Expand description
Status of a slot in the hash table
A status can either be free, a tombstone, or a hash value of the associated
item. This can be implemented as a u32 or a usize, for instance. Since
there are possibly more u64 hash values than Status hash values, it is
fine to apply some mapping (e.g. only take the lowest n - 1 bits).
Part of the idea of storing hash values is that we can avoid recomputing the
hash values when rehashing (resizing) the table. Consequently, we cannot
meaningfully address a table that is larger than the number of Status hash
values. This is why we have Self::check_capacity().
§Safety
All valid status values are either Status::FREE, a Status::TOMBSTONE
or a hash value. Status::from_hash() must always return a hash value,
and Status::is_hash() must return true if and only if the given
Status is indeed a hash value.
Required Associated Constants§
Required Methods§
Sourcefn from_hash(hash: u64) -> Self
fn from_hash(hash: u64) -> Self
Convert a u64 hash value (e.g. as returned by
Hash) into a Status hash value
Sourcefn check_capacity(capacity: usize)
fn check_capacity(capacity: usize)
Panics if capacity exceeds the number of possible Status hash values
Sourcefn hash_as_usize(self) -> usize
fn hash_as_usize(self) -> usize
Convert a Status hash value into a usize
The result is unspecified if the status is free, a tombstone, or invalid. In this case, the implementation is allowed to panic.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.