Skip to content

Latest commit

 

History

History
240 lines (105 loc) · 7.93 KB

simple_multimap.md

File metadata and controls

240 lines (105 loc) · 7.93 KB

Module 0x2::simple_multimap

A simple map that stores key/value pairs in a vector, and support multi values for one key.

Struct SimpleMultiMap

struct SimpleMultiMap<Key, Value> has copy, drop, store

Struct Element

struct Element<Key, Value> has copy, drop, store

Constants

Map key is not found

const ErrorKeyNotFound: u64 = 1;

Function new

Create an empty SimpleMultiMap.

public fun new<Key, Value>(): simple_multimap::SimpleMultiMap<Key, Value>

Function length

public fun length<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>): u64

Function is_empty

public fun is_empty<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>): bool

Function borrow

public fun borrow<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): &vector<Value>

Function borrow_mut

public fun borrow_mut<Key, Value>(map: &mut simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): &mut vector<Value>

Function borrow_first

public fun borrow_first<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): &Value

Function borrow_first_mut

public fun borrow_first_mut<Key, Value>(map: &mut simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): &mut Value

Function borrow_first_with_default

public fun borrow_first_with_default<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>, key: &Key, default: &Value): &Value

Function contains_key

public fun contains_key<Key, Value>(map: &simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): bool

Function destroy_empty

public fun destroy_empty<Key, Value>(map: simple_multimap::SimpleMultiMap<Key, Value>)

Function add

public fun add<Key: drop, store, Value: store>(map: &mut simple_multimap::SimpleMultiMap<Key, Value>, key: Key, value: Value)

Function keys

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>

Function values

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>

Function to_vec_pair

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>>)

Function remove

public fun remove<Key, Value>(map: &mut simple_multimap::SimpleMultiMap<Key, Value>, key: &Key): (Key, vector<Value>)