From b661c9d19e4073a26393641fc73b1bfc7c7d18c1 Mon Sep 17 00:00:00 2001 From: Ivan Kalinin Date: Wed, 6 Nov 2024 14:26:11 +0100 Subject: [PATCH] feat(dict): add `Dict::get_raw_owned` --- src/dict/typed.rs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/dict/typed.rs b/src/dict/typed.rs index 50533a9..45c91e7 100644 --- a/src/dict/typed.rs +++ b/src/dict/typed.rs @@ -8,8 +8,8 @@ use crate::error::Error; use crate::util::*; use super::{ - build_dict_from_sorted_iter, dict_find_bound, dict_find_owned, dict_get, dict_insert, - dict_load_from_root, dict_split_by_prefix, DictBound, DictKey, SetMode, + build_dict_from_sorted_iter, dict_find_bound, dict_find_owned, dict_get, dict_get_owned, + dict_insert, dict_load_from_root, dict_split_by_prefix, DictBound, DictKey, SetMode, }; use super::{dict_remove_bound_owned, raw::*}; @@ -158,6 +158,7 @@ impl Dict { impl Dict { /// Loads a non-empty dictionary from a root cell. + #[inline] pub fn load_from_root_ext( slice: &mut CellSlice<'_>, context: &mut dyn CellContext, @@ -178,6 +179,7 @@ where K: Store + DictKey, { /// Returns `true` if the dictionary contains a value for the specified key. + #[inline] pub fn contains_key(&self, key: Q) -> Result where Q: Borrow, @@ -205,6 +207,7 @@ where K: Store + DictKey, { /// Returns the value corresponding to the key. + #[inline] pub fn get<'a: 'b, 'b, Q>(&'a self, key: Q) -> Result, Error> where Q: Borrow + 'b, @@ -241,6 +244,7 @@ where } /// Returns the raw value corresponding to the key. + #[inline] pub fn get_raw<'a: 'b, 'b, Q>(&'a self, key: Q) -> Result>, Error> where Q: Borrow + 'b, @@ -265,6 +269,34 @@ where get_raw_impl(&self.root, key.borrow()) } + /// Returns cell slice parts of the value corresponding to the key. + /// + /// NOTE: Uses the default cell context. + #[inline] + pub fn get_raw_owned(&self, key: Q) -> Result, Error> + where + Q: Borrow, + { + pub fn get_raw_impl( + root: &Option, + key: &K, + ) -> Result, Error> + where + K: Store + DictKey, + { + let mut builder = CellBuilder::new(); + ok!(key.store_into(&mut builder, &mut Cell::empty_context())); + dict_get_owned( + root.as_ref(), + K::BITS, + builder.as_data_slice(), + &mut Cell::empty_context(), + ) + } + + get_raw_impl(&self.root, key.borrow()) + } + /// Removes the value associated with key in dictionary. /// Returns an optional removed value. /// @@ -691,6 +723,7 @@ where /// Returns an optional removed value as cell slice parts. /// /// Dict is rebuild using the provided cell context. + #[inline] pub fn remove_raw_ext( &mut self, key: Q,