func (t *table) Delete(typ *abi.SwissMapType, m *Map, hash uintptr, key unsafe.Pointer) {
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)
match := g.ctrls().matchH2(h2(hash))
for match != 0 {
i := match.first()
slotKey := g.key(typ, i)
origSlotKey := slotKey
if typ.IndirectKey() {
slotKey = *((*unsafe.Pointer)(slotKey))
}
if typ.Key.Equal(key, slotKey) {
t.used--
m.used--
if typ.IndirectKey() {
*(*unsafe.Pointer)(origSlotKey) = nil
} else if typ.Key.Pointers() {
typedmemclr(typ.Key, slotKey)
}
slotElem := g.elem(typ, i)
if typ.IndirectElem() {
*(*unsafe.Pointer)(slotElem) = nil
} else {
typedmemclr(typ.Elem, slotElem)
}
if g.ctrls().matchEmpty() != 0 {
g.ctrls().set(i, ctrlEmpty)
t.growthLeft++
} else {
g.ctrls().set(i, ctrlDeleted)
}
t.checkInvariants(typ, m)
return
}
match = match.removeFirst()
}
match = g.ctrls().matchEmpty()
if match != 0 {
return
}
}
}
- 根据哈希值的高位构造探测序列
- 循环遍历
- SIMD快速匹配候选人
- 逐个比较候选人的键
- 如果找到, 是指针就清零, 不是指针就清内存
- 未找到,则继续下一个Group,直到到达终点
- 清空后,看组里有没有空位
- 有,说明是探测序列终点,可以置metadata为空
- 没有,说明组内满员,不是终点,置为墓碑(ctrlDeleted)