We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b2a3031 commit 5fa71e0Copy full SHA for 5fa71e0
map.md
@@ -287,6 +287,18 @@ again:
287
// 这里的 bucketCnt 是全局常量
288
// 其实叫 bucketElemCnt 更合适
289
if b.tophash[i] != top {
290
+ // 在 b.tophash[i] != top 的情况下
291
+ // 理论上有可能会是一个空槽位
292
+ // 一般情况下 map 的槽位分布是这样的,e 表示 empty:
293
+ // [h1][h2][h3][h4][h5][e][e][e]
294
+ // 但在执行过 delete 操作时,可能会变成这样:
295
+ // [h1][h2][e][e][h5][e][e][e]
296
+ // 所以如果再插入的话,会尽量往前面的位置插
297
298
+ // ^
299
300
+ // 这个位置
301
+ // 所有在循环的时候还要顺便把前面的空位置先记下来
302
if b.tophash[i] == empty && inserti == nil {
303
// 如果这个槽位没有被占,说明可以往这里塞 key 和 value
304
inserti = &b.tophash[i] // tophash 的插入位置
0 commit comments