hash

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyCircle = errors.New("empty circle")

ErrEmptyCircle is the error returned when trying to get an element when nothing has been added to hash.

View Source
var (
	Name = "consistent_hash"
)

Functions

func FromContext

func FromContext(ctx context.Context) (string, bool)

FromContext returns the hashkey in ctx if it exists.

func NewContext

func NewContext(ctx context.Context, key string) context.Context

NewContext creates a new context with hashkey.

Types

type Consistent

type Consistent struct {
	NumberOfReplicas int

	UseFnv bool
	// contains filtered or unexported fields
}

Consistent holds the information about the members of the consistent hash circle.

func NewHash

func NewHash() *Consistent

NewHash creates a new Consistent object with a default setting of 50 replicas for each entry.

To change the number of replicas, set NumberOfReplicas before adding entries.

func (*Consistent) Add

func (c *Consistent) Add(elt Node)

Add inserts a string element in the consistent hash.

func (*Consistent) Get

func (c *Consistent) Get(name string) (string, error)

Get returns an element close to where name hashes to in the circle.

func (*Consistent) GetN

func (c *Consistent) GetN(name string, n int) ([]string, error)

GetN returns the N closest distinct elements to the name input in the circle.

func (*Consistent) GetTwo

func (c *Consistent) GetTwo(name string) (string, string, error)

GetTwo returns the two closest distinct elements to the name input in the circle.

func (*Consistent) Index

func (c *Consistent) Index(etl string) int

func (*Consistent) Members

func (c *Consistent) Members() []string

func (*Consistent) Remove

func (c *Consistent) Remove(elt Node)

Remove removes an element from the hash.

func (*Consistent) Set

func (c *Consistent) Set(elts []Node)

Set sets all the elements in the hash. If there are existing elements not present in elts, they will be removed.

type Node

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

type Picker

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

func New

func New() *Picker

func (*Picker) Pick

func (p *Picker) Pick(ctx context.Context, nodes []naming.Instance) (node *naming.Instance, done func(balancer.DoneInfo))

func (*Picker) Schema

func (p *Picker) Schema() string

Jump to

Keyboard shortcuts

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