Expand description
Collections that offer an alternative to standard containers from std::collections::*
by
utilizing the underlying blockchain trie storage more efficiently.
The updated version of this module lives in near_sdk::store
,
where the data structures are more optimized and have a closer API to std::collections
.
For example, the following smart contract does not work with state efficiently, because it will
load the entire HashMap
at the beginning of the contract call, and will save it entirely at
the end, in cases when there is state modification. This is fine for small number of elements,
but very inefficient for large numbers.
#[near(contract_state)]
pub struct StatusMessage {
records: HashMap<String, String>,
}
The following is an efficient alternative. It will load each element individually only when it is read and will save it only when it is written/removed.
#[near(contract_state)]
pub struct StatusMessage {
records: LookupMap<String, String>,
}
The efficiency of LookupMap
comes at the cost, since it has fewer methods than HashMap
and is not
that seamlessly integrated with the rest of the Rust standard library.
Re-exports§
pub use vector::Vector;
pub use unordered_map::UnorderedMap;
Modules§
- unordered_
map - A map implemented on a trie. Unlike
std::collections::HashMap
the keys in this map are not hashed but are instead serialized. - vector
- A vector implemented on a trie. Unlike standard vector does not support insertion and removal of an element results in the last element being placed in the empty position.
Structs§
- Lazy
Option - An persistent lazy option, that stores a value in the storage.
- Legacy
Tree Map Deprecated - TreeMap based on AVL-tree
- Lookup
Map - An non-iterable implementation of a map that stores its content directly on the trie.
- Lookup
Set - A non-iterable implementation of a set that stores its content directly on the storage trie.
- TreeMap
- TreeMap based on AVL-tree
- Unordered
Set - An iterable implementation of a set that stores its content directly on the trie.