Struct near_sdk::collections::LegacyTreeMap
source · pub struct LegacyTreeMap<K, V> { /* private fields */ }
Expand description
TreeMap based on AVL-tree
Runtime complexity (worst case):
get
/contains_key
: O(1) - UnorderedMap lookupinsert
/remove
: O(log(N))min
/max
: O(log(N))above
/below
: O(log(N))range
of K elements: O(Klog(N))
Implementations
sourceimpl<K, V> LegacyTreeMap<K, V>where
K: Ord + Clone + BorshSerialize + BorshDeserialize,
V: BorshSerialize + BorshDeserialize,
impl<K, V> LegacyTreeMap<K, V>where
K: Ord + Clone + BorshSerialize + BorshDeserialize,
V: BorshSerialize + BorshDeserialize,
pub fn new<S>(prefix: S) -> Selfwhere
S: IntoStorageKey,
pub fn len(&self) -> u64
pub fn clear(&mut self)
pub fn contains_key(&self, key: &K) -> bool
pub fn get(&self, key: &K) -> Option<V>
pub fn insert(&mut self, key: &K, val: &V) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
sourcepub fn higher(&self, key: &K) -> Option<K>
pub fn higher(&self, key: &K) -> Option<K>
Returns the smallest key that is strictly greater than key given as the parameter
sourcepub fn lower(&self, key: &K) -> Option<K>
pub fn lower(&self, key: &K) -> Option<K>
Returns the largest key that is strictly less than key given as the parameter
sourcepub fn ceil_key(&self, key: &K) -> Option<K>
pub fn ceil_key(&self, key: &K) -> Option<K>
Returns the smallest key that is greater or equal to key given as the parameter
sourcepub fn floor_key(&self, key: &K) -> Option<K>
pub fn floor_key(&self, key: &K) -> Option<K>
Returns the largest key that is less or equal to key given as the parameter
sourcepub fn iter(&self) -> impl Iterator<Item = (K, V)> + '_
pub fn iter(&self) -> impl Iterator<Item = (K, V)> + '_
Iterate all entries in ascending order: min to max, both inclusive
sourcepub fn iter_from(&self, key: K) -> impl Iterator<Item = (K, V)> + '_
pub fn iter_from(&self, key: K) -> impl Iterator<Item = (K, V)> + '_
Iterate entries in ascending order: given key (exclusive) to max (inclusive)
sourcepub fn iter_rev(&self) -> impl Iterator<Item = (K, V)> + '_
pub fn iter_rev(&self) -> impl Iterator<Item = (K, V)> + '_
Iterate all entries in descending order: max to min, both inclusive
sourcepub fn iter_rev_from(&self, key: K) -> impl Iterator<Item = (K, V)> + '_
pub fn iter_rev_from(&self, key: K) -> impl Iterator<Item = (K, V)> + '_
Iterate entries in descending order: given key (exclusive) to min (inclusive)
sourcepub fn range(&self, r: (Bound<K>, Bound<K>)) -> impl Iterator<Item = (K, V)> + '_
pub fn range(&self, r: (Bound<K>, Bound<K>)) -> impl Iterator<Item = (K, V)> + '_
Iterate entries in ascending order according to specified bounds.
Panics
Panics if range start > end. Panics if range start == end and both bounds are Excluded.
sourcepub fn to_vec(&self) -> Vec<(K, V)>
pub fn to_vec(&self) -> Vec<(K, V)>
Helper function which creates a [Vec<(K, V)>
] of all items in the LegacyTreeMap
.
This function collects elements from LegacyTreeMap::iter
.