Expand description
§Sparse Bitmap
A module that provides an efficient way to track message nonces using a sparse bitmap.
§Overview
The SparseBitmap
uses a StorageMap<u64, u128>
to store bit flags for a large range of
nonces. Each key (bucket) in the storage map contains a 128-bit value that can track 128
individual nonces.
The implementation efficiently maps a u64 index (nonce) to:
- A bucket - calculated as
index >> 7
(dividing by 128) - A bit position - calculated as
index & 127
(remainder when dividing by 128)
§Example
For nonce 300:
- Bucket = 300 >> 7 = 2 (third bucket)
- Bit position = 300 & 127 = 44 (45th bit in the bucket)
- Corresponding bit mask = 1 << 44
This approach allows tracking up to 2^64 nonces while only storing buckets that actually contain data, making it suitable for sparse sets of nonces across a wide range.
Structs§
- Sparse bitmap implementation.
Traits§
- Sparse bitmap interface.