Re: Best way to hash a set of integers?




Ben Pfaff wrote:
"Digital Puer" <digital_puer@xxxxxxxxxxx> writes:

However, I'm still looking for info on how to best hash a *set*
of integers; do I add them, XOR them, multiply them, etc. to
get a final key? What are best practices?

That this was what you wanted wasn't clear to me at first. It's
a more interesting question that hashing a single integer.

I would suggest XOR'ing the integers, then using an integer hash
algorithm on the composite value. Of course, whether XOR is the
best function to use depends on properties of the sets. Can you
tell us anything about the sets?


I guess I'm looking for a way to compute what could be
called a multi-dimensional key. Suppose I have three integers
representing age, height (in cm), and weight (in lbs). I want
to somehow combine those together into a single key that will be
my index into a hash table (prior to doing mod hash_table_size).

Some approaches I can think of:
-- If I know the range of each value, I can use something like atoi,
like age*100 + height * 10 + weight
-- I could create a multi-level data structure, like a hash table
that leads to another hash table that leads to another hash table
(or with binary trees).
-- I could do some arbitrary artihmetic like XOR.

.



Relevant Pages

  • Re: GetHashCode for Objects that Compare Based on Value (Not reference equality)
    ... Further, for those sets of data, an XOR hash produces a sufficiently ... random distribution for hashes to work just fine. ... realm of developing a good generic algorithm; ... Saying that XOR produces collisions is not very useful. ...
    (microsoft.public.dotnet.framework)
  • Re: Help me break this stupid cipher I just invented. :P
    ... C= x xor b ... When I look at this, it looks a lot like the common XOR against a PRNG, ... But if you're using a cryptographically strong one-way hash, ... creating a secure key stream in this sort of crypto system. ...
    (sci.crypt)
  • Re: Best Way To Randomize/Salt A Text String Before SHA256?
    ... XOR wouldn't work. ... then the value you actually hash is ... you publish both "Apple" and the random r value ... length r, or publish the length of r in the commitment (otherwise, if you ...
    (sci.crypt)
  • Re: New non-cryptograhic hash function(s)
    ... whether that's a good hash or not, but I did notice one interesting ... This is the first design I came up with and after some ... I know that it can be proven that XOR or better: addition modulo 2 in base 2 ... a hash function is more trial and error with a touch of theory than any well ...
    (comp.programming)
  • Re: Windows Vista half price
    ... Hash: SHA1 ... and several other papers. ... That page leads me to a 404 error. ...
    (Ubuntu)