Re: Best way to hash a set of integers?
- From: "Digital Puer" <digital_puer@xxxxxxxxxxx>
- Date: 19 Sep 2006 16:11:48 -0700
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.
.
- Follow-Ups:
- Re: Best way to hash a set of integers?
- From: Logan Shaw
- Re: Best way to hash a set of integers?
- From: Richard Heathfield
- Re: Best way to hash a set of integers?
- References:
- Best way to hash a set of integers?
- From: Digital Puer
- Re: Best way to hash a set of integers?
- From: toby
- Re: Best way to hash a set of integers?
- From: Digital Puer
- Re: Best way to hash a set of integers?
- From: Ben Pfaff
- Best way to hash a set of integers?
- Prev by Date: Re: Getting a C++ compiler for Windows XP
- Next by Date: Re: Best way to hash a set of integers?
- Previous by thread: Re: Best way to hash a set of integers?
- Next by thread: Re: Best way to hash a set of integers?
- Index(es):
Relevant Pages
|