Zilliqa / scilla

Scilla - A Smart Contract Intermediate Level Language
https://scilla-lang.org
GNU General Public License v3.0
240 stars 78 forks source link

Provide a folder for Maps #254

Open vaivaswatha opened 5 years ago

vaivaswatha commented 5 years ago

The current way to iterate over Maps is to convert it to a list (builtin to_list) and then fold over the list. It may be faster (lesser gas consumed) to directly iterate (fold) over the Map.

jjcnn commented 5 years ago

Note that the design for this issue may affect the design of issue #516.

jjcnn commented 5 years ago

Consider adding iterators for maps as well. This would definitely impact the design of #516.

anton-trunov commented 4 years ago

FWIW, Solidity does not allow contracts to iterate over the keys of a mapping.

jjcnn commented 4 years ago

I thought about this a while ago, and I couldn't come up with a better way to do it than what @vaivaswatha suggests above, so maybe we should just retire this issue?

anton-trunov commented 4 years ago

Speaking of the pure fragment of Scilla, we could expose the underlying OCaml map fold as a primitive.

Btw, this would allow us to retire builtin to_list as this one could be implemented in Scilla then (although we might want to keep it because e.g. of performance reasons).

jjcnn commented 4 years ago

Can we guarantee the traversal order? i suppose we can, since we appear to be able to guarantee determinism of Hashtable.to_list or whatever it's called in OCaml.

anton-trunov commented 4 years ago

Right, citing the OCaml manual:

If the hash table was created in non-randomized mode, the order in which the bindings are enumerated is reproducible between successive runs of the program, and even between minor versions of OCaml. For randomized hash tables, the order of enumeration is entirely random.