ring

package
v0.0.0-...-70736be Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const Size = 256

Size indicates the exact number of virtual-nodes on the ring.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparable

type Comparable interface {
	comparable
	Hash() string
}

type Ring

type Ring[K Comparable] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewRing

func NewRing[K Comparable]() *Ring[K]

func (*Ring[K]) Add

func (r *Ring[K]) Add(position int, node K) any

Add a new node to the ring on the specified position. If a node with the same position is already exists, replace it then return the old node.

func (*Ring[K]) All

func (r *Ring[K]) All() []K

All returns virtual nodes on the ring sorted by their index (from 0 to 255)

func (*Ring[K]) Contains

func (r *Ring[K]) Contains(node K) bool

func (*Ring[K]) Get

func (r *Ring[K]) Get(position int) K

func (*Ring[K]) GetNextN

func (r *Ring[K]) GetNextN(position int, n int) []K

GetNextN returns n clockwise nodes starting from position on the ring. does not return error if it cannot find n nodes

func (*Ring[K]) GetUniqueHashes

func (r *Ring[K]) GetUniqueHashes() map[string]K

func (*Ring[K]) GetUniques

func (r *Ring[K]) GetUniques() map[K][]uint32

GetUniques returns all the unique values stored on the ring

func (*Ring[K]) Remove

func (r *Ring[K]) Remove(node K) []int

Remove all positions that are pointing to `node`

Jump to

Keyboard shortcuts

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