3 ms·
I doubt that’s why. Modern hash tables typically include a random factor in the hashing to prevent bucketing from being predictable, so attackers can’t craft ma
by lilyball 5y ago
I doubt that’s why. Modern hash tables typically include a random factor in the hashing to prevent bucketing from being predictable, so attackers can’t craft malicious input that causes every value to be put in the same bucket as a form of DOS attack. The fact that this means iteration order is randomized is a side effect.
- codys 5y agoThe insertion of a random factor in hashing/bucketing that you're describing would change the iteration order per _instance_ of a hash table, not per _iteration_ as the parent comment notes is the case for go maps.
- lilyball 5y agoIt's per _iteration_? That was not clear. Parent comment said "execution", not "iteration". I interpreted that as per execution of the program.
- benesch 5y agoNo, the OP is correct: the Go developers intentionally introduced randomness into map iteration order to shake out bugs. For evidence, see: https://github.com/golang/go/issues/6719 https://github.com/golang/go/issues/6719 https://stackoverflow.com/a/55925880 https://stackoverflow.com/a/55925880 https://codereview.appspot.com/5285042 https://codereview.appspot.com/5285042