Skip to main content

CompactMessageVec

Struct CompactMessageVec 

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

Sorted message storage with O(log n) lookup by ID.

Messages are stored sorted by timestamp. A separate index provides O(log n) lookup by message ID using binary search.

Implementations§

Source§

impl CompactMessageVec

Source

pub fn new() -> Self

Source

pub fn with_capacity(capacity: usize) -> Self

Source

pub fn len(&self) -> usize

Number of messages

Source

pub fn is_empty(&self) -> bool

Source

pub fn messages(&self) -> &[CompactMessage]

Get all messages (sorted by timestamp)

Source

pub fn messages_mut(&mut self) -> &mut Vec<CompactMessage>

Get a mutable reference to all messages

Source

pub fn iter(&self) -> Iter<'_, CompactMessage>

Iterate over messages (supports .rev())

Source

pub fn iter_mut(&mut self) -> IterMut<'_, CompactMessage>

Iterate over messages mutably

Source

pub fn last(&self) -> Option<&CompactMessage>

Get the last message

Source

pub fn last_timestamp(&self) -> Option<u64>

Get last message timestamp (in milliseconds)

Source

pub fn first(&self) -> Option<&CompactMessage>

Get the first message

Source

pub fn find_by_id(&self, id: &[u8; 32]) -> Option<&CompactMessage>

Find a message by ID using binary search - O(log n)

Source

pub fn find_by_id_mut(&mut self, id: &[u8; 32]) -> Option<&mut CompactMessage>

Find a message by ID (mutable) - O(log n)

Source

pub fn find_by_hex_id(&self, id_str: &str) -> Option<&CompactMessage>

Find a message by ID string (hex or pending) - O(log n)

Source

pub fn find_by_hex_id_mut( &mut self, id_str: &str, ) -> Option<&mut CompactMessage>

Find a message by ID string (mutable) - O(log n)

Source

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

Check if a message with the given ID exists - O(log n)

Source

pub fn remove_by_hex_id(&mut self, id_str: &str) -> bool

Remove a message by hex ID string. Returns true if removed.

Source

pub fn contains_hex_id(&self, id_str: &str) -> bool

Check if a message with the given ID string exists - O(log n)

Source

pub fn insert(&mut self, msg: CompactMessage) -> bool

Insert a message, maintaining sort order by timestamp.

Returns true if the message was added, false if duplicate ID.

Performance: O(log n) for append (common case), O(n) for out-of-order insert.

Source

pub fn rebuild_index(&mut self)

Rebuild the ID index (call after bulk modifications)

Source

pub fn insert_batch( &mut self, messages: impl IntoIterator<Item = CompactMessage>, ) -> usize

Batch insert messages - optimized for different scenarios.

Returns the number of messages actually added (excludes duplicates).

Performance:

  • Append case (newer msgs): O(k log n) where k = new messages
  • Prepend case (older msgs): O(k log n + k)
  • Mixed: O(n log n) full sort
Source

pub fn memory_usage(&self) -> usize

Total memory used (approximate)

Source

pub fn drain(&mut self, range: Range<usize>) -> Drain<'_, CompactMessage>

Drain messages from a range (rebuilds index after)

Source

pub fn sort_by_key<K, F>(&mut self, f: F)
where F: FnMut(&CompactMessage) -> K, K: Ord,

Sort messages by a key (rebuilds index after)

Source

pub fn clear(&mut self)

Clear all messages

Trait Implementations§

Source§

impl Clone for CompactMessageVec

Source§

fn clone(&self) -> CompactMessageVec

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompactMessageVec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DeepSize for CompactMessageVec

Source§

impl Default for CompactMessageVec

Source§

fn default() -> CompactMessageVec

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more