Collections
When deciding on data structures to use for the data of the application, it is important to minimize the amount of data read and written to storage but also the amount of data serialized and deserialized to minimize the cost of transactions.
The collections within
near-sdk
are designed to split the data into chunks and defer reading and writing to the store until needed. These data structures will handle the low-level storage interactions and aim to have a similar API to thestd::collections
.When using
std::collections
, each time state is loaded, all entries in the data structure will be read eagerly from storage and deserialized. This will come at a large cost for any non-trivial amount of data.
Existing Data Structures
SDK collection |
| Description |
|
| Optional value in storage. This value will only be read from storage when interacted with. This value will be |
|
| A growable array type. The values are sharded in memory and can be used for iterable and indexable values that are dynamically sized. |
|
| This structure behaves as a thin wrapper around the key-value storage available to contracts. This structure does not contain any metadata about the elements in the map, so it is not iterable. |
|
| Similar to |
|
| An ordered equivalent of |
|
| A set, which is similar to |
|
| An iterable equivalent of |
Last updated