mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Fix the code of hash map chaining.
This commit is contained in:
@ -78,8 +78,13 @@ class HashMapChaining {
|
||||
int index = hashFunc(key);
|
||||
List<Pair> bucket = buckets[index];
|
||||
// 遍历桶,从中删除键值对
|
||||
bucket.removeWhere((Pair pair) => pair.key == key);
|
||||
size--;
|
||||
for (Pair pair in bucket) {
|
||||
if (pair.key == key) {
|
||||
bucket.remove(pair);
|
||||
size--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 扩容哈希表 */
|
||||
|
||||
Reference in New Issue
Block a user