PMap

Struct PMap 

Source
pub struct PMap<K, V> { /* private fields */ }
Expand description

A persistent ordered map. Cloning is O(1) and shares everything.

Implementations§

Source§

impl<K: Ord + Clone, V: Clone> PMap<K, V>

Source

pub fn new() -> PMap<K, V>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn get(&self, key: &K) -> Option<&V>

Source

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

Source

pub fn same_root(&self, other: &PMap<K, V>) -> bool

Whether two maps are the same tree, not merely equal ones.

O(1), and the answer the incremental engine needs when deciding whether an event moved a map at all: structural equality would be O(n) per event, which is the cost the engine exists to avoid. A false here means “it may have changed”, never “it did”.

Source

pub fn insert(&self, key: K, value: V) -> PMap<K, V>

Insert, returning a new map. Shares every subtree the new key did not pass through.

Source

pub fn remove(&self, key: &K) -> PMap<K, V>

Remove, returning a new map.

Source

pub fn iter(&self) -> Iter<'_, K, V>

Entries in key order.

Source

pub fn keys(&self) -> impl Iterator<Item = &K>

Source

pub fn values(&self) -> impl Iterator<Item = &V>

Source§

impl<K: Ord + Clone, V: Clone + PartialEq> PMap<K, V>

Source

pub fn diff(&self, next: &PMap<K, V>) -> Vec<Change<K, V>>

The entries that differ between two versions, in key order.

§Why this is O(δ log n) rather than O(n)

This is the operation the whole incremental view engine rests on (docs/24-incremental-views-report.md): a fold produces a whole new accumulator per event, and a dataflow plan consumes deltas, so something has to turn one into the other. Comparing entry by entry would be O(n) per event, which is the recount §3.8 exists to abolish — the plan downstream would be incremental and the thing feeding it would not.

insert rebuilds only the path to the key and shares every subtree that path did not pass through, by Arc. So two versions of a map that differ by one insert share n - O(log n) nodes by pointer, and a diff that can recognise a shared subtree can skip all of its entries at once.

The traversal is an ordered merge of the two trees, with one extra rule: when the heads of the two remaining sequences are the same subtree by pointer, both are dropped. That is sound for a reason worth stating, because it is the correctness of the engine: pointer-identical subtrees hold identical entries, so the two remaining sorted sequences share that prefix exactly, and a merge over sorted sequences reports nothing for a shared prefix. It holds whatever rebalancing did to the position of that subtree in either tree.

Trait Implementations§

Source§

impl<K, V> Clone for PMap<K, V>

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<K: Debug, V: Debug> Debug for PMap<K, V>

Source§

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

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

impl<K, V> Default for PMap<K, V>

Source§

fn default() -> Self

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

impl<K: Ord + Clone, V: Clone> FromIterator<(K, V)> for PMap<K, V>

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<K: Ord + Clone, V: Clone + Ord> Ord for PMap<K, V>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<K: Ord + Clone + PartialEq, V: Clone + PartialEq> PartialEq for PMap<K, V>

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<K: Ord + Clone, V: Clone + Ord> PartialOrd for PMap<K, V>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<K: Ord + Clone, V: Clone + Eq> Eq for PMap<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for PMap<K, V>

§

impl<K, V> RefUnwindSafe for PMap<K, V>

§

impl<K, V> Send for PMap<K, V>
where K: Sync + Send, V: Sync + Send,

§

impl<K, V> Sync for PMap<K, V>
where K: Sync + Send, V: Sync + Send,

§

impl<K, V> Unpin for PMap<K, V>

§

impl<K, V> UnwindSafe for PMap<K, V>

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