MCPcopy Create free account
hub / github.com/golang/groupcache / Get

Method Get

consistenthash/consistenthash.go:65–81  ·  view source on GitHub ↗

Get gets the closest item in the hash to the provided key.

(key string)

Source from the content-addressed store, hash-verified

63
64// Get gets the closest item in the hash to the provided key.
65func (m *Map) Get(key string) string {
66 if m.IsEmpty() {
67 return ""
68 }
69
70 hash := int(m.hash([]byte(key)))
71
72 // Binary search for appropriate replica.
73 idx := sort.Search(len(m.keys), func(i int) bool { return m.keys[i] >= hash })
74
75 // Means we have cycled back to the first replica.
76 if idx == len(m.keys) {
77 idx = 0
78 }
79
80 return m.hashMap[m.keys[idx]]
81}

Callers

nothing calls this directly

Calls 1

IsEmptyMethod · 0.95

Tested by

no test coverage detected