pub struct MessageDeduplicator { /* private fields */ }Expand description
Two-layer message deduplicator: Bloom filter + bounded LRU cache.
See module documentation for usage.
Implementations§
Source§impl MessageDeduplicator
impl MessageDeduplicator
Sourcepub fn new(config: DedupConfig) -> Self
pub fn new(config: DedupConfig) -> Self
Create a new deduplicator with the given configuration.
Sourcepub fn check_and_insert(&mut self, msg_id: &MsgId, now: u64) -> bool
pub fn check_and_insert(&mut self, msg_id: &MsgId, now: u64) -> bool
Check whether msg_id has been seen before and, if not, record it.
Returns true if the message is a duplicate (was already seen),
false if it is new (first occurrence).
now is the caller-supplied timestamp in milliseconds (e.g. from
std::time::SystemTime or a monotonic clock).
Sourcepub fn is_duplicate_bloom(&self, msg_id: &MsgId) -> bool
pub fn is_duplicate_bloom(&self, msg_id: &MsgId) -> bool
Check the bloom filter alone (probabilistic — may have false positives).
Returns true if the bloom filter believes msg_id was seen before.
Sourcepub fn insert_bloom(&mut self, msg_id: &MsgId)
pub fn insert_bloom(&mut self, msg_id: &MsgId)
Set the bloom filter bits for msg_id.
Sourcepub fn bloom_bit_positions(msg_id: &MsgId, count: u32) -> Vec<usize>
pub fn bloom_bit_positions(msg_id: &MsgId, count: u32) -> Vec<usize>
Compute count bloom bit positions for msg_id using
Kirsch-Mitzenmacher double hashing over FNV-1a.
Uses two independent FNV-1a 64-bit hashes (h1, h2) and derives
positions as (h1 + i * h2) mod usize::MAX. The modulo against the
actual bit-array size is applied by the caller.
Sourcepub fn make_msg_id(data: &[u8]) -> MsgId
pub fn make_msg_id(data: &[u8]) -> MsgId
Sourcepub fn purge_expired(&mut self, now: u64) -> usize
pub fn purge_expired(&mut self, now: u64) -> usize
Remove all cache entries whose first_seen timestamp is older than
now - window_ms. Returns the number of entries purged.
Note: the bloom filter is not cleared by this call (bloom filters do not support deletion). Only the exact cache is pruned.
Sourcepub fn evict_oldest(&mut self) -> bool
pub fn evict_oldest(&mut self) -> bool
Evict the oldest (least recently inserted) entry from the cache.
Returns true if an entry was evicted, false if the cache was empty.
Sourcepub fn seen_count(&self) -> usize
pub fn seen_count(&self) -> usize
Return the number of unique entries currently in the exact cache.
Sourcepub fn stats(&self) -> &MsgDedupStats
pub fn stats(&self) -> &MsgDedupStats
Return a reference to the accumulated statistics.
Auto Trait Implementations§
impl Freeze for MessageDeduplicator
impl RefUnwindSafe for MessageDeduplicator
impl Send for MessageDeduplicator
impl Sync for MessageDeduplicator
impl Unpin for MessageDeduplicator
impl UnsafeUnpin for MessageDeduplicator
impl UnwindSafe for MessageDeduplicator
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more