2 comments
> Like addition<p>I'm perplexed to the claim that addition is cheaper than XOR, especially since addition is built upon XOR, am I missing anything? Is it javascript specific?
a hash function that produce hashes that are already in the hash table should, IMO, not be called a hash function.<p>I get why technically it is a hash function, but still, no.
It is mathematically impossible for a proper hash function (one with an output range smaller than its input range) to not have collisions. The proof uses the Pigeon Hole Principle <a href="https://en.wikipedia.org/wiki/Pigeonhole_principle" rel="nofollow">https://en.wikipedia.org/wiki/Pigeonhole_principle</a>
A perfect hash function
<a href="https://en.wikipedia.org/wiki/Perfect_hash_function" rel="nofollow">https://en.wikipedia.org/wiki/Perfect_hash_function</a> has to be specially constructed for each desired set of inputs. Generic hash functions cannot be 'perfect'.
Here is a hash function that does not have hash collisions:<p><pre><code> fn hash(data):
return data</code></pre>