As made clear in update 3 on this answer , this notation:(正如在这个答案的更新3中所表明的那样,这种表示法:)
var hash = {};
hash[X]
does not actually hash the object X
;(实际上并没有散列对象X
;) it actually just converts X
to a string (via .toString()
if it's an object, or some other built-in conversions for various primitive types) and then looks that string up, without hashing it, in " hash
".(它实际上只是将X
转换为字符串(如果它是一个对象,则通过.toString()
,或者为各种基本类型转换为其他一些内置转换),然后在“ hash
”中查找该字符串,而不对其进行hash
。) Object equality is also not checked - if two different objects have the same string conversion, they will just overwrite each other.(也不检查对象相等性 - 如果两个不同的对象具有相同的字符串转换,它们将仅相互覆盖。)
Given this - are there any efficient implementations of hashmaps in javascript?(鉴于此 - 在JavaScript中是否有任何有效的哈希映射实现?) (For example, the 2nd Google result of javascript hashmap
yields an implementation which is O(n) for any operation. Various other results ignore the fact that different objects with equivalent string representations overwrite each other.((例如, javascript hashmap
的第二个Google结果产生了任何操作的O(n)实现。各种其他结果忽略了具有等效字符串表示的不同对象相互覆盖的事实。)
ask by Claudiu translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…