Big_map
A lazily deserialised map that is intended to store large amounts of
data. Here, "lazily" means that storage is read or written per key on
demand. Therefore there are no map
, fold
, and iter
operations as
there are in Map.
Compared to strict maps, which have a high upfront gas cost to deserialise all the data and then have cheaper access costs thereafter, lazily deserialised maps spread this cost out across each access, increasing the per-access gas costs, but providing a cheaper overall cost when only a small portion of a large dataset is needed.
val empty : ('key, 'value) big_map
let empty: big_map<'key, 'value>
Create an empty big map.
type move = int * int
type register = (address, move) big_map
let empty : register = Big_map.empty
type move = [int, int];
type register = big_map<address, move>;
let empty: register = Big_map.empty;
val literal : ('key * 'value) list -> ('key, 'value) big_map
let literal: (items: list<['key, 'value]>) => big_map<'key, 'value>
Create a non-empty big_map.
let moves : register =
Big_map.literal [
(("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2));
(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))]
let moves: register =
Big_map.literal (list([
[("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" as address), [1, 2]],
[("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" as address), [0, 3]]]));
val find_opt : 'key -> ('key, 'value) big_map -> 'value option
let find_opt: (key: 'key, big_map: big_map <'key, 'value>) => option <'value>
Retrieve a value from a big map with the given key.
Because the key may be missing in the big map, the result is an optional value.
let my_balance : move option =
Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves
let my_balance: option <move> =
Big_map.find_opt(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" as address), moves);
val mem : 'key -> ('key, 'value) big_map -> bool
let mem: (key: 'key, big_map: big_map <'key, 'value>) => bool
Test whether a given key exists within a big map.
let has_balance : bool =
Big_map.mem ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves
let has_balance: bool =
Big_map.mem(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" as address), moves);
val update: 'key -> 'value option -> ('key, 'value) big_map -> ('key, 'value) big_map
let update: (key: 'key, value: option<'value>, big_map: big_map<'key, 'value>) => big_map<'key, 'value>
Note: when None
is used as a value, the value is removed from the big_map.
let updated_map : register =
Big_map.update
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) moves
let updated_map: register =
Big_map.update
(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" as address), Some([4,9]), moves);
val get_and_update : 'key -> 'value option -> ('key, 'value) big_map -> value option * ('key, 'value) big_map
let get_and_update: (key: 'key, value: option<'value>, big_map: big_map<'key, 'value>) => [option<'value>, big_map<'key, 'value>]
Similar to update
but it also returns the value that was previously stored in the big_map
val add : 'key -> 'value -> ('key, 'value) big_map -> ('key, 'value) big_map
let add: (key: 'key, value: 'value, big_map: big_map<'key, 'value>) => big_map<'key, 'value>
let add (m : register) : register =
Big_map.add
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (4,9) m
let add = (m: register): register =>
Big_map.add
(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" as address), [4,9], m);
val remove: 'key -> ('key, 'value) big_map -> ('key, 'value) big_map
let remove: (key: 'key, big_map: big_map<'key, 'value>) => big_map<'key, 'value>
let updated_map : register =
Big_map.remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves
let updated_map_: register =
Big_map.remove(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" as address), moves);