1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Cuckoo hash based cache storage engine with fixed-size item slots.
//!
//! This crate implements an array-based cache that uses cuckoo hashing to map
//! keys to one of D=4 candidate positions in a flat array of fixed-size slots.
//! When all candidate positions for a new key are occupied, existing items may
//! be displaced to their alternative positions, up to a configurable depth.
//! If displacement fails, an item is evicted according to the configured policy.
//!
//! The design is based on the cuckoo storage engine from Pelikan:
//! <https://github.com/pelikan-io/pelikan>
//!
//! Goals:
//! * O(1) lookup with bounded worst case
//! * fixed per-item memory overhead
//! * bounded insertion latency via displacement limits
//!
//! Non-goals:
//! * not designed for concurrent access
//! * not suited for items larger than the configured slot size
extern crate log;
pub use Builder;
pub use CuckooCache;
pub use CuckooCacheError;
pub use Item;
pub use Value;
/// Eviction policy used when all candidate positions are occupied and
/// displacement cannot free a slot.
/// The number of candidate hash positions per item (D in the cuckoo
/// hashing literature).
pub const D: usize = 4;