consistenthash

package
v2.7.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

Current implementation

$ go test -bench=. ./...
goos: linux
goarch: amd64
pkg: github.com/modernprogram/groupcache/v2/consistenthash
cpu: 13th Gen Intel(R) Core(TM) i7-1360P
BenchmarkGet8-16      	27974676	        37.06 ns/op
BenchmarkGet32-16     	29410753	        39.68 ns/op
BenchmarkGet128-16    	25937828	        45.28 ns/op
BenchmarkGet512-16    	19554933	        54.32 ns/op
PASS
ok  	github.com/modernprogram/groupcache/v2/consistenthash	4.769s

Previous implementation

$ go test -bench=. ./...
goos: linux
goarch: amd64
pkg: github.com/modernprogram/groupcache/v2/consistenthash
cpu: 13th Gen Intel(R) Core(TM) i7-1360P
BenchmarkGet8-16      	27004227	        43.38 ns/op
BenchmarkGet32-16     	24552079	        47.78 ns/op
BenchmarkGet128-16    	21309058	        53.39 ns/op
BenchmarkGet512-16    	14953760	        71.02 ns/op
PASS
ok  	github.com/modernprogram/groupcache/v2/consistenthash	5.747s

Documentation

Overview

Package consistenthash provides an implementation of a ring hash.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

type Hash func(data []byte) uint64

type Map

type Map struct {
	// contains filtered or unexported fields
}

func New

func New(replicas int, fn Hash) *Map

func (*Map) Add

func (m *Map) Add(keys ...string)

Add adds some keys to the hash.

func (*Map) Get

func (m *Map) Get(key string) string

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

func (*Map) IsEmpty

func (m *Map) IsEmpty() bool

IsEmpty returns true if there are no items available.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL