in reply to Re: Curious: are anon-hashes in random order? (updated)
in thread Curious: are anon-hashes in random order?
it's not like hashes themselves are shuffled in memory, it's the order in which they are iterated over that is randomized.
Actually, it is neither.
The "randomisation" takes the form of picking a single random number to seed the accumulator(*) when performing the hashing calculation for storing or retrieving the keys. Ie. by randomly initialising the accumulator, the position within the array that underlies the hash implementation, into which any given key gets stored, varies from hash to hash and run to run.
More importantly, the order in which the underlying array is iterated (first to last) when using each or keys or values is constant for all hashes and all runs -- thus very efficient. The randomisation occurs do to the addition of a (per hash, randomly chosen once) offset that gets added to all the hashing calculations and thus causes the same key to get stored in different slots for different hashes; and different slots for the same hash for different runs.
*there was, belatedly, some attempt to add a choice of different hashing algorithms to the mix; but these proved pointless overkill and pragmatically too inefficient; and fell into immediate disuse. If they are still needlessly cluttering the codebase -- I haven't looked lately -- it is simply because no one has got around to removing them.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Curious: are anon-hashes in random order?
by syphilis (Archbishop) on Sep 13, 2016 at 20:41 UTC | |
by haukex (Archbishop) on Sep 14, 2016 at 09:28 UTC | |
by BrowserUk (Patriarch) on Sep 13, 2016 at 22:00 UTC | |
|
Re^3: Curious: are anon-hashes in random order?
by haukex (Archbishop) on Sep 13, 2016 at 15:29 UTC |