简体   繁体   English

如果 ArrayMap 或 SparseArray 中键的散列冲突怎么办?

[英]What if there is conflict of hashing of keys in ArrayMap or SparseArray?

I have read many blogs for array map and sparse array where every where I am getting that我已经阅读了许多关于数组映射和稀疏数组的博客,其中每个地方我都得到了

ArrayMap contains two small array instead of one in a HashMap. ArrayMap 包含两个小数组而不是 HashMap 中的一个。 The first array (Hash-Array) contains the specified hash keys in sorted order.第一个数组 (Hash-Array) 按排序顺序包含指定的哈希键。 The second array (Key Value Array) stores the keys and values of the objects according to the first array.第二个数组(Key Value Array)根据第一个数组存储对象的键和值。 For reference below link is given https://android.jlelse.eu/app-optimization-with-arraymap-sparsearray-in-android-c0b7de22541a以下链接供参考https://android.jlelse.eu/app-optimization-with-arraymap-sparsearray-in-android-c0b7de22541a

But no where I am getting that what happens if I have same hash code for two different keys in array map as in hash map it happens that in case having same key hash(collision) it appends the key value pair in linked list for a given bucket position for the next item.但是,如果我在数组映射中的两个不同键的哈希码与哈希映射中的相同,那么如果我在哈希映射中具有相同的哈希码,会发生什么情况,如果具有相同的键哈希(冲突),它会在给定的链表中附加键值对下一个项目的桶位置。

Unlike the hashMap in ArrayMap when a hash collision occurs, instead of appending the key value pair in linked list for a given bucket position, for the next item it simply puts the value in next available position in second array.与 ArrayMap 中发生哈希冲突时的 hashMap 不同,它不是将给定桶位置的键值对附加到链表中,而是将下一项的值放在第二个数组中的下一个可用位置。 And for searching, when a hash collision occurs, it walk though the second array until finds the desired values .对于搜索,当发生哈希冲突时,它会遍历第二个数组,直到找到所需的值

Here it is described in provided doc:在提供的文档中对其进行了描述:

When we fetch an item, a binary-search is done on the Hash-Array to find a matching hash the index and then directly return the key-value pair from the second array (Key Value Array).当我们获取一个项目时,会在 Hash-Array 上进行二分搜索以找到匹配的哈希索引,然后直接从第二个数组(键值数组)中返回键值对。 If the key in the second array (Key Value Array), doesn't match then a linearly walk is done over the second array (Key Value Array) to resolve the collision.如果第二个数组(键值数组)中的键不匹配,则在第二个数组(键值数组)上进行线性遍历以解决冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM