How Hashtable Makes Sure Object Keys Are Hashed Into A Unique Index In Javascript
After looking at a simple hash table implementation in JavaScript, the key index is computed as: function index(str, max) { var hash = 0; for (var i = 0; i < str.length; i++
Solution 1:
V8 developer here. Hashes of strings are not unique (that's kind of the point of using a hash function); V8 uses quadratic probing to deal with collisions (see source). You can read more about various strategies at https://en.wikipedia.org/wiki/Hash_table#Collision_resolution.
Also, hash = (hash & hash) % max;
is pretty silly ;-)
Post a Comment for "How Hashtable Makes Sure Object Keys Are Hashed Into A Unique Index In Javascript"