pub struct SLog<T: StableType + AsFixedSizeBytes> { /* private fields */ }Expand description
Non-reallocating growing vector optimized for storing logs or history entries
Very similar to SVec, but internally does not perform reallocations
nor moves of data. Instead, when the capacity is reached, a new block of stable memory (which
here is called a Sector) is allocated and attached to the end of the current block. So, in
some sense, this is a linked list, where each node can hold multiple elements.
T has to implement both StableType and AsFixedSizeBytes. SLog itself also implements these
trait, which means that you can store it inside an another stable structure.
This data structure is “infinite” - it can handle up to u64::MAX elements.
SLog grows exponentially - each new Sector is twice as big as the previous one. But if the
canister is short on stable memory, the newly created Sector may be shrunk, to be able to continue
to grow.
It is well optimized when you access elements near the end (the most recently added). The further the element you access from the end, the worser the performance.
Implementations§
Source§impl<T: StableType + AsFixedSizeBytes> SLog<T>
impl<T: StableType + AsFixedSizeBytes> SLog<T>
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all elements from this SLog
Deallocates all Sectors, but the first one, freeing the memory.
Sourcepub fn get(&self, idx: u64) -> Option<SRef<'_, T>>
pub fn get(&self, idx: u64) -> Option<SRef<'_, T>>
Returns an immutable reference SRef to an element at the requested index
See also SLog::get_mut.
The closer the index to 0, the worser the performance of this call.
Source§impl<T: StableType + AsFixedSizeBytes + Debug> SLog<T>
impl<T: StableType + AsFixedSizeBytes + Debug> SLog<T>
Sourcepub fn debug_print(&self)
pub fn debug_print(&self)
Prints sectored representation of this SLog
Useful for tests
Trait Implementations§
Source§impl<T: StableType + AsFixedSizeBytes> AsFixedSizeBytes for SLog<T>
impl<T: StableType + AsFixedSizeBytes> AsFixedSizeBytes for SLog<T>
Source§fn as_fixed_size_bytes(&self, buf: &mut [u8])
fn as_fixed_size_bytes(&self, buf: &mut [u8])
Source§fn from_fixed_size_bytes(buf: &[u8]) -> Self
fn from_fixed_size_bytes(buf: &[u8]) -> Self
Source§fn as_new_fixed_size_bytes(&self) -> Self::Buf
fn as_new_fixed_size_bytes(&self) -> Self::Buf
Source§impl<T: StableType + AsFixedSizeBytes> Default for SLog<T>
impl<T: StableType + AsFixedSizeBytes> Default for SLog<T>
Source§impl<T: StableType + AsFixedSizeBytes> Drop for SLog<T>
impl<T: StableType + AsFixedSizeBytes> Drop for SLog<T>
Source§impl<T: StableType + AsFixedSizeBytes> StableType for SLog<T>
impl<T: StableType + AsFixedSizeBytes> StableType for SLog<T>
Source§unsafe fn stable_drop_flag_off(&mut self)
unsafe fn stable_drop_flag_off(&mut self)
off position, if it is applicable Read moreSource§unsafe fn stable_drop_flag_on(&mut self)
unsafe fn stable_drop_flag_on(&mut self)
on position, if it is applicable Read more