pub struct Format { /* private fields */ }Expand description
Helpers for a given storage configuration.
Implementations§
Source§impl Format
impl Format
Sourcepub fn new<S: Storage>(storage: &S) -> Option<Format>
pub fn new<S: Storage>(storage: &S) -> Option<Format>
Extracts the format from a storage.
Returns None if the storage is not supported.
Sourcepub fn is_storage_supported<S: Storage>(storage: &S) -> bool
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:
- The
Storage::word_sizeisWORD_SIZEbytes. - The
Storage::word_sizeevenly divides theStorage::page_size. - The
Storage::page_sizeis betweenMIN_PAGE_SIZEwords andMAX_PAGE_SIZEbytes. - The
Storage::num_pagesis betweenMIN_NUM_PAGESandMAX_PAGE_INDEX+ 1. - The
Storage::max_word_writesis at least 2. - The
Storage::max_page_erasesis at mostMAX_ERASE_CYCLE.
Sourcepub fn page_size(&self) -> Nat
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.
Sourcepub fn num_pages(&self) -> Nat
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.
Sourcepub fn max_page(&self) -> Nat
pub fn max_page(&self) -> Nat
The maximum page index.
This is at least MIN_NUM_PAGES - 1 and at most MAX_PAGE_INDEX.
Sourcepub fn max_page_erases(&self) -> Nat
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.
Sourcepub fn max_updates(&self) -> Nat
pub fn max_updates(&self) -> Nat
The maximum number of updates per transaction.
Sourcepub fn virt_page_size(&self) -> Nat
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.
Sourcepub fn max_value_len(&self) -> Nat
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.
Sourcepub fn max_prefix_len(&self) -> Nat
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.
Sourcepub fn window_size(&self) -> Nat
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.
Sourcepub fn virt_size(&self) -> Nat
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.
Sourcepub fn total_capacity(&self) -> Nat
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
Sourcepub fn total_lifetime(&self) -> Position
pub fn total_lifetime(&self) -> Position
The total virtual lifetime in words, denoted by L.
We have L = (E * N + N - 1) * Q.
Sourcepub fn page_head(&self, init: InitInfo, page: Nat) -> Position
pub fn page_head(&self, init: InitInfo, page: Nat) -> Position
Returns the word position of the first entry of a page.
Sourcepub fn index_init(&self, page: Nat) -> StorageIndex
pub fn index_init(&self, page: Nat) -> StorageIndex
Returns the storage index of the init info of a page.
Sourcepub fn parse_init(&self, word: Word) -> Result<WordState<InitInfo>, Error>
pub fn parse_init(&self, word: Word) -> Result<WordState<InitInfo>, Error>
Parses the init info of a page from its storage representation.
Sourcepub fn build_init(&self, init: InitInfo) -> Result<WordSlice, Error>
pub fn build_init(&self, init: InitInfo) -> Result<WordSlice, Error>
Builds the storage representation of an init info.
Sourcepub fn index_compact(&self, page: Nat) -> StorageIndex
pub fn index_compact(&self, page: Nat) -> StorageIndex
Returns the storage index of the compact info of a page.
Sourcepub fn parse_compact(&self, word: Word) -> Result<WordState<CompactInfo>, Error>
pub fn parse_compact(&self, word: Word) -> Result<WordState<CompactInfo>, Error>
Parses the compact info of a page from its storage representation.
Sourcepub fn build_compact(&self, compact: CompactInfo) -> Result<WordSlice, Error>
pub fn build_compact(&self, compact: CompactInfo) -> Result<WordSlice, Error>
Builds the storage representation of a compact info.
Sourcepub fn build_internal(
&self,
internal: InternalEntry,
) -> Result<WordSlice, Error>
pub fn build_internal( &self, internal: InternalEntry, ) -> Result<WordSlice, Error>
Builds the storage representation of an internal entry.
Sourcepub fn parse_word(&self, word: Word) -> Result<WordState<ParsedWord>, Error>
pub fn parse_word(&self, word: Word) -> Result<WordState<ParsedWord>, Error>
Parses the first word of an entry from its storage representation.
Sourcepub fn build_user(&self, key: Nat, value: &[u8]) -> Result<Vec<u8>, Error>
pub fn build_user(&self, key: Nat, value: &[u8]) -> Result<Vec<u8>, Error>
Builds the storage representation of a user entry.
Sourcepub fn set_padding(&self, word: &mut Word) -> Result<(), Error>
pub fn set_padding(&self, word: &mut Word) -> Result<(), Error>
Sets the padding bit in the first word of a user entry.
Sourcepub fn set_deleted(&self, word: &mut Word)
pub fn set_deleted(&self, word: &mut Word)
Sets the deleted bit in the first word of a user entry.
Sourcepub fn transaction_capacity<ByteSlice: Borrow<[u8]>>(
&self,
updates: &[StoreUpdate<ByteSlice>],
) -> Nat
pub fn transaction_capacity<ByteSlice: Borrow<[u8]>>( &self, updates: &[StoreUpdate<ByteSlice>], ) -> Nat
Returns the capacity required by a transaction.
Sourcepub fn entry_size(&self, value: &[u8]) -> Nat
pub fn entry_size(&self, value: &[u8]) -> Nat
Returns the size of a user entry given its value.
Sourcepub fn transaction_valid<ByteSlice: Borrow<[u8]>>(
&self,
updates: &[StoreUpdate<ByteSlice>],
) -> Option<Vec<Nat>>
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.
Sourcepub fn bytes_to_words(&self, bytes: Nat) -> Nat
pub fn bytes_to_words(&self, bytes: Nat) -> Nat
Returns the minimum number of words to represent a given number of bytes.
§Preconditions
bytes+Self::word_sizedoes not overflow.