Skip to main content

Module growth_policy

Module growth_policy 

Source
Expand description

Growth policies that map a hash to a bucket and decide the next table size.

A policy owns the current bucket count and translates a hash into a bucket index. Three strategies are provided:

  • PowerOfTwo keeps the bucket count a power of two and maps with a mask. Fast, and the default.
  • Mod grows by a rational factor and maps with a modulo. Useful for slower growth.
  • Prime uses a fixed table of primes. It spreads values better when the hash function is poor, such as an identity hash of pointers.

Each policy is constructed from a minimum bucket count. The policy may round that value up and reports the value it settled on. A request above the policy maximum returns LengthError.

Structs§

LengthError
The requested bucket count exceeds what a growth policy can represent.
Mod
Grow by the rational factor NUM / DEN and map with a modulo.
PowerOfTwo
Grow by a power-of-two factor and map with a mask.
Prime
Grow by stepping through a fixed table of primes and map with a modulo.

Constants§

PRIMES_TABLE
The prime table used by Prime. Ascending, 40 entries.

Traits§

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