AugDict

Struct AugDict 

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

Typed augmented dictionary with fixed length keys.

§TLB scheme

ahm_edge#_ {n:#} {V:Type} {A:Type} {l:#} {m:#}
  label:(HmLabel ~l n) {n = (~m) + l}
  node:(HashmapAugNode m V A) = HashmapAug n V A;

ahmn_leaf#_ {V:Type} {A:Type} extra:A value:V = HashmapAugNode 0 V A;
ahmn_fork#_ {n:#} {V:Type} {A:Type} left:^(HashmapAug n V A)
  right:^(HashmapAug n V A) extra:A = HashmapAugNode (n + 1) V A;

ahme_empty$0 {n:#} {V:Type} {A:Type} extra:A = HashmapAugE n V A;
ahme_root$1 {n:#} {V:Type} {A:Type} root:^(HashmapAug n V A) extra:A = HashmapAugE n V A;

Implementations§

Source§

impl<K, A: Default, V> AugDict<K, A, V>

Source

pub fn new() -> Self

Creates an empty dictionary

Source

pub const fn from_parts(dict: Dict<K, (A, V)>, extra: A) -> Self

Manually constructs the dictionaty from parts.

Source

pub fn into_parts(self) -> (Dict<K, (A, V)>, A)

Returns an underlying dictionary and the extra value.

Source

pub fn cast_into<Q, T>(self) -> AugDict<Q, A, T>

Converts into a dictionary with an equivalent value type.

Source§

impl<K, A, V> AugDict<K, A, V>
where K: DictKey, for<'a> A: Default + Load<'a>,

Source

pub fn update_root_extra(&mut self) -> Result<(), Error>

Recomputes the root extra value.

Source§

impl<K, A, V> AugDict<K, A, V>

Source

pub const fn is_empty(&self) -> bool

Returns true if the dictionary contains no elements.

Source

pub const fn dict(&self) -> &Dict<K, (A, V)>

Returns the underlying dictionary.

Source

pub const fn root_extra(&self) -> &A

Returns the root augmented value.

Source§

impl<K, A, V> AugDict<K, A, V>
where K: Store + DictKey,

Source

pub fn contains_key<Q>(&self, key: Q) -> Result<bool, Error>
where Q: Borrow<K>,

Returns true if the dictionary contains a value for the specified key.

Source§

impl<K, A, V> AugDict<K, A, V>
where K: Store + DictKey,

Source

pub fn get<'a: 'b, 'b, Q>(&'a self, key: Q) -> Result<Option<(A, V)>, Error>
where Q: Borrow<K> + 'b, (A, V): Load<'a>,

Returns the value corresponding to the key.

Source§

impl<K, A, V> AugDict<K, A, V>
where K: DictKey,

Source

pub fn find_by_extra<'a, S>( &'a self, flow: S, ) -> Result<Option<(K, A, V)>, Error>
where S: SearchByExtra<A>, A: Load<'a>, V: Load<'a>,

Searches for an item using a predicate on extra values.

Used as a secondary index.

Source§

impl<K, A, V> AugDict<K, A, V>
where K: Store + DictKey, for<'a> A: AugDictExtra + Store + Load<'a>, V: Store,

Source

pub fn try_from_btree<Q, E, T>( sorted: &BTreeMap<Q, (E, T)>, ) -> Result<Self, Error>
where Q: Borrow<K>, E: Borrow<A>, T: Borrow<V>, K: Ord,

Builds a dictionary from a sorted collection.

Source

pub fn try_from_sorted_slice<Q, E, T>( sorted: &[(Q, E, T)], ) -> Result<Self, Error>
where Q: Borrow<K>, E: Borrow<A>, T: Borrow<V>, K: Ord,

Builds a dictionary from a sorted slice.

Source

pub fn set<Q, E, T>(&mut self, key: Q, aug: E, value: T) -> Result<bool, Error>
where Q: Borrow<K>, E: Borrow<A>, T: Borrow<V>,

Sets the augmented value associated with the key in the aug dictionary.

Use set_ext if you need to use a custom cell context.

Source

pub fn set_ext<Q, E, T>( &mut self, key: Q, aug: E, value: T, context: &mut dyn CellContext, ) -> Result<bool, Error>
where Q: Borrow<K>, E: Borrow<A>, T: Borrow<V>,

Sets the value associated with the key in the dictionary.

Source

pub fn replace<Q, E, T>( &mut self, key: Q, aug: E, value: T, ) -> Result<bool, Error>
where Q: Borrow<K>, E: Borrow<A>, T: Borrow<V>,

Sets the augmented value associated with the key in the aug dictionary only if the key was already present in it.

Use replace_ext if you need to use a custom cell context.

Source

pub fn replace_ext<Q, E, T>( &mut self, key: Q, aug: E, value: T, context: &mut dyn CellContext, ) -> Result<bool, Error>
where Q: Borrow<K>, E: Borrow<A>, T: Borrow<V>,

Sets the value associated with the key in the dictionary only if the key was already present in it.

Source

pub fn add<Q, E, T>(&mut self, key: Q, aug: E, value: T) -> Result<bool, Error>
where Q: Borrow<K>, E: Borrow<A>, T: Borrow<V>,

Sets the value associated with key in aug dictionary, but only if it is not already present.

Use add_ext if you need to use a custom cell context.

Source

pub fn add_ext<Q, E, T>( &mut self, key: Q, aug: E, value: T, context: &mut dyn CellContext, ) -> Result<bool, Error>
where Q: Borrow<K>, E: Borrow<A>, T: Borrow<V>,

