pub struct RawDict<C: CellFamily, const N: u16>(_);
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<C: CellFamily, const N: u16> RawDict<C, N>

source

pub const fn new() -> Self

Creates an empty dictionary.

source

pub const fn is_empty(&self) -> bool

Returns true if the dictionary contains no elements.

source

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

Returns the underlying root cell of the dictionary.

source§

impl<C, const N: u16> RawDict<C, N>where for<'c> C: CellFamily + 'c,

source

pub fn load_from_root_ext( slice: &mut CellSlice<'_, C>, finalizer: &mut dyn Finalizer<C> ) -> Option<Self>

Loads a non-empty dictionary from a root cell.

source§

impl<C, const N: u16> RawDict<C, N>where for<'c> C: CellFamily + 'c,

source

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

Returns a CellSlice of the value corresponding to the key.

source

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

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

source

pub fn set_ext( &mut self, key: CellSlice<'_, C>, value: CellSlice<'_, C>, finalizer: &mut dyn Finalizer<C> ) -> Result<(), Error>

Sets the value associated with the key in the dictionary.

source

pub fn replace_ext( &mut self, key: CellSlice<'_, C>, value: CellSlice<'_, C>, finalizer: &mut dyn Finalizer<C> ) -> Result<(), 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<'_, C>, value: CellSlice<'_, C>, finalizer: &mut dyn Finalizer<C> ) -> Result<(), Error>

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

source

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

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

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 keys(&self) -> RawKeys<'_, C>

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

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<'_, C>

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

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

source§

impl<C, const N: u16> RawDict<C, N>where for<'c> C: DefaultFinalizer + 'c,

source

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

Sets the value associated with the key in the dictionary.

Use set_ext if you need to use a custom finalizer.

source

pub fn replace( &mut self, key: CellSlice<'_, C>, value: CellSlice<'_, C> ) -> Result<(), 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 finalizer.

source

pub fn add( &mut self, key: CellSlice<'_, C>, value: CellSlice<'_, C> ) -> Result<(), 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 finalizer.

Trait Implementations§

source§

impl<C: CellFamily, const N: u16> Clone for RawDict<C, N>

source§

fn clone(&self) -> Self

Returns a copy 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<C: CellFamily, const N: u16> Debug for RawDict<C, N>

source§

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

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

impl<C: CellFamily, const N: u16> Default for RawDict<C, N>

source§

fn default() -> Self

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

impl<C: CellFamily, const N: u16> From<Option<<C as CellFamily>::Container>> for RawDict<C, N>

source§

fn from(value: Option<CellContainer<C>>) -> Self

Converts to this type from the input type.
source§

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

source§

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

Tries to load itself from a cell slice.
source§

impl<C: CellFamily, const N: u16> PartialEq<RawDict<C, N>> for RawDict<C, N>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<C: CellFamily, const N: u16> Store<C> for RawDict<C, N>

source§

fn store_into( &self, builder: &mut CellBuilder<C>, finalizer: &mut dyn Finalizer<C> ) -> bool

Tries to store itself into the cell builder.
source§

impl<C: CellFamily, const N: u16> Eq for RawDict<C, N>

Auto Trait Implementations§

§

impl<C, const N: u16> RefUnwindSafe for RawDict<C, N>where <C as CellFamily>::Container: RefUnwindSafe,

§

impl<C, const N: u16> Send for RawDict<C, N>where <C as CellFamily>::Container: Send,

§

impl<C, const N: u16> Sync for RawDict<C, N>where <C as CellFamily>::Container: Sync,

§

impl<C, const N: u16> Unpin for RawDict<C, N>where <C as CellFamily>::Container: Unpin,

§

impl<C, const N: u16> UnwindSafe for RawDict<C, N>where <C as CellFamily>::Container: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.