Skip to main content

CalculatedPageStates

Struct CalculatedPageStates 

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

A cache that uses knowledge about the typical layout of pages.

Use the ArrayPageStates cache or HeapPageStates cache when you have fewer than ~32 pages.

The layout is always as follows:

  • X amount of closed pages
  • Y amount of open pages
    • Y is at least 1
    • One of the open pages may be partial
  • If a partial page is present, it’s in the order ascending page indices: Closed -> Partial -> Open

The idea is to have an anchor which is the first open page (which may be the partial open page) and then keep track of the amount of open pages in front and the amount of closed pages behind it.

We know the anchor for sure when we find a partial open page. Since sequential-storage always iterates going forward and never back, we can have a ‘guessed’ anchor if we find the first open page. But when the anchor is guessed, we need to be a little pessimistic.

Thus, this cache isn’t able to remember every page state in every situation, but this is only the case when the anchor hasn’t been found yet. When the cache is fully warm, it does have perfect knowledge.

We don’t have to care about corruption, because when corruption is repaired the cache is invalidated.

Implementations§

Source§

impl CalculatedPageStates

Source

pub const fn new(page_count: usize) -> Self

Create a new empty cache for the amount of pages

Trait Implementations§

Source§

impl Debug for CalculatedPageStates

Source§

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

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

impl PageStatesCache for CalculatedPageStates

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