chash1

package
v0.0.0-...-3cfa233 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_REPLICAS = 10000

Variables

This section is empty.

Functions

func GetRandom

func GetRandom() string

产生一个随机字符串

Types

type Consistent

type Consistent struct {
	Nodes map[uint32]Node

	Resources map[int]bool

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewConsistent

func NewConsistent() *Consistent

func (*Consistent) Add

func (c *Consistent) Add(node *Node) bool

func (*Consistent) Get

func (c *Consistent) Get(key string) Node

数据分配,根据key计算出的hash值确定 这个key由哪个节点承载

func (*Consistent) Remove

func (c *Consistent) Remove(node *Node)

type HashRing

type HashRing []uint32

func (HashRing) Len

func (c HashRing) Len() int

func (HashRing) Less

func (c HashRing) Less(i, j int) bool

func (HashRing) Swap

func (c HashRing) Swap(i, j int)

type Node

type Node struct {
	Id        int
	Randomstr string
	// Ip       string
	// Port     int
	// HostName string
	Weight int
}

func NewNode

func NewNode(id int, rstr string, weight int) *Node

NewNode 节点信息,IP地址 还有一个权重值

Jump to

Keyboard shortcuts

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