MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / GetNeighbor

Method GetNeighbor

consistent/consistent.go:231–243  ·  view source on GitHub ↗

GetNeighbor returns an node close to where name hashes to in the circle.

(name string)

Source from the content-addressed store, hash-verified

229
230// GetNeighbor returns an node close to where name hashes to in the circle.
231func (c *Consistent) GetNeighbor(name string) (proto.Node, error) {
232 c.RLock()
233 defer c.RUnlock()
234 c.cacheLock.RLock()
235 defer c.cacheLock.RUnlock()
236
237 if len(c.circle) == 0 {
238 return proto.Node{}, ErrEmptyCircle
239 }
240 key := hashKey(name)
241 i := c.search(key)
242 return *c.circle[c.sortedHashes[i]], nil
243}
244
245// GetNode returns an node by its node id.
246func (c *Consistent) GetNode(name string) (*proto.Node, error) {

Callers 10

TestGetEmptyFunction · 0.80
TestGetSingleFunction · 0.80
TestGetMultipleFunction · 0.80
TestGetMultipleQuickFunction · 0.80
TestGetMultipleRemoveFunction · 0.80
BenchmarkGetFunction · 0.80
BenchmarkGetLargeFunction · 0.80
TestAddCollisionFunction · 0.80
TestConcurrentGetSetFunction · 0.80

Calls 2

searchMethod · 0.95
hashKeyFunction · 0.85

Tested by 10

TestGetEmptyFunction · 0.64
TestGetSingleFunction · 0.64
TestGetMultipleFunction · 0.64
TestGetMultipleQuickFunction · 0.64
TestGetMultipleRemoveFunction · 0.64
BenchmarkGetFunction · 0.64
BenchmarkGetLargeFunction · 0.64
TestAddCollisionFunction · 0.64
TestConcurrentGetSetFunction · 0.64