Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Curious: are anon-hashes in random order?

by BrowserUk (Pope)
on Sep 13, 2016 at 15:22 UTC ( #1171682=note: print w/replies, xml ) Need Help??


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.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^2: Curious: are anon-hashes in random order?

Replies are listed 'Best First'.
Re^3: Curious: are anon-hashes in random order?
by syphilis (Chancellor) on Sep 13, 2016 at 20:41 UTC
    *the 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

    The above can be attributed to BrowserUk, and I was hoping to register the fact that I (syphilis) had given his view a ++ (and would have given even more upvotes if such were possible).
    However, when I preview my post, I find that it is being attributed to gods.
    What is going on ? (A "god" is the last fucking thing I would want to be ;-)

    Cheers,
    Rob
      However, when I preview my post, I find that it is being attributed to gods.

      It seems, though I never noticed it before, so it may be a recent change, that all previews are attributed to "gods", until you commit them.

      It makes some sense in that if you choose to abandon a preview, it will be discarded, so not connecting it to a particular account before that point might save some DB fiddling.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Curious: are anon-hashes in random order?
by haukex (Monsignor) on Sep 13, 2016 at 15:29 UTC

    Hi BrowserUk,

    I admit my knowledge of the internals of hashing is limited; thank you for the clarification!

    Regards,
    -- Hauke D

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1171682]
help
Chatterbox?
holli scratches his head
holli feels silly

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2017-09-24 14:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (274 votes). Check out past polls.

    Notices?