Sets the value associated with key in dictionary, but only if it is not already present.

Source

pub fn remove<Q>(&mut self, key: Q) -> Result<Option<(A, V)>, Error>
where Q: Borrow<K>, for<'a> A: Load<'a> + 'static, for<'a> V: Load<'a> + 'static,

Removes the value associated with key in aug dictionary. Returns an optional removed value as cell slice parts.

Source

pub fn remove_raw_ext<Q>( &mut self, key: Q, context: &mut dyn CellContext, ) -> Result<Option<CellSliceParts>, Error>
where Q: Borrow<K>,

Removes the value associated with key in dictionary. Returns an optional removed value as cell slice parts.

Source

pub fn split(&self) -> Result<(Self, Self), Error>

Split dictionary into 2 dictionaries by the first key bit.

Source

pub fn split_ext( &self, context: &mut dyn CellContext, ) -> Result<(Self, Self), Error>

Split dictionary into 2 dictionaries by the first key bit.

Source

pub fn split_by_prefix( &self, key_prefix: &CellSlice<'_>, ) -> Result<(Self, Self), Error>

Split dictionary into 2 dictionaries at the prefix.

Source

pub fn split_by_prefix_ext( &self, key_prefix: &CellSlice<'_>, context: &mut dyn CellContext, ) -> Result<(Self, Self), Error>

Split dictionary into 2 dictionaries at the prefix.

Source§

impl<K, A, V> AugDict<K, A, V>
where K: DictKey,

Source

pub fn iter<'a>(&'a self) -> AugIter<'a, K, A, V>
where V: Load<'a>,

Gets an iterator over the entries of the dictionary, sorted by key. The iterator element type is Result<(K, A, V)>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

§Performance

In the current implementation, iterating over dictionary builds a key for each element. Use values or raw_values if you don’t need keys from an iterator.

Source

pub fn keys(&self) -> Keys<'_, K>

Gets an iterator over the keys of the dictionary, in sorted order. The iterator element type is Result<K>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

§Performance

In the current implementation, iterating over dictionary builds a key for each element. Use values if you don’t need keys from an iterator.

Source§

impl<K, A, V> AugDict<K, A, V>
where K: DictKey,

Source

pub fn values<'a>(&'a self) -> Values<'a, (A, V)>
where V: Load<'a>,

Gets an iterator over the augmented values of the dictionary, in order by key. The iterator element type is Result<V>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

Source§

impl<K, A, V> AugDict<K, A, V>
where K: Store + DictKey,

Source

pub fn raw_iter(&self) -> RawIter<'_>

Gets an iterator over the raw entries of the dictionary, sorted by key. The iterator element type is Result<(CellBuilder, CellSlice)>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

§Performance

In the current implementation, iterating over dictionary builds a key for each element. Use values or raw_values if you don’t need keys from an iterator.

Source

pub fn raw_keys(&self) -> RawKeys<'_>

Gets an iterator over the raw keys of the dictionary, in sorted order. The iterator element type is Result<CellBuilder>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

§Performance

In the current implementation, iterating over dictionary builds a key for each element. Use values or raw_values if you don’t need keys from an iterator.

Source§

impl<K, A, V> AugDict<K, A, V>
where K: DictKey,

Source

pub fn raw_values(&self) -> RawValues<'_>

Gets an iterator over the raw values of the dictionary, in order by key. The iterator element type is Result<CellSlice>.

If the dictionary is invalid, finishes after the first invalid element, returning an error.

Trait Implementations§

Source§

impl<K, A: Clone, V> Clone for AugDict<K, A, 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, A: Debug, V> Debug for AugDict<K, A, V>

Source§

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

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

impl<K, A: Default, V> Default for AugDict<K, A, V>

Source§

fn default() -> Self

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

impl<K, A: ExactSize, V> ExactSize for AugDict<K, A, V>

Source§

fn exact_size(&self) -> Size

Exact size of the value when it is stored in a slice.
Source§

impl<'a, K, A: Load<'a>, V> Load<'a> for AugDict<K, A, V>

Source§

fn load_from(slice: &mut CellSlice<'a>) -> Result<Self, Error>

Tries to load itself from a cell slice.
Source§

impl<K, A: PartialEq, V> PartialEq for AugDict<K, A, 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, A, V> Serialize for AugDict<K, A, V>
where K: Serialize + Store + DictKey, for<'a> A: Serialize + Store + Load<'a>, for<'a> V: Serialize + Load<'a>,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<K, A: Store, V> Store for AugDict<K, A, V>

Source§

fn store_into( &self, builder: &mut CellBuilder, context: &mut dyn CellContext, ) -> Result<(), Error>

Tries to store itself into the cell builder.
Source§

impl<K, A: Eq, V> Eq for AugDict<K, A, V>

Auto Trait Implementations§

§

impl<K, A, V> Freeze for AugDict<K, A, V>
where A: Freeze,

§

impl<K, A, V> !RefUnwindSafe for AugDict<K, A, V>

§

impl<K, A, V> Send for AugDict<K, A, V>
where A: Send, K: Send, V: Send,

§

impl<K, A, V> Sync for AugDict<K, A, V>
where A: Sync, K: Sync, V: Sync,

§

impl<K, A, V> Unpin for AugDict<K, A, V>
where A: Unpin, K: Unpin, V: Unpin,

§

impl<K, A, V> !UnwindSafe for AugDict<K, A, 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Compares self to key and returns 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> Same for T

Source§

type Output = T

Should always be Self
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

Source§

impl<T> EquivalentRepr<T> for T