Skip to main content

PageAllocator

Struct PageAllocator 

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

Hands out page numbers during a save.

Lifetime: one allocator per save_database call. Not thread-safe; not shared across saves.

Implementations§

Source§

impl PageAllocator

Source

pub fn new(freelist: VecDeque<u32>, next_extend: u32) -> Self

freelist carries the pages from the previously-persisted freelist (sorted ascending by the caller). next_extend is typically 1 for a brand-new save.

Source

pub fn set_preferred(&mut self, pool: Vec<u32>)

Seeds the per-table preferred pool. Drained on subsequent [allocate] calls before any other source.

Source

pub fn finish_preferred(&mut self)

Empties the per-table preferred pool, returning any leftover pages to the global freelist (they’re now free again).

Source

pub fn allocate(&mut self) -> u32

Returns the next page to write. Picks from preferred → freelist → extend. Records the result in used and bumps next_extend if the page came from one of the pools and was past the current high water.

Source

pub fn add_to_freelist(&mut self, pages: impl IntoIterator<Item = u32>)

Adds pages to the global freelist. Used to drop pages that the caller traversed but didn’t end up restaging (e.g., a dropped table’s leaves; the previous freelist’s trunk pages).

Bumps next_extend past any added page so the final page_count covers freelist trunks even if they live past the highest used payload page.

Source

pub fn high_water(&self) -> u32

Page-count to publish in the new header. Equal to 1 + max page handed out after staging.

Source

pub fn used(&self) -> &HashSet<u32>

Every page handed out this save.

Source

pub fn drain_freelist(&mut self) -> Vec<u32>

Snapshot of pages still on the global freelist (i.e., free pages that need to be persisted into trunk pages). Sorted ascending so the encoded freelist trunks are deterministic.

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.