pub struct NeoMap<K, V> { /* private fields */ }Expand description
Neo N3 Map type
Implementations§
Source§impl<K, V> NeoMap<K, V>
impl<K, V> NeoMap<K, V>
pub fn new() -> NeoMap<K, V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>where
K: PartialEq,
Sourcepub fn get(&self, key: &K) -> Option<&V>where
K: PartialEq,
pub fn get(&self, key: &K) -> Option<&V>where
K: PartialEq,
Gets a reference to the value associated with the given key.
§Performance
This operation is O(n) as it performs a linear search. Consider using a HashMap for O(1) lookups if performance is critical.
Sourcepub fn get_mut(&mut self, key: &K) -> Option<&mut V>where
K: PartialEq,
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>where
K: PartialEq,
Gets a mutable reference to the value associated with the given key.
§Performance
This operation is O(n) as it performs a linear search.
Sourcepub fn remove(&mut self, key: &K) -> Option<V>where
K: PartialEq,
pub fn remove(&mut self, key: &K) -> Option<V>where
K: PartialEq,
Removes the key-value pair associated with the given key.
§Performance
This operation is O(n) due to the element removal.
§Order stability
Uses Vec::remove (shift) so iteration order of remaining entries is
preserved (D7: swap_remove reordered entries, diverging from on-chain
NeoVM Map semantics and breaking deterministic serialization). Note that
on-chain NeoVM Map is sorted by key; this NeoMap is a linear map
(insertion-stable), not the on-chain sorted map.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
Sourcepub fn contains_key(&self, key: &K) -> boolwhere
K: PartialEq,
pub fn contains_key(&self, key: &K) -> boolwhere
K: PartialEq,
Returns true if the map contains the given key.
Sourcepub fn values(&self) -> impl Iterator<Item = &V>
pub fn values(&self) -> impl Iterator<Item = &V>
Returns an iterator over the values of the map.
Sourcepub fn remove_strict(
&mut self,
key: &K,
expected_value: &V,
) -> Result<(), RemoveStrictError>
pub fn remove_strict( &mut self, key: &K, expected_value: &V, ) -> Result<(), RemoveStrictError>
Strict removal: only removes if both key AND expected_value
match. Returns Ok(()) on success and Err(Mismatch) on value
mismatch or missing key. Mirrors the C# NeoVM MAPREMOVE
semantics (which FAULTs if value doesn’t match), letting
contracts handle the bound explicitly.
Mismatch::Found distinguishes “missing key” (the standard
remove would have returned None) from “wrong value” (a
potential optimistic-concurrency conflict).