logoalt Hacker News

lilyballyesterday at 7:47 PM1 replyview on HN

This claim sounds vaguely familiar to me (though the documentation on Dictionary does not state any reason for why the iteration order is unpredictable), though the more common reason for languages to have unstable hash table iteration orders is as a consequence of protection against hash flooding, malicious input causing all keys to hash to the same bucket (because iteration order is dependent on bucket order).


Replies

frizlabyesterday at 11:33 PM

Oh yeah you’re right, apparently the main reason was to avoid hash-flooding attacks[1].

I do seem to remember there was a claim regarding the fact that it also prevented a certain class of errors (that I mentioned earlier), but I cannot find the source again, so it might just be my memory playing tricks on me.

[1] https://forums.swift.org/t/psa-the-stdlib-now-uses-randomly-...