scilla icon indicating copy to clipboard operation
scilla copied to clipboard

Provide a folder for Maps

Open vaivaswatha opened this issue 7 years ago • 7 comments

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.

vaivaswatha avatar Oct 03 '18 08:10 vaivaswatha

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

jjcnn avatar Apr 01 '19 03:04 jjcnn

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

jjcnn avatar Apr 01 '19 04:04 jjcnn

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

anton-trunov avatar Feb 17 '20 08:02 anton-trunov

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?

jjcnn avatar Feb 17 '20 12:02 jjcnn

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).

anton-trunov avatar Feb 17 '20 13:02 anton-trunov

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.

jjcnn avatar Feb 17 '20 13:02 jjcnn

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.

anton-trunov avatar Feb 17 '20 13:02 anton-trunov