hash

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

* @Author: cnzf1 * @Date: 2023-01-10 16:21:18 * @LastEditors: cnzf1 * @LastEditTime: 2023-01-10 16:21:46 * @Description:

* @Author: cnzf1 * @Date: 2021-07-21 15:52:04 * @Descripttion:

Index

Constants

View Source
const (
	// TopWeight is the top weight that one entry might set.
	TopWeight = 100
)

Variables

This section is empty.

Functions

func Hash

func Hash(data []byte) uint64

Hash returns the hash value of data.

func MD5

func MD5(input []byte) []byte

MD5

func SHA1

func SHA1(input []byte) []byte

SHA1

func SHA256

func SHA256(input []byte) []byte

SHA256

func SHA512

func SHA512(input []byte) []byte

SHA512

Types

type ConsistentHash

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

A ConsistentHash is a ring hash implementation.

func NewConsistentHash

func NewConsistentHash() *ConsistentHash

NewConsistentHash returns a ConsistentHash.

func NewCustomConsistentHash

func NewCustomConsistentHash(replicas int, fn Func) *ConsistentHash

NewCustomConsistentHash returns a ConsistentHash with given replicas and hash func.

func (*ConsistentHash) Add

func (h *ConsistentHash) Add(node interface{})

Add adds the node with the number of h.replicas, the later call will overwrite the replicas of the former calls.

func (*ConsistentHash) AddWithReplicas

func (h *ConsistentHash) AddWithReplicas(node interface{}, replicas int)

AddWithReplicas adds the node with the number of replicas, replicas will be truncated to h.replicas if it's larger than h.replicas, the later call will overwrite the replicas of the former calls.

func (*ConsistentHash) AddWithWeight

func (h *ConsistentHash) AddWithWeight(node interface{}, weight int)

AddWithWeight adds the node with weight, the weight can be 1 to 100, indicates the percent, the later call will overwrite the replicas of the former calls.

func (*ConsistentHash) Get

func (h *ConsistentHash) Get(v interface{}) (interface{}, bool)

Get returns the corresponding node from h base on the given v.

func (*ConsistentHash) Remove

func (h *ConsistentHash) Remove(node interface{})

Remove removes the given node from h.

type Func

type Func func(data []byte) uint64

Func defines the hash method.

Jump to

Keyboard shortcuts

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