Struct rustdb::sortedfile::SortedFile

source ·
pub struct SortedFile {
    pub dirty_pages: RefCell<FxHashMap<u64, PagePtr>>,
    pub rec_size: usize,
    pub key_size: usize,
    pub root_page: Cell<u64>,
    pub ok: Cell<bool>,
}
Expand description

Sorted Record storage.

SortedFile is a tree of pages.

Each page is either a parent page with links to child pages, or a leaf page.

Fields§

§dirty_pages: RefCell<FxHashMap<u64, PagePtr>>

Map of pages that have not been saved..

§rec_size: usize

Size of a record.

§key_size: usize

Size of a key.

§root_page: Cell<u64>

The root page.

§ok: Cell<bool>

Status

Implementations§

source§

impl SortedFile

source

pub fn new(rec_size: usize, key_size: usize, root_page: u64) -> Self

Create File with specified record size, key size, root page.

source

pub fn changed(&self) -> bool

Test whether file has unsaved changes.

source

pub fn save(&self, db: &DB, op: SaveOp)

Save changes to underlying storage.

source

pub fn rollback(&self)

Clear the cache, changes are discarded instead of being saved.

source

pub fn free_pages(&self, db: &DB, r: &dyn Record)

Free the underlying storage. File is not useable after this.

source

pub fn insert(&self, db: &DB, r: &dyn Record)

Insert a Record. Panics if the key is a duplicate.

source

pub fn remove(&self, db: &DB, r: &dyn Record)

Remove a Record.

source

pub fn get(&self, db: &DB, r: &dyn Record) -> Option<(PagePtr, usize)>

Locate a record with matching key. Result is PagePtr and offset of data.

source

pub fn asc(self: &Rc<Self>, db: &DB, start: Box<dyn Record>) -> Asc

For iteration in ascending order from start.

source

pub fn dsc(self: &Rc<Self>, db: &DB, start: Box<dyn Record>) -> Dsc

For iteration in descending order from start.

source

pub fn set_dirty(&self, p: &mut Page, pp: &PagePtr)

Mark a page as changed.

source

pub fn repack(&self, db: &DB, r: &dyn Record) -> i64

Attempt to free up logical pages by re-packing child pages.

source

pub fn get_used(&self, db: &DB, to: &mut HashSet<u64>)

Get the set of used logical pages.

source

pub fn ren(&self, from: u64, db: &DB) -> u64

Renumber, adjusting cache.

source

pub fn renumber(&self, db: &DB, target: u64)

Renumber pages >= target.

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

§

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

§

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.