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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2021 Twitter, Inc.
// Copyright 2023 Pelikan Cache contributors
// Licensed under the MIT and Apache-2.0 licenses
//! Hash buckets are used to store a group of item entries with a shared
//! metadata entry.
//!
//! Bucket Info:
//! ```text
//! ┌──────────────────────────────┬──────┬──────┬──────────────┐
//! │ CAS │ ---- │CHAIN │ TIMESTAMP │
//! │ │ │ LEN │ │
//! │ 32 bit │8 bit │8 bit │ 16 bit │
//! │ │ │ LEN │ │
//! │0 31│32 39|40 47|48 63|
//! └──────────────────────────────┴──────┴──────┴──────────────┘
//! ```
//!
//! Item Info:
//! ```text
//! ┌──────────┬──────┬──────────────────────┬──────────────────┐
//! │ TAG │ FREQ │ SEG ID │ OFFSET │
//! │ │ │ │ │
//! │ 12 bit │8 bit │ 24 bit │ 20 bit │
//! │ │ │ │ │
//! │0 11│12 19│20 43│44 63│
//! └──────────┴──────┴──────────────────────┴──────────────────┘
//! ```
use *;
/// A mask to get the bits containing the chain length from the bucket info
pub const BUCKET_CHAIN_LEN_MASK: u64 = 0x0000_0000_00FF_0000;
/// A mask to get the bits containing the timestamp from the bucket info
pub const TS_MASK: u64 = 0x0000_0000_0000_FFFF;
/// A mask to get the bits containing the CAS value from the bucket info
pub const CAS_MASK: u64 = 0xFFFF_FFFF_0000_0000;
/// Number of bits to shift the bucket info masked with the chain length mask
/// to get the actual chain length
pub const BUCKET_CHAIN_LEN_BIT_SHIFT: u64 = 16;
/// Number of bits to shift the bucket info masked with the cas mask to get the
/// cas value
pub const CAS_BIT_SHIFT: u64 = 32;
// item info
/// A mask to get the bits containing the item tag from the item info
pub const TAG_MASK: u64 = 0xFFF0_0000_0000_0000;
/// A mask to get the bits containing the item frequency from the item info
pub const FREQ_MASK: u64 = 0x000F_F000_0000_0000;
/// A mask to get the bits containing the containing segment id from the item
/// info
pub const SEG_ID_MASK: u64 = 0x0000_0FFF_FFF0_0000;
/// A mask to get the bits containing the offset within the containing segment
/// from the item info
pub const OFFSET_MASK: u64 = 0x0000_0000_000F_FFFF;
/// Number of bits to shift the item info masked with the frequency mask to get
/// the actual item frequency
pub const FREQ_BIT_SHIFT: u64 = 44;
/// Number of bits to shift the item info masked with the segment id mask to get
/// the actual segment id
pub const SEG_ID_BIT_SHIFT: u64 = 20;
/// Offset alignment in bits, this value results in 8byte alignment within the
/// segment
pub const OFFSET_UNIT_IN_BIT: u64 = 3;
/// Mask to get the item info without the frequency smoothing bit set
pub const CLEAR_FREQ_SMOOTH_MASK: u64 = 0xFFF7_FFFF_FFFF_FFFF;
/// Mask to get the lower 16 bits from a timestamp
pub const PROC_TS_MASK: u32 = 0x0000_FFFF;
pub
/// Calculate a item's tag from the hash value
pub const
/// Get the item's offset from the item info
pub const
/// Get the item's segment from the item info
pub const
/// Get the item frequency from the item info
pub const
/// Get the CAS value from the bucket info
pub const
/// Get the timestamp from the bucket info
pub const
/// Get the tag from the item info
pub const
/// Returns the item info with the frequency cleared
pub const
/// Get the chain length from the bucket info
pub const
/// Create the item info from the tag, segment id, and offset
pub const