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
impl PageAllocator
Sourcepub fn new(freelist: VecDeque<u32>, next_extend: u32) -> Self
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.
Sourcepub fn set_preferred(&mut self, pool: Vec<u32>)
pub fn set_preferred(&mut self, pool: Vec<u32>)
Seeds the per-table preferred pool. Drained on subsequent
[allocate] calls before any other source.
Sourcepub fn finish_preferred(&mut self)
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).
Sourcepub fn allocate(&mut self) -> u32
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.
Sourcepub fn add_to_freelist(&mut self, pages: impl IntoIterator<Item = u32>)
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.
Sourcepub fn high_water(&self) -> u32
pub fn high_water(&self) -> u32
Page-count to publish in the new header. Equal to
1 + max page handed out after staging.
Sourcepub fn drain_freelist(&mut self) -> Vec<u32>
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.