Status

Trait Status 

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

Source

const FREE: Self

Marker for the slot being free

Source

const TOMBSTONE: Self

Marker that is placed for deleted entries in a collision list

Required Methods§

Source

fn from_hash(hash: u64) -> Self

Convert a u64 hash value (e.g. as returned by Hash) into a Status hash value

Source

fn check_capacity(capacity: usize)

Panics if capacity exceeds the number of possible Status hash values

Source

fn is_hash(self) -> bool

Check if the Status is a hash value

Source

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.

Implementations on Foreign Types§

Source§

impl Status for u32

Source§

const FREE: Self = 4_294_967_295u32

Source§

const TOMBSTONE: Self = 4_294_967_294u32

Source§

fn from_hash(hash: u64) -> Self

Source§

fn check_capacity(capacity: usize)

Source§

fn is_hash(self) -> bool

Source§

fn hash_as_usize(self) -> usize

Source§

impl Status for usize

Source§

const FREE: Self = 4_294_967_295usize

Source§

const TOMBSTONE: Self = 4_294_967_294usize

Source§

fn from_hash(hash: u64) -> Self

Source§

fn check_capacity(capacity: usize)

Source§

fn is_hash(self) -> bool

Source§

fn hash_as_usize(self) -> usize

Implementors§