Skip to main content

Layer

Struct Layer 

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

Live documents and tombstones produced by applying operations in order.

§Examples

use itzma_core::layer::Layer;
use itzma_core::{Document, WalOp};

let doc = |id: &str| Document { id: id.into(), vector: vec![1.0], attrs: None, sparse: None };

let mut older = Layer::new();
older.apply(WalOp::Upsert(doc("a")));

let mut newer = Layer::new();
newer.apply(WalOp::Delete("a".into()));

older.overlay(newer);
assert_eq!(older.doc_count(), 0);
assert_eq!(older.sorted_tombstones(), ["a"]);

Implementations§

Source§

impl Layer

Source

pub fn new() -> Self

An empty layer.

Source

pub fn apply(&mut self, op: WalOp)

Apply one operation. An upsert replaces the document and clears any tombstone for its id. A delete removes the document and records a tombstone, even when the id is not in this layer, because it may be hiding a document in an older one.

Source

pub fn apply_entry(&mut self, entry: WalEntry)

Apply every operation of one WAL entry, in order.

Source

pub fn apply_log(&mut self, log: Vec<(u64, WalEntry)>)

Apply every operation of every entry, in log order.

Source

pub fn overlay(&mut self, newer: Layer)

Put a newer layer on top of this one: its tombstones remove documents here, then its documents replace or add. Folding a range of operations in two halves and overlaying the results equals replaying the whole range.

Source

pub fn drop_tombstones(&mut self)

Forget every tombstone. Only right for a layer with nothing older beneath it, which is a segment that starts at WAL seq 1.

Source

pub fn doc_count(&self) -> usize

Number of live documents.

Source

pub fn tombstone_count(&self) -> usize

Number of tombstones.

Source

pub fn sorted_docs(&self) -> Vec<&Document>

Live documents in ascending id order. Sorting is what makes an encoded segment a pure function of the layer’s contents.

Source

pub fn sorted_tombstones(&self) -> Vec<&str>

Tombstoned ids in ascending order.

Source

pub fn into_docs(self) -> impl Iterator<Item = Document>

Consume the layer, yielding its live documents in no particular order.

Trait Implementations§

Source§

impl Clone for Layer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Layer

Source§

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

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

impl Default for Layer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Layer

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Layer

Auto Trait Implementations§

§

impl Forget for Layer

§

impl Freeze for Layer

§

impl Move for Layer

§

impl RefUnwindSafe for Layer

§

impl Send for Layer
where RawTable<(String, Document)>: Send, RawTable<(String, ())>: Send,

§

impl Sync for Layer
where RawTable<(String, Document)>: Sync, RawTable<(String, ())>: Sync,

§

impl Unpin for Layer
where *const u8 is !null: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin,

§

impl UnsafeUnpin for Layer

§

impl UnwindSafe for Layer

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.