consistenthash

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package consistenthash provides an implementation of consistent hashing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashFunc

type HashFunc func(b []byte) uint32

HashFunc is a function type that implements the Hasher interface.

func (HashFunc) Hash

func (hf HashFunc) Hash(b []byte) uint32

Hash implements the Hasher interface for HashFunc.

type Hasher

type Hasher interface {
	Hash(b []byte) uint32
}

Hasher defines an interface for hash functions that produce uint32 values.

type Map

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

Map implements consistent hashing ring.

func New

func New(k int, h Hasher) *Map

New creates a new 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

Returns true if there are no items available.

func (*Map) ReadFrom

func (m *Map) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom implements io.ReaderFrom.

func (Map) WriteTo

func (m Map) WriteTo(w io.Writer) (n int64, err error)

WriteTo implements io.WriterTo.

Jump to

Keyboard shortcuts

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