wrh

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: BSD-3-Clause Imports: 2 Imported by: 1

README

wrh

GoDoc

Package wrh is implementation of weighted rendezvous hash algorithm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindByMaxScore

func FindByMaxScore(nodes Nodes) int

FindByMaxScore finds a node which has maximum score and returns its index. If nodes has no node, it returns -1.

func FindBySeed

func FindBySeed(nodes Nodes, seed uint32) int

FindBySeed finds a node by seed and returns its index. If seed is not exists, it returns -1.

func ResponsibleNodes

func ResponsibleNodes(nodes Nodes, key []byte, respNodes Nodes)

ResponsibleNodes calculates all scores from nodes and puts responsible nodes into respNodes.

Types

type Node

type Node struct {
	Seed   uint32
	Weight float64
	Data   interface{}
	// contains filtered or unexported fields
}

Node is a container of Seed, Weight, Data to find responsible nodes. Data is a custom data to use free.

func (*Node) Score

func (nd *Node) Score(key []byte) float64

Score calculates score by given key.

type Nodes

type Nodes []Node

Nodes is a Node slice and it implements sort.Interface to use sort package.

func MergeNodes

func MergeNodes(nodes1, nodes2 Nodes, mergedNodesIn Nodes) (mergedNodes Nodes)

MergeNodes merges nodes1 and nodes2, appends mergedNodesIn, returns mergedNodes which has all merged nodes. mergedNodesIn can be nil.

func ResponsibleNodes2

func ResponsibleNodes2(nodes Nodes, key []byte, count int) Nodes

ResponsibleNodes2 calculates all scores from nodes and returns responsible nodes.

func (Nodes) Len

func (n Nodes) Len() int

func (Nodes) Less

func (n Nodes) Less(i, j int) bool

func (Nodes) Swap

func (n Nodes) Swap(i, j int)

Jump to

Keyboard shortcuts

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