t.hash(0.00000000000000002) == t.hash(0.00000000000000003)
How often would this cause issues in real-world? t.hash(0.00000000000000002) == t.hash(0.00000000000000003)
How often would this cause issues in real-world?So if a hash function has lots of collisions it will use the memory of the hash table less efficiently and cause inserts and lookups to be slower. I think collisions are undesirable for other reasons too, none of which are coming to me right now.
The thing that bothers me personally about these examples is that there are a lot that end in 0x000000 or 0xffffff, i.e. all bits set or all bits unset in many of the trailing bits.
If you use this for a hash table, a common way that you get your index into the table is:
index = hash_result % table_size
If you use power-of-two table sizes, then you are going to get these collisions, even though the upper bits differ.You can use a non-power-of-two table size to compensate for this (prime sizes are typically the most robust choice I think) at the cost of a more expensive modulo operation. See more here in the first section: https://en.wikipedia.org/wiki/Hash_table#Hashing