Module sui::vec_map
- Struct 
VecMap - Struct 
Entry - Constants
 - Function 
empty - Function 
insert - Function 
remove - Function 
pop - Function 
get_mut - Function 
get - Function 
try_get - Function 
contains - Function 
size - Function 
is_empty - Function 
destroy_empty - Function 
into_keys_values - Function 
from_keys_values - Function 
keys - Function 
get_idx_opt - Function 
get_idx - Function 
get_entry_by_idx - Function 
get_entry_by_idx_mut - Function 
remove_entry_by_idx 
use std::option;
use std::vector;
Struct VecMap
A map data structure backed by a vector. The map is guaranteed not to contain duplicate keys, but entries are not sorted by key--entries are included in insertion order. All operations are O(N) in the size of the map--the intention of this data structure is only to provide the convenience of programming against a map API. Large maps should use handwritten parent/child relationships instead. Maps that need sorted iteration rather than insertion order iteration should also be handwritten.
public struct VecMap<K: copy, V> has copy, drop, store
Fields
- contents: vector<sui::vec_map::Entry<K, V>>
 
Struct Entry
An entry in the map
public struct Entry<K: copy, V> has copy, drop, store
Fields
- key: K
 - value: V
 
Constants
This key already exists in the map
const EKeyAlreadyExists: u64 = 0;
This key does not exist in the map
const EKeyDoesNotExist: u64 = 1;
Trying to destroy a map that is not empty
const EMapNotEmpty: u64 = 2;
Trying to access an element of the map at an invalid index
const EIndexOutOfBounds: u64 = 3;
Trying to pop from a map that is empty
const EMapEmpty: u64 = 4;
Trying to construct a map from keys and values of different lengths
const EUnequalLengths: u64 = 5;
Function empty
Create an empty VecMap
public fun empty<K: copy, V>(): sui::vec_map::VecMap<K, V>
Function insert
Insert the entry key |-> value into self. Aborts if key is already bound in self.
public fun insert<K: copy, V>(self: &mut sui::vec_map::VecMap<K, V>, key: K, value: V)
Implementation
public fun insert<K: copy, V>(self: &mut VecMap<K, V>, key: K, value: V) {
    assert!(!self.contains(&key), EKeyAlreadyExists);
    self.contents.push_back(Entry { key, value })
}
Function remove
Remove the entry key |-> value from self. Aborts if key is not bound in self.
public fun remove<K: copy, V>(self: &mut sui::vec_map::VecMap<K, V>, key: &K): (K, V)
Function pop
Pop the most recently inserted entry from the map. Aborts if the map is empty.
public fun pop<K: copy, V>(self: &mut sui::vec_map::VecMap<K, V>): (K, V)