Skip to main content

GrowthPolicy

Trait GrowthPolicy 

Source
pub trait GrowthPolicy: Clone {
    // Required methods
    fn new(min_bucket_count: usize) -> Result<(Self, usize), LengthError>;
    fn bucket_for_hash(&self, hash: usize) -> usize;
    fn next_bucket_count(&self) -> Result<usize, LengthError>;
    fn max_bucket_count(&self) -> usize;
    fn clear(&mut self);

    // Provided method
    fn is_power_of_two() -> bool { ... }
}
Expand description

Strategy for sizing the bucket array and mapping a hash to a bucket.

A policy is created with GrowthPolicy::new, which returns the policy and the bucket count it settled on. That count is at least the requested minimum. GrowthPolicy::bucket_for_hash and GrowthPolicy::clear must not allocate or panic.

Required Methods§

Source

fn new(min_bucket_count: usize) -> Result<(Self, usize), LengthError>

Build a policy for at least min_bucket_count buckets.

Returns the policy and the bucket count it settled on. That count is the requested minimum rounded up as the policy requires. Returns LengthError when the request is above GrowthPolicy::max_bucket_count.

When min_bucket_count is 0 the settled count is 0 and bucket_for_hash returns 0 for every hash.

Source

fn bucket_for_hash(&self, hash: usize) -> usize

Map hash to a bucket in [0, bucket_count).

Source

fn next_bucket_count(&self) -> Result<usize, LengthError>

The bucket count to use on the next growth.

Returns LengthError when the table cannot grow further.

Source

fn max_bucket_count(&self) -> usize

The largest bucket count the policy can represent.

Source

fn clear(&mut self)

Reset the policy to the state of a 0-bucket table.

Provided Methods§

Source

fn is_power_of_two() -> bool

Whether this policy keeps the bucket count a power of two.

The engine uses this to pick the mask-based probe path.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl GrowthPolicy for Prime

Source§

impl<const FACTOR: usize> GrowthPolicy for PowerOfTwo<FACTOR>

Source§

impl<const NUM: usize, const DEN: usize> GrowthPolicy for Mod<NUM, DEN>