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§
Sourcefn new(min_bucket_count: usize) -> Result<(Self, usize), LengthError>
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.
Sourcefn bucket_for_hash(&self, hash: usize) -> usize
fn bucket_for_hash(&self, hash: usize) -> usize
Map hash to a bucket in [0, bucket_count).
Sourcefn next_bucket_count(&self) -> Result<usize, LengthError>
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.
Sourcefn max_bucket_count(&self) -> usize
fn max_bucket_count(&self) -> usize
The largest bucket count the policy can represent.
Provided Methods§
Sourcefn is_power_of_two() -> bool
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".