Reputation: 7314
In Rust we have many data structures available in the standard library. NEAR Protocol has some optimized data structures in near-api-rs
, but what are the main differences?
Upvotes: 1
Views: 261
Reputation: 7314
Evgeny Kuzyakov (a Near protocol engineer) answered in Discord:
If you talking about LookupMap vs HashMap then the difference is LookupMap is stored in the trie, while HashMap is stored in memory.
When a method on a contract is called, the contract reads and deserializes the main struct from the storage trie. If it contains a HashMap then all records of this map will be read and deserialized. If it contains a LookupMap then only the key_prefix will be read and deserialized, so it's cheaper from gas perspective. But every time you access a key/value from a LookupMap you have to read and deserialize it from the trie.
Upvotes: 3