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>
impl<const N: u16> RawDict<N>
Sourcepub fn try_from_btree<K, V>(sorted: &BTreeMap<K, V>) -> Result<Self, Error>
pub fn try_from_btree<K, V>(sorted: &BTreeMap<K, V>) -> Result<Self, Error>
Builds a dictionary from a sorted collection.
Sourcepub fn try_from_sorted_slice<K, V>(sorted: &[(K, V)]) -> Result<Self, Error>
pub fn try_from_sorted_slice<K, V>(sorted: &[(K, V)]) -> Result<Self, Error>
Builds a dictionary from a sorted slice.
Sourcepub fn load_from_root_ext(
slice: &mut CellSlice<'_>,
context: &mut dyn CellContext,
) -> Result<Self, Error>
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.
Sourcepub fn get<'a>(
&'a self,
key: CellSlice<'_>,
) -> Result<Option<CellSlice<'a>>, Error>
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.
Sourcepub fn get_ext<'a>(
&'a self,
key: CellSlice<'_>,
context: &mut dyn CellContext,
) -> Result<Option<CellSlice<'a>>, Error>
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.
Sourcepub fn get_next_owned(
&self,
key: CellSlice<'_>,
signed: bool,
) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>
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.
Sourcepub fn get_subdict<'a>(
&'a self,
prefix: CellSlice<'a>,
context: &mut dyn CellContext,
) -> Result<Option<Cell>, Error>
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
Sourcepub fn get_prev_owned(
&self,
key: CellSlice<'_>,
signed: bool,
) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>
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.
Sourcepub fn get_or_next_owned(
&self,
key: CellSlice<'_>,
signed: bool,
) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>
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.
Sourcepub fn get_or_prev_owned(
&self,
key: CellSlice<'_>,
signed: bool,
) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>
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.
Sourcepub fn get_owned(
&self,
key: CellSlice<'_>,
) -> Result<Option<CellSliceParts>, Error>
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.
Sourcepub fn get_owned_ext(
&self,
key: CellSlice<'_>,
context: &mut dyn CellContext,
) -> Result<Option<CellSliceParts>, Error>
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.
Sourcepub fn get_min(
&self,
signed: bool,
) -> Result<Option<(CellBuilder, CellSlice<'_>)>, Error>
pub fn get_min( &self, signed: bool, ) -> Result<Option<(CellBuilder, CellSlice<'_>)>, Error>
Returns the lowest key and a value corresponding to the key.
Sourcepub fn get_max(
&self,
signed: bool,
) -> Result<Option<(CellBuilder, CellSlice<'_>)>, Error>
pub fn get_max( &self, signed: bool, ) -> Result<Option<(CellBuilder, CellSlice<'_>)>, Error>
Returns the largest key and a value corresponding to the key.
Sourcepub fn get_bound(
&self,
bound: DictBound,
signed: bool,
) -> Result<Option<(CellBuilder, CellSlice<'_>)>, Error>
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.
Sourcepub fn get_bound_ext(
&self,
bound: DictBound,
signed: bool,
context: &mut dyn CellContext,
) -> Result<Option<(CellBuilder, CellSlice<'_>)>, Error>
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.
Sourcepub fn get_min_owned(
&self,
signed: bool,
) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>
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.
Sourcepub fn get_max_owned(
&self,
signed: bool,
) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>
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.
Sourcepub fn get_bound_owned(
&self,
bound: DictBound,
signed: bool,
) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>
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.
Sourcepub fn get_bound_owned_ext(
&self,
bound: DictBound,
signed: bool,
context: &mut dyn CellContext,
) -> Result<Option<(CellBuilder, CellSliceParts)>, Error>
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.
Sourcepub fn contains_key(&self, key: CellSlice<'_>) -> Result<bool, Error>
pub fn contains_key(&self, key: CellSlice<'_>) -> Result<bool, Error>
Returns true if the dictionary contains a value for the specified key.
Sourcepub fn set_ext(
&mut self,
key: CellSlice<'_>,
value: &dyn Store,
context: &mut dyn CellContext,
) -> Result<bool, Error>
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.
Sourcepub fn replace_ext(
&mut self,
key: CellSlice<'_>,
value: &dyn Store,
context: &mut dyn CellContext,
) -> Result<bool, Error>
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.
Sourcepub fn add_ext(
&mut self,
key: CellSlice<'_>,
value: &dyn Store,
context: &mut dyn CellContext,
) -> Result<bool, Error>
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.
Sourcepub fn remove_ext(
&mut self,
key: CellSlice<'_>,
context: &mut dyn CellContext,
) -> Result<Option<CellSliceParts>, Error>
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.
Sourcepub fn remove_bound_ext(
&mut self,
bound: DictBound,
signed: bool,
context: &mut dyn CellContext,
) -> Result<Option<DictOwnedEntry>, Error>
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.
Sourcepub fn split(&self) -> Result<(Self, Self), Error>
pub fn split(&self) -> Result<(Self, Self), Error>
Split dictionary into 2 dictionaries by the first key bit.
Sourcepub fn split_ext(
&self,
context: &mut dyn CellContext,
) -> Result<(Self, Self), Error>
pub fn split_ext( &self, context: &mut dyn CellContext, ) -> Result<(Self, Self), Error>
Split dictionary into 2 dictionaries by the first key bit.
Sourcepub fn split_by_prefix(
&self,
key_prefix: &CellSlice<'_>,
) -> Result<(Self, Self), Error>
pub fn split_by_prefix( &self, key_prefix: &CellSlice<'_>, ) -> Result<(Self, Self), Error>
Split dictionary into 2 dictionaries at the prefix.
Sourcepub fn split_by_prefix_ext(
&self,
key_prefix: &CellSlice<'_>,
context: &mut dyn CellContext,
) -> Result<(Self, Self), Error>
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.
Sourcepub fn iter(&self) -> RawIter<'_> ⓘ
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.
Sourcepub fn iter_union<'a>(&'a self, other: &'a RawDict<N>) -> UnionRawIter<'a> ⓘ
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.
Sourcepub fn iter_owned(&self) -> RawOwnedIter<'_> ⓘ
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.
Sourcepub fn keys(&self) -> RawKeys<'_> ⓘ
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.
Sourcepub fn values(&self) -> RawValues<'_> ⓘ
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.
Sourcepub fn values_owned(&self) -> RawOwnedValues<'_> ⓘ
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.
Sourcepub fn set<T: Store>(
&mut self,
key: CellSlice<'_>,
value: T,
) -> Result<bool, Error>
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.
Sourcepub fn replace<T: Store>(
&mut self,
key: CellSlice<'_>,
value: T,
) -> Result<bool, Error>
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.
Sourcepub fn add<T: Store>(
&mut self,
key: CellSlice<'_>,
value: T,
) -> Result<bool, Error>
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.
Sourcepub fn remove(
&mut self,
key: CellSlice<'_>,
) -> Result<Option<CellSliceParts>, Error>
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.
Sourcepub fn remove_min(
&mut self,
signed: bool,
) -> Result<Option<DictOwnedEntry>, Error>
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.
Sourcepub fn remove_max(
&mut self,
signed: bool,
) -> Result<Option<DictOwnedEntry>, Error>
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.
Sourcepub fn remove_bound(
&mut self,
bound: DictBound,
signed: bool,
) -> Result<Option<DictOwnedEntry>, Error>
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> ExactSize for RawDict<N>
impl<const N: u16> ExactSize for RawDict<N>
Source§fn exact_size(&self) -> Size
fn exact_size(&self) -> Size
Source§impl<const N: u16> Store for RawDict<N>
impl<const N: u16> Store for RawDict<N>
Source§fn store_into(
&self,
builder: &mut CellBuilder,
context: &mut dyn CellContext,
) -> Result<(), Error>
fn store_into( &self, builder: &mut CellBuilder, context: &mut dyn CellContext, ) -> Result<(), Error>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
self to key and returns true if they are equal.