pub struct PacketHashlist { /* private fields */ }Expand description
Bounded FIFO packet-hash deduplication.
Retains at most max_size unique packet hashes. New unique hashes are
appended in insertion order; when full, the oldest retained hash is evicted.
Re-inserting a retained hash is a no-op and does not refresh its recency.
Implementations§
Source§impl PacketHashlist
impl PacketHashlist
pub fn new(max_size: usize) -> Self
Sourcepub fn with_allocation(
max_size: usize,
allocation: PacketHashlistAllocation,
) -> Self
pub fn with_allocation( max_size: usize, allocation: PacketHashlistAllocation, ) -> Self
A table retaining up to max_size hashes. Its storage is allocated
once, at full size, and never moved or freed while the table lives,
so growth leaves no freed blocks behind for the allocator to keep.
Eager touches every slot up front; Lazy leaves the slots to be
touched as hashes are written, in order, and uses a prefix of the
index that doubles with occupancy, so a table’s resident memory
follows the hashes it holds.
Sourcepub fn seed_hashing(&mut self, seed: u64)
pub fn seed_hashing(&mut self, seed: u64)
Key bucket placement with a secret seed, so that senders cannot
grind packets whose hashes share a probe sequence. Unseeded tables
index buckets by the hashes’ leading bits.
Sourcepub fn is_duplicate(&self, hash: &[u8; 32]) -> bool
pub fn is_duplicate(&self, hash: &[u8; 32]) -> bool
Check if a hash is currently retained.
Sourcepub fn prefetch(&self, hash: &[u8; 32])
pub fn prefetch(&self, hash: &[u8; 32])
Start loading the bucket a lookup of hash probes first, so a later
is_duplicate or add for it can
overlap that cache miss with other work.
Sourcepub fn add(&mut self, hash: [u8; 32])
pub fn add(&mut self, hash: [u8; 32])
Retain a hash. If the dedup table is full, evict the oldest unique hash.
Sourcepub fn remove(&mut self, hash: &[u8; 32]) -> bool
pub fn remove(&mut self, hash: &[u8; 32]) -> bool
Stop retaining a hash, preserving the FIFO order of all other entries.