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
impl CompactMessageVec
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
pub fn is_empty(&self) -> bool
Sourcepub fn messages(&self) -> &[CompactMessage]
pub fn messages(&self) -> &[CompactMessage]
Get all messages (sorted by timestamp)
Sourcepub fn messages_mut(&mut self) -> &mut Vec<CompactMessage>
pub fn messages_mut(&mut self) -> &mut Vec<CompactMessage>
Get a mutable reference to all messages
Sourcepub fn iter(&self) -> Iter<'_, CompactMessage>
pub fn iter(&self) -> Iter<'_, CompactMessage>
Iterate over messages (supports .rev())
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, CompactMessage>
pub fn iter_mut(&mut self) -> IterMut<'_, CompactMessage>
Iterate over messages mutably
Sourcepub fn last(&self) -> Option<&CompactMessage>
pub fn last(&self) -> Option<&CompactMessage>
Get the last message
Sourcepub fn last_timestamp(&self) -> Option<u64>
pub fn last_timestamp(&self) -> Option<u64>
Get last message timestamp (in milliseconds)
Sourcepub fn first(&self) -> Option<&CompactMessage>
pub fn first(&self) -> Option<&CompactMessage>
Get the first message
Sourcepub fn find_by_id(&self, id: &[u8; 32]) -> Option<&CompactMessage>
pub fn find_by_id(&self, id: &[u8; 32]) -> Option<&CompactMessage>
Find a message by ID using binary search - O(log n)
Sourcepub fn find_by_id_mut(&mut self, id: &[u8; 32]) -> Option<&mut CompactMessage>
pub fn find_by_id_mut(&mut self, id: &[u8; 32]) -> Option<&mut CompactMessage>
Find a message by ID (mutable) - O(log n)
Sourcepub fn find_by_hex_id(&self, id_str: &str) -> Option<&CompactMessage>
pub fn find_by_hex_id(&self, id_str: &str) -> Option<&CompactMessage>
Find a message by ID string (hex or pending) - O(log n)
Sourcepub fn find_by_hex_id_mut(
&mut self,
id_str: &str,
) -> Option<&mut CompactMessage>
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)
Sourcepub fn contains_id(&self, id: &[u8; 32]) -> bool
pub fn contains_id(&self, id: &[u8; 32]) -> bool
Check if a message with the given ID exists - O(log n)
Sourcepub fn remove_by_hex_id(&mut self, id_str: &str) -> bool
pub fn remove_by_hex_id(&mut self, id_str: &str) -> bool
Remove a message by hex ID string. Returns true if removed.
Sourcepub fn contains_hex_id(&self, id_str: &str) -> bool
pub fn contains_hex_id(&self, id_str: &str) -> bool
Check if a message with the given ID string exists - O(log n)
Sourcepub fn insert(&mut self, msg: CompactMessage) -> bool
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.
Sourcepub fn rebuild_index(&mut self)
pub fn rebuild_index(&mut self)
Rebuild the ID index (call after bulk modifications)
Sourcepub fn insert_batch(
&mut self,
messages: impl IntoIterator<Item = CompactMessage>,
) -> usize
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
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Total memory used (approximate)
Sourcepub fn drain(&mut self, range: Range<usize>) -> Drain<'_, CompactMessage>
pub fn drain(&mut self, range: Range<usize>) -> Drain<'_, CompactMessage>
Drain messages from a range (rebuilds index after)
Sourcepub fn sort_by_key<K, F>(&mut self, f: F)
pub fn sort_by_key<K, F>(&mut self, f: F)
Sort messages by a key (rebuilds index after)
Trait Implementations§
Source§impl Clone for CompactMessageVec
impl Clone for CompactMessageVec
Source§fn clone(&self) -> CompactMessageVec
fn clone(&self) -> CompactMessageVec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompactMessageVec
impl Debug for CompactMessageVec
Source§impl Default for CompactMessageVec
impl Default for CompactMessageVec
Source§fn default() -> CompactMessageVec
fn default() -> CompactMessageVec
Auto Trait Implementations§
impl Freeze for CompactMessageVec
impl RefUnwindSafe for CompactMessageVec
impl Send for CompactMessageVec
impl Sync for CompactMessageVec
impl Unpin for CompactMessageVec
impl UnsafeUnpin for CompactMessageVec
impl UnwindSafe for CompactMessageVec
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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