views:

181

answers:

2

Is it possible to create collision free hash function for a data structure with specific properties.

  1. The datastructure is int[][][]
  2. It contains no duplicates
  3. The range of integers that are contained in it is defined. Let's say it's 0..1000, the maximal integer is definitely not greater than 10000.

Big problem is that this hash function should also be very fast. Is there a way to create such a hash function? Maybe at run time depending on the integer range?

ADDITION: I should say that the purpose of this hash function is to quckily check if the particular combination was processed. So when some combination of numbers in the data structure is processed, I calculate the hash value and store it. Then when processing another combination of numbers within the data structure I will compare the hash values.

+3  A: 

I think what you want is a "perfect hash" or even a "minimal perfect hash":

http://en.wikipedia.org/wiki/Perfect_hash_function

Edit: That said, if you're sure and certain you'll never go above [0...1000] and depending on what you need to do you probably can simply "bucket" your results directly in an array. If you don't have many elements, that array would be sparse (and hence a bit of a waste) but for at most 1001 elements going from [0...1000] an Object[1001] (or int[1001] or whatever) will probably do.

Webinator
A: 

what if you just use a 64-bit value and store the location in each level of the hierarchy into one section of bits?

something like(off the top of my head): hash = (a << 34) | (b << 17) | (c)

jessecurry