// Get performs a lookup of the key that key points to. It returns a pointer to
// the element, or false if the key doesn't exist.
func (m *Map) Get(key unsafe.Pointer) (unsafe.Pointer, bool) {
- _, elem, ok := m.getWithKey(key)
- return elem, ok
+ return m.getWithoutKey(key)
}
func (m *Map) getWithKey(key unsafe.Pointer) (unsafe.Pointer, unsafe.Pointer, bool) {
return m.directoryAt(idx).getWithKey(hash, key)
}
+func (m *Map) getWithoutKey(key unsafe.Pointer) (unsafe.Pointer, bool) {
+ hash := m.typ.Hasher(key, m.seed)
+
+ if m.dirLen == 0 {
+ _, elem, ok := m.getWithKeySmall(hash, key)
+ return elem, ok
+ }
+
+ idx := m.directoryIndex(hash)
+ return m.directoryAt(idx).getWithoutKey(hash, key)
+}
+
func (m *Map) getWithKeySmall(hash uintptr, key unsafe.Pointer) (unsafe.Pointer, unsafe.Pointer, bool) {
g := groupReference{
typ: m.typ,
}
}
+func (t *table) getWithoutKey(hash uintptr, key unsafe.Pointer) (unsafe.Pointer, bool) {
+ seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
+ for ; ; seq = seq.next() {
+ g := t.groups.group(seq.offset)
+
+ match := g.ctrls().matchH2(h2(hash))
+
+ for match != 0 {
+ i := match.first()
+
+ slotKey := g.key(i)
+ if t.typ.Key.Equal(key, slotKey) {
+ return g.elem(i), true
+ }
+ match = match.removeFirst()
+ }
+
+ match = g.ctrls().matchEmpty()
+ if match != 0 {
+ // Finding an empty slot means we've reached the end of
+ // the probe sequence.
+ return nil, false
+ }
+ }
+}
+
// PutSlot returns a pointer to the element slot where an inserted element
// should be written, and ok if it returned a valid slot.
//