Format

Struct Format 

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

Helpers for a given storage configuration.

Implementations§

Source§

impl Format

Source

pub fn new<S: Storage>(storage: &S) -> Option<Format>

Extracts the format from a storage.

Returns None if the storage is not supported.

Source

pub fn is_storage_supported<S: Storage>(storage: &S) -> bool

Returns whether a storage is supported.

A storage is supported if the following conditions hold:

Source

pub fn word_size(&self) -> Nat

The size of a word in bytes.

Source

pub fn page_size(&self) -> Nat

The size of a page in bytes.

This is at least MIN_PAGE_SIZE words and at most MAX_PAGE_SIZE bytes.

Source

pub fn num_pages(&self) -> Nat

The number of pages in the storage, denoted by N.

We have MIN_NUM_PAGES <= N <= MAX_PAGE_INDEX + 1.

Source

pub fn max_page(&self) -> Nat

The maximum page index.

This is at least MIN_NUM_PAGES - 1 and at most MAX_PAGE_INDEX.

Source

pub fn max_page_erases(&self) -> Nat

The maximum number of times a page can be erased, denoted by E.

We have E <= MAX_ERASE_CYCLE.

Source

pub fn max_key(&self) -> Nat

The maximum key.

Source

pub fn max_updates(&self) -> Nat

The maximum number of updates per transaction.

Source

pub fn virt_page_size(&self) -> Nat

The size of a virtual page in words, denoted by Q.

A virtual page is stored in a physical page after the page header.

We have MIN_PAGE_SIZE - 2 <= Q <= MAX_VIRT_PAGE_SIZE.

Source

pub fn max_value_len(&self) -> Nat

The maximum length in bytes of a user payload.

This is at least MIN_PAGE_SIZE - 3 words and at most MAX_VALUE_LEN.

Source

pub fn max_prefix_len(&self) -> Nat

The maximum prefix length in words, denoted by M.

A prefix is the first words of a virtual page that belong to the last entry of the previous virtual page. This happens because entries may overlap up to 2 virtual pages.

We have MIN_PAGE_SIZE - 3 <= M < Q.

Source

pub fn window_size(&self) -> Nat

The virtual window size in words, denoted by W.

This is the span of virtual storage that is accessible. In particular, all store content fits within this window.

We have W = (N - 1) * Q - M.

Source

pub fn virt_size(&self) -> Nat

The total virtual capacity in words, denoted by V.

This is the span of virtual storage after which we trigger a compaction. This is smaller than the virtual window because compaction may transiently overflow out of this virtual capacity.

We have V = W - (N - 1) = (N - 1) * (Q - 1) - M.

Source

pub fn total_capacity(&self) -> Nat

The total user capacity in words, denoted by C.

We have C = V - N = (N - 1) * (Q - 2) - M - 1.

We can show C >= (N - 2) * (Q - 2) - 2 with the following steps:

  • M <= Q - 1 from M < Q from M’s definition
  • C >= (N - 1) * (Q - 2) - (Q - 1) - 1 from C’s definition
  • C >= (N - 2) * (Q - 2) - 2 by calculus
Source

pub fn total_lifetime(&self) -> Position

The total virtual lifetime in words, denoted by L.

We have L = (E * N + N - 1) * Q.

Source

pub fn page_head(&self, init: InitInfo, page: Nat) -> Position

Returns the word position of the first entry of a page.

Source

pub fn index_init(&self, page: Nat) -> StorageIndex

Returns the storage index of the init info of a page.

Source

pub fn parse_init(&self, word: Word) -> Result<WordState<InitInfo>, Error>

Parses the init info of a page from its storage representation.

Source

pub fn build_init(&self, init: InitInfo) -> Result<WordSlice, Error>

Builds the storage representation of an init info.

Source

pub fn index_compact(&self, page: Nat) -> StorageIndex

Returns the storage index of the compact info of a page.

Source

pub fn parse_compact(&self, word: Word) -> Result<WordState<CompactInfo>, Error>

Parses the compact info of a page from its storage representation.

Source

pub fn build_compact(&self, compact: CompactInfo) -> Result<WordSlice, Error>

Builds the storage representation of a compact info.

Source

pub fn build_internal( &self, internal: InternalEntry, ) -> Result<WordSlice, Error>

Builds the storage representation of an internal entry.

Source

pub fn parse_word(&self, word: Word) -> Result<WordState<ParsedWord>, Error>

Parses the first word of an entry from its storage representation.

Source

pub fn build_user(&self, key: Nat, value: &[u8]) -> Result<Vec<u8>, Error>

Builds the storage representation of a user entry.

Source

pub fn set_padding(&self, word: &mut Word) -> Result<(), Error>

Sets the padding bit in the first word of a user entry.

Source

pub fn set_deleted(&self, word: &mut Word)

Sets the deleted bit in the first word of a user entry.

Source

pub fn transaction_capacity<ByteSlice: Borrow<[u8]>>( &self, updates: &[StoreUpdate<ByteSlice>], ) -> Nat

Returns the capacity required by a transaction.

Source

pub fn entry_size(&self, value: &[u8]) -> Nat

Returns the size of a user entry given its value.

Source

pub fn transaction_valid<ByteSlice: Borrow<[u8]>>( &self, updates: &[StoreUpdate<ByteSlice>], ) -> Option<Vec<Nat>>

Checks if a transaction is valid and returns its sorted keys.

Returns None if the transaction is invalid.

Source

pub fn bytes_to_words(&self, bytes: Nat) -> Nat

Returns the minimum number of words to represent a given number of bytes.

§Preconditions

Trait Implementations§

Source§

impl Clone for Format

Source§

fn clone(&self) -> Format

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Format

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Format

§

impl RefUnwindSafe for Format

§

impl Send for Format

§

impl Sync for Format

§

impl Unpin for Format

§

impl UnwindSafe for Format

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, 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> 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.