The generic type parameter K
can be any valid AssemblyScript type.
The generic type parameter V
can be any valid AssemblyScript type.
MISC:
Original code from Near (https://github.com/near/near-sdk-as/blob/master/sdk-core/assembly/collections/persistentMap.ts)
Creates or restores a persistent map with a given storage prefix. Always use a unique storage prefix for different collections.
Example
let map = new PersistentMap<string, string>("m") // note the prefix must be unique (per Massa account)
A prefix to use for every key of this map.
Retrieves the related value for a given key, or uses the defaultValue
if not key is found
let map = new PersistentMap<string, string>("m")
map.set("hello", "world")
let found = map.get("hello")
let notFound = map.get("goodbye", "cruel world")
assert(found == "world")
assert(notFound == "cruel world")
Value for the given key or the default value.
Key of the element.
The default value if the key is not present.
Retrieves a related value for a given key or fails assertion with "key not found"
let map = new PersistentMap<string, string>("m")
map.set("hello", "world")
let result = map.getSome("hello")
// map.getSome("goodbye") // will throw with failed assertion
assert(result == "world")
Value for the given key or the default value.
Key of the element.
Generated using TypeDoc
This class is one of several convenience collections built on top of the
Storage
class It implements a map -- a persistent unordered map.To create a map
To use the map
IMPORTANT NOTES:
(1) The Map doesn't store keys, so if you need to retrieve them, include keys in the values.
(2) Since all data stored on the blockchain is kept in a single key-value store under the contract account, you must always use a unique storage prefix for different collections to avoid data collision.