Skip to main content

PATCH

Struct PATCH 

Source
pub struct PATCH<const KEY_LEN: usize, O = IdentitySchema, V = ()>
where O: KeySchema<KEY_LEN>,
{ /* private fields */ }
Expand description

A PATCH is a persistent data structure that stores a set of keys. Each key can be reordered and segmented, based on the provided key ordering and segmentation.

The patch supports efficient set operations, like union, intersection, and difference, because it efficiently maintains a hash for all keys that are part of a sub-tree.

The tree itself is a path- and node-compressed a 256-ary trie. Each nodes stores its children in a byte oriented cuckoo hash table, allowing for O(1) access to children, while keeping the memory overhead low. Table sizes are powers of two, starting at 2.

Having a single node type for all branching factors simplifies the implementation, compared to other adaptive trie implementations, like ARTs or Judy Arrays

The PATCH allows for cheap copy-on-write operations, with clone being O(1).

Implementations§

Source§

impl<const KEY_LEN: usize, O, V> PATCH<KEY_LEN, O, V>
where O: KeySchema<KEY_LEN>,

Source

pub fn new() -> Self

Creates a new empty PATCH.

Source

pub fn insert(&mut self, entry: &Entry<KEY_LEN, V>)

Inserts a shared key into the PATCH.

Takes an Entry object that can be created from a key, and inserted into multiple PATCH instances.

If the key is already present, this is a no-op.

Source

pub fn replace(&mut self, entry: &Entry<KEY_LEN, V>)

Inserts a key into the PATCH, replacing the value if it already exists.

Source

pub fn remove(&mut self, key: &[u8; KEY_LEN])

Removes a key from the PATCH.

If the key is not present, this is a no-op.

Source

pub fn len(&self) -> u64

Returns the number of keys in the PATCH.

Source

pub fn is_empty(&self) -> bool

Returns true if the PATCH contains no keys.

Source

pub fn get(&self, key: &[u8; KEY_LEN]) -> Option<&V>

Returns the value associated with key if present.

Source

pub fn infixes<const PREFIX_LEN: usize, const INFIX_LEN: usize, F>( &self, prefix: &[u8; PREFIX_LEN], for_each: F, )
where F: FnMut(&[u8; INFIX_LEN]),

Allows iteratig over all infixes of a given length with a given prefix. Each infix is passed to the provided closure.

The entire operation is performed over the tree view ordering of the keys.

The length of the prefix and the infix is provided as type parameters, but will usually inferred from the arguments.

The sum of PREFIX_LEN and INFIX_LEN must be less than or equal to KEY_LEN or a compile-time assertion will fail.

Because all infixes are iterated in one go, less bookkeeping is required, than when using an Iterator, allowing for better performance.

Source

pub fn has_prefix<const PREFIX_LEN: usize>( &self, prefix: &[u8; PREFIX_LEN], ) -> bool

Returns true if the PATCH has a key with the given prefix.

PREFIX_LEN must be less than or equal to KEY_LEN or a compile-time assertion will fail.

Source

pub fn segmented_len<const PREFIX_LEN: usize>( &self, prefix: &[u8; PREFIX_LEN], ) -> u64

Returns the number of unique segments in keys with the given prefix.

Source

pub fn iter<'a>(&'a self) -> PATCHIterator<'a, KEY_LEN, O, V>

Iterates over all keys in the PATCH. The keys are returned in key ordering but random order.

Source

pub fn iter_ordered<'a>(&'a self) -> PATCHOrderedIterator<'a, KEY_LEN, O, V>

Iterates over all keys in the PATCH in key order.

The traversal visits every key in lexicographic key order, without accepting a prefix filter. For prefix-aware iteration, see PATCH::iter_prefix_count.

Source

pub fn iter_prefix_count<'a, const PREFIX_LEN: usize>( &'a self, ) -> PATCHPrefixIterator<'a, KEY_LEN, PREFIX_LEN, O, V>

Iterate over all prefixes of the given length in the PATCH. The prefixes are naturally returned in tree ordering and tree order. A count of the number of elements for the given prefix is also returned.

Source

pub fn union(&mut self, other: Self)

Unions this PATCH with another PATCH.

The other PATCH is consumed, and this PATCH is updated in place.

Source

pub fn intersect(&self, other: &Self) -> Self

Intersects this PATCH with another PATCH.

Returns a new PATCH that contains only the keys that are present in both PATCHes.

Source

pub fn difference(&self, other: &Self) -> Self

Returns the difference between this PATCH and another PATCH.

Returns a new PATCH that contains only the keys that are present in this PATCH, but not in the other PATCH.

Source

pub fn debug_branch_fill(&self) -> [f32; 8]

Calculates the average fill level for branch nodes grouped by their branching factor. The returned array contains eight entries for branch sizes 2, 4, 8, 16, 32, 64, 128 and 256 in that order.

Source§

impl<const KEY_LEN: usize, O: KeySchema<KEY_LEN>, V> PATCH<KEY_LEN, O, V>

Source

pub fn into_iter_ordered(self) -> PATCHIntoOrderedIterator<KEY_LEN, O, V>

Consume and return an iterator that yields keys in key order.

Trait Implementations§

Source§

impl<const KEY_LEN: usize, O, V> Clone for PATCH<KEY_LEN, O, V>
where O: KeySchema<KEY_LEN>,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, S: ValueSchema> ContainsConstraint<'a, S> for &'a PATCH<VALUE_LEN, IdentitySchema, ()>

Source§

type Constraint = PatchValueConstraint<'a, S>

The concrete constraint type produced by has.
Source§

fn has(self, v: Variable<S>) -> Self::Constraint

Create a constraint that filters the values assigned to the variable to only those that are contained in the collection. Read more
Source§

impl<'a, S: ValueSchema> ContainsConstraint<'a, S> for PATCH<ID_LEN, IdentitySchema, ()>

Source§

type Constraint = PatchIdConstraint<S>

The concrete constraint type produced by has.
Source§

fn has(self, v: Variable<S>) -> Self::Constraint

Create a constraint that filters the values assigned to the variable to only those that are contained in the collection. Read more
Source§

impl<const KEY_LEN: usize, O, V: Debug> Debug for PATCH<KEY_LEN, O, V>
where O: KeySchema<KEY_LEN> + Debug,

Source§

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

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

impl<const KEY_LEN: usize, O, V> Default for PATCH<KEY_LEN, O, V>
where O: KeySchema<KEY_LEN>,

Source§

fn default() -> Self

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

impl<'a, const KEY_LEN: usize, O, V> IntoIterator for &'a PATCH<KEY_LEN, O, V>
where O: KeySchema<KEY_LEN>,

Source§

type Item = &'a [u8; KEY_LEN]

The type of the elements being iterated over.
Source§

type IntoIter = PATCHIterator<'a, KEY_LEN, O, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<const KEY_LEN: usize, O: KeySchema<KEY_LEN>, V> IntoIterator for PATCH<KEY_LEN, O, V>

Source§

type Item = [u8; KEY_LEN]

The type of the elements being iterated over.
Source§

type IntoIter = PATCHIntoIterator<KEY_LEN, O, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<const KEY_LEN: usize, O, V> PartialEq for PATCH<KEY_LEN, O, V>
where O: KeySchema<KEY_LEN>,

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const KEY_LEN: usize, O, V> Eq for PATCH<KEY_LEN, O, V>
where O: KeySchema<KEY_LEN>,

Auto Trait Implementations§

§

impl<const KEY_LEN: usize, O, V> Freeze for PATCH<KEY_LEN, O, V>

§

impl<const KEY_LEN: usize, O, V> RefUnwindSafe for PATCH<KEY_LEN, O, V>

§

impl<const KEY_LEN: usize, O, V> Send for PATCH<KEY_LEN, O, V>

§

impl<const KEY_LEN: usize, O, V> Sync for PATCH<KEY_LEN, O, V>

§

impl<const KEY_LEN: usize, O, V> Unpin for PATCH<KEY_LEN, O, V>
where O: Unpin, <O as KeySchema<KEY_LEN>>::Segmentation: Unpin, V: Unpin,

§

impl<const KEY_LEN: usize, O, V> UnsafeUnpin for PATCH<KEY_LEN, O, V>

§

impl<const KEY_LEN: usize, O, V> UnwindSafe for PATCH<KEY_LEN, O, V>
where O: UnwindSafe, <O as KeySchema<KEY_LEN>>::Segmentation: UnwindSafe, V: UnwindSafe,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<I> Spread for I
where I: IntoIterator,

Source§

type Item = <I as IntoIterator>::Item

The type of each yielded value.
Source§

type Iter = I

The iterator type returned by spread.
Source§

fn spread(self) -> (<I as Spread>::Iter, TribleSet)

Decomposes the value into an iterator of items and extra facts to merge.
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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V