RawDict

Struct RawDict 

Source
pub struct RawDict<const N: u16>(/* private fields */);
Expand description

Dictionary with fixed length keys (where N is a number of bits in each key).

§TLB scheme

// ordinary Hashmap / HashmapE, with fixed length keys

hm_edge#_ {n:#} {X:Type} {l:#} {m:#} label:(HmLabel ~l n)
          {n = (~m) + l} node:(HashmapNode m X) = Hashmap n X;

hmn_leaf#_ {X:Type} value:X = HashmapNode 0 X;
hmn_fork#_ {n:#} {X:Type} left:^(Hashmap n X)
           right:^(Hashmap n X) = HashmapNode (n + 1) X;

hml_short$0 {m:#} {n:#} len:(Unary ~n) {n <= m} s:(n * Bit) = HmLabel ~n m;
hml_long$10 {m:#} n:(#<= m) s:(n * Bit) = HmLabel ~n m;
hml_same$11 {m:#} v:Bit n:(#<= m) = HmLabel ~n m;

hme_empty$0 {n:#} {X:Type} = HashmapE n X;
hme_root$1 {n:#} {X:Type} root:^(Hashmap n X) = HashmapE n X;

unary_zero$0 = Unary ~0;
unary_succ$1 {n:#} x:(Unary ~n) = Unary ~(n + 1);

bit$_ (## 1) = Bit;

Implementations§

Source§

impl<const N: u16> RawDict<N>

Source

pub const fn new() -> Self

Creates an empty dictionary.

Source

pub fn try_from_btree<K, V>(sorted: &BTreeMap<K, V>) -> Result<Self, Error>
where K: Store + Ord, V: Store,

Builds a dictionary from a sorted collection.

Source

pub fn try_from_sorted_slice<K, V>(sorted: &[(K, V)]) -> Result<Self, Error>
where K: Store + Ord, V: Store,

Builds a dictionary from a sorted slice.

Source

pub const fn is_empty(&self) -> bool

Returns true if the dictionary contains no elements.

Source

pub const fn root(&self) -> &Option<Cell>

Returns the underlying root cell of the dictionary.

Source

pub fn into_root(self) -> Option<Cell>

Returns the underlying root cell of the dictionary.

Source

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

Loads a non-empty dictionary from a root cell.

Source

pub fn get<'a>( &'a self, key: CellSlice<'_>, ) -> Result<Option<CellSlice<'a>>, Error>

Returns a CellSlice of the value corresponding to the key.

NOTE: Uses the default cell context.

Source

pub fn get_ext<'a>( &'a self, key: CellSlice<'_>, context: &mut dyn CellContext, ) -> Result<Option<CellSlice<'a>>, Error>

Returns a CellSlice of the value corresponding to the key.

Source

pub fn get_next_owned( &self, key: CellSlice<'_>, signed: bool, ) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>

Computes the minimal key in dictionary that is lexicographically greater than key, and returns it along with associated value as cell slice parts.

Source

pub fn get_subdict<'a>( &'a self, prefix: CellSlice<'a>, context: &mut dyn CellContext, ) -> Result<Option<Cell>, Error>

Get subdict of dictionary by specified key prefix

Source

pub fn get_prev_owned( &self, key: CellSlice<'_>, signed: bool, ) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>

Computes the maximal key in dictionary that is lexicographically smaller than key, and returns it along with associated value as cell slice parts.

Source

pub fn get_or_next_owned( &self, key: CellSlice<'_>, signed: bool, ) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>

Computes the minimal key in dictionary that is lexicographically greater than key, and returns it along with associated value as cell slice parts.

Source

pub fn get_or_prev_owned( &self, key: CellSlice<'_>, signed: bool, ) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>

Computes the maximal key in dictionary that is lexicographically smaller than key, and returns it along with associated value as cell slice parts.

Source

pub fn get_owned( &self, key: CellSlice<'_>, ) -> Result<Option<CellSliceParts>, Error>

Returns cell slice parts of the value corresponding to the key.

NOTE: Uses the default cell context.

Source

pub fn get_owned_ext( &self, key: CellSlice<'_>, context: &mut dyn CellContext, ) -> Result<Option<CellSliceParts>, Error>

Returns cell slice parts of the value corresponding to the key.

Source

pub fn get_min( &self, signed: bool, ) -> Result<Option<(CellBuilder, CellSlice<'_>)>, Error>

Returns the lowest key and a value corresponding to the key.

Source

pub fn get_max( &self, signed: bool, ) -> Result<Option<(CellBuilder, CellSlice<'_>)>, Error>

Returns the largest key and a value corresponding to the key.

Source

pub fn get_bound( &self, bound: DictBound, signed: bool, ) -> Result<Option<(CellBuilder, CellSlice<'_>)>, Error>

Finds the specified dict bound and returns a key and a value corresponding to the key.

Source

pub fn get_bound_ext( &self, bound: DictBound, signed: bool, context: &mut dyn CellContext, ) -> Result<Option<(CellBuilder, CellSlice<'_>)>, Error>

Finds the specified dict bound and returns a key and a value corresponding to the key.

Source

pub fn get_min_owned( &self, signed: bool, ) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>

Returns the lowest key and cell slice parts corresponding to the key.

Source

pub fn get_max_owned( &self, signed: bool, ) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>

Returns the largest key and cell slice parts corresponding to the key.

Source

pub fn get_bound_owned( &self, bound: DictBound, signed: bool, ) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>

Finds the specified dict bound and returns a key and cell slice parts corresponding to the key.

Source

pub fn get_bound_owned_ext( &self, bound: DictBound, signed: bool, context: &mut dyn CellContext, ) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>

Finds the specified dict bound and returns a key and cell slice parts corresponding to the key.

Source

pub fn contains_key(&self, key: CellSlice<'_>) -> Result<bool, Error>

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

Source

pub fn set_ext( &mut self, key: CellSlice<'_>, value: &dyn Store, context: &mut dyn CellContext, ) -> Result<bool, Error>

Sets the value associated with the key in the dictionary.

Source

pub fn replace_ext( &mut self, key: CellSlice<'_>, value: &dyn Store, context: &mut dyn CellContext, ) -> Result<bool, Error>

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

Source

pub fn add_ext( &mut self, key: CellSlice<'_>, value: &dyn Store, context: &mut dyn CellContext, ) -> Result<bool, Error>

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

Source

pub fn remove_ext( &mut self, key: CellSlice<'_>, context: &mut dyn CellContext, ) -> Result<Option<CellSliceParts>, Error>

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

Source

pub fn remove_bound_ext( &mut self, bound: DictBound, signed: bool, context: &mut dyn CellContext, ) -> Result<Option<DictOwnedEntry>, Error>

Removes the specified dict bound. Returns an optional removed key and 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

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

Gets an iterator over the 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 if you don’t need keys from an iterator.

Source

pub fn iter_union<'a>(&'a self, other: &'a RawDict<N>) -> UnionRawIter<'a>

Gets an iterator over the entries of two dictionaries, sorted by key. The iterator element type is Result<(CellBuilder, Option<CellSlice>, Option<CellSlice>)>. Where the first element is the key, the second is the value from the first dictionary, and the third is the value from the second dictionary.

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.

Source

pub fn iter_owned(&self) -> RawOwnedIter<'_>

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

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_owned if you don’t need keys from an iterator.

Source

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

Gets an iterator over the 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 if you don’t need keys from an iterator.

Source

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

Gets an iterator over the 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.

Source

pub fn values_owned(&self) -> RawOwnedValues<'_>

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

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

Source

pub fn set<T: Store>( &mut self, key: CellSlice<'_>, value: T, ) -> Result<bool, Error>

Sets the value associated with the key in the dictionary.

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

Source

pub fn replace<T: Store>( &mut self, key: CellSlice<'_>, value: T, ) -> Result<bool, Error>

Sets the value associated with the key in the 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 add<T: Store>( &mut self, key: CellSlice<'_>, value: T, ) -> Result<bool, Error>

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

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

Source

pub fn remove( &mut self, key: CellSlice<'_>, ) -> Result<Option<CellSliceParts>, Error>

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

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

Source

pub fn remove_min( &mut self, signed: bool, ) -> Result<Option<DictOwnedEntry>, Error>

Removes the lowest key from the dict. Returns an optional removed key and value as cell slice parts.

Use remove_bound_ext if you need to use a custom context.

Source

pub fn remove_max( &mut self, signed: bool, ) -> Result<Option<DictOwnedEntry>, Error>

Removes the largest key from the dict. Returns an optional removed key and value as cell slice parts.

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

Source

pub fn remove_bound( &mut self, bound: DictBound, signed: bool, ) -> Result<Option<DictOwnedEntry>, Error>

Removes the specified dict bound. Returns an optional removed key and value as cell slice parts.

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

Trait Implementations§

Source§

impl<const N: u16> Clone for RawDict<N>

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<const N: u16> Debug for RawDict<N>

Source§

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

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

impl<const N: u16> Default for RawDict<N>

Source§

fn default() -> Self

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

impl<const N: u16> ExactSize for RawDict<N>

Source§

fn exact_size(&self) -> Size

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

impl<const N: u16> From<Option<Cell>> for RawDict<N>

Source§

fn from(value: Option<Cell>) -> Self

Converts to this type from the input type.
Source§

impl<'a, const N: u16> Load<'a> for RawDict<N>

Source§

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

Tries to load itself from a cell slice.
Source§

impl<const N: u16> PartialEq for RawDict<N>

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 N: u16> Store for RawDict<N>

Source§

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

Tries to store itself into the cell builder.
Source§

impl<const N: u16> Eq for RawDict<N>

Auto Trait Implementations§

§

impl<const N: u16> Freeze for RawDict<N>

§

impl<const N: u16> !RefUnwindSafe for RawDict<N>

§

impl<const N: u16> Send for RawDict<N>

§

impl<const N: u16> Sync for RawDict<N>

§

impl<const N: u16> Unpin for RawDict<N>

§

impl<const N: u16> !UnwindSafe for RawDict<N>

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