Skip to main content

PacketHashlist

Struct PacketHashlist 

Source
pub struct PacketHashlist { /* private fields */ }
Expand description

Double-buffered packet hash deduplication.

Uses two BTreeSets: current and previous. When the current set grows past max_size / 2, it rotates: current becomes previous, and a new empty set becomes current. This means the oldest hashes are forgotten after two rotations.

Implementations§

Source§

impl PacketHashlist

Source

pub fn new(max_size: usize) -> Self

Source

pub fn is_duplicate(&self, hash: &[u8; 32]) -> bool

Check if a hash is a duplicate (exists in current or previous set).

Source

pub fn add(&mut self, hash: [u8; 32])

Add a hash to the current set.

Source

pub fn maybe_rotate(&mut self) -> bool

Rotate if current set exceeds max_size / 2. Returns true if rotation occurred.

Source

pub fn len(&self) -> usize

Total number of tracked hashes (current + previous).

Source

pub fn current_len(&self) -> usize

Number of hashes in the current set only.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.