A simple map that stores key/value pairs in a vector, and support multi values for one key.
- Struct
SimpleMultiMap
- Struct
Element
- Constants
- Function
new
- Function
length
- Function
is_empty
- Function
borrow
- Function
borrow_mut
- Function
borrow_first
- Function
borrow_first_mut
- Function
borrow_first_with_default
- Function
contains_key
- Function
destroy_empty
- Function
add
- Function
keys
- Function
values
- Function
to_vec_pair
- Function
remove
use 0x1::option;
use 0x1::vector;
struct SimpleMultiMap<Key, Value> has copy, drop, store
struct Element<Key, Value> has copy, drop, store
Map key is not found
const ErrorKeyNotFound: u64 = 1;
Create an empty SimpleMultiMap.
public fun new<Key, Value>(): simple_multimap::SimpleMultiMap<Key, Value>
public fun length<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>): u64
public fun is_empty<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>): bool
public fun borrow<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): &vector<Value>
public fun borrow_mut<Key, Value>(map: &mut simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): &mut vector<Value>
public fun borrow_first<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): &Value
public fun borrow_first_mut<Key, Value>(map: &mut simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): &mut Value
public fun borrow_first_with_default<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>, key: &Key, default: &Value): &Value
public fun contains_key<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): bool
public fun destroy_empty<Key, Value>(map: simple_multimap::SimpleMultiMap<Key, Value>)
public fun add<Key: drop, store, Value: store>(map: &mut simple_multimap::SimpleMultiMap<Key, Value>, key: Key, value: Value)
Return all keys in the map. This requires keys to be copyable.
public fun keys<Key: copy, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>): vector<Key>
Return all values in the map. This requires values to be copyable. This function flatten the vector<vector> to vector
public fun values<Key, Value: copy>(map: &simple_multimap::SimpleMultiMap<Key, Value>): vector<Value>
Transform the map into two vectors with the keys and values respectively Primarily used to destroy a map Note: Do not assume the key's order
public fun to_vec_pair<Key, Value>(map: simple_multimap::SimpleMultiMap<Key, Value>): (vector<Key>, vector<vector<Value>>)
public fun remove<Key, Value>(map: &mut simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): (Key, vector<Value>)