Instead of trying to write a new article in an already well-lit section, see the wikipedia article on hash functions. In particular, the first image clearly shows how several inputs are hashed to a single value.
Basically, your triplet is hashed to a certain hash value in the range [0.2 ^ 64 - 1] (duplicates are allowed!). Then the range is reduced to some slightly larger than your number of input values ββ(e.g. n = 5) through the equation hash = hash% n. The resulting ratio for input values, for example, [(1,1,1), (1,2,3), (2321, 322, 232), (3,3,3)], will look something like this:
(1,1,1) -> 2 (1,2,3) -> 0 (2321, 322, 232) -> 0 (3,3,3) -> 3
As you can see, no input value is associated (e.g. hashes) with 1 or 4, but there are two input hash values ββup to 0.
The strength of the hash (and the reason the average case is O (1)) becomes clear, noting that in order to get the input value from the hash table (for example, (1,1,1)), the following steps are performed.
- The hash x of the input value is calculated and
hash = hash % n is applied, therefore (1,1,1) β 2. - A direct search is performed O (1), i.e.
hash_function[2] = (1,1,1) + additional data stored with this particular input value . - Done!
In the case when more than one input value is matched with the same hash function value (0 in our example), the internal algorithm should search for those input values ββthat are often performed using the red-black tree (worst case O(log n) ). Thus, the worst case for any search is also O(log n) .
An ideal hash occurs when a relation becomes one-to-one in function (bijection). This gives better performance, but rarely. As I said earlier, fortunately, it's easy to create an almost perfect hash where duplicates are not enough. Essentially make your hash function as random as possible.
The examples I gave in the comments may be adequate (and the wrong way to do it) :), but a more standard caculation would be: hash = ((((prime1 + value1) * prime2) + value2) * prime3) + value3) * prime4
which also answers the question. Note that primes can be any primary, but small values ββare usually used, such as 31.37, etc.
In practice, testing can be used to test performance, but is usually not required.
In any case, re-reading your question, I wonder why you are not discarding the whole idea of ββthe hash, and not just storing your points in a simple array?