hashring

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(key string) uint32

Types

type HashRing

type HashRing[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any]() *HashRing[T]

func (*HashRing[T]) Add

func (h *HashRing[T]) Add(slots ...Slot[T])

Add slots to hashring. It will be slow if you call too often

func (*HashRing[T]) Count

func (h *HashRing[T]) Count() int

Count slot number

func (*HashRing[T]) ForEach

func (h *HashRing[T]) ForEach(fn func(index int, hash uint32, value T))

ForEach hashring

func (*HashRing[T]) Get

func (h *HashRing[T]) Get(key string) (Slot[T], bool)

Get slot by key

func (*HashRing[T]) GetNext

func (h *HashRing[T]) GetNext(s Slot[T]) Slot[T]

GetNext from slot

func (*HashRing[T]) GetPrev

func (h *HashRing[T]) GetPrev(s Slot[T]) Slot[T]

GetPrev from slot

func (*HashRing[T]) Len

func (h *HashRing[T]) Len() int

sort

func (*HashRing[T]) Less

func (h *HashRing[T]) Less(i, j int) bool

func (*HashRing[T]) Remove

func (h *HashRing[T]) Remove(keys ...string)

Remove slot by keys

func (*HashRing[T]) Sort

func (h *HashRing[T]) Sort()

Sort hashring

func (*HashRing[T]) Swap

func (h *HashRing[T]) Swap(i, j int)

func (*HashRing[T]) UnsortAdd

func (h *HashRing[T]) UnsortAdd(slots ...Slot[T])

UnsortAdd slots to hashring, but no sort

type Slot

type Slot[T any] struct {
	// contains filtered or unexported fields
}

func NewSlot

func NewSlot[T any](key string, value T) Slot[T]

func (*Slot[T]) GetValue

func (s *Slot[T]) GetValue() T

func (*Slot[T]) Hash

func (s *Slot[T]) Hash() uint32

Jump to

Keyboard shortcuts

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