[erlang-questions] map elements in defined order
Jesper Louis Andersen
Thu Oct 26 20:31:43 CEST 2017
It is generally a bad idea to rely on order in anything which uses a hash
function. The hash function is often subject to change---rather quickly I
might add if it proves to be a security bug. Picking a family of hashes and
seeding it randomly is usually a good trick.
Our "sister language" Go *randomizes* iteration order on its maps. This is
to force programmers into not relying on the map order at all, even if it
happens to be ordered right now. This opens up implementations in the
If you wanted order in a map, it would be *far* better if you could create
a map based on RB-trees or the like. Those are naturally ordered by
structure. OCaml, for instance, defines Hash Tables as well as Maps. The
latter is the ordered variant.
On Thu, Oct 26, 2017 at 8:07 PM Ulf Wiger <ulf@REDACTED> wrote:
> But they *are* ordered. Otherwise, comparison of two maps would be
> Ulf W
> Den 26 okt. 2017 18:20 skrev "Roger Lipscombe" <roger@REDACTED>:
> On 26 October 2017 at 16:30, Ulf Wiger <ulf@REDACTED> wrote:
> > Wouldn't it be reasonable to have such a function?
> First thought: No, because people would start abusing it. Maps *aren't*
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions