jumphash

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package jumphash provides a jump consistent hash implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(key uint64, buckets int) int

Hash takes a key and the number of buckets, returns an integer in the range [0, buckets). If the number of buckets is not greater than 1 then 1 is used.

func HashString

func HashString(key string, buckets int) int

HashString takes string as key instead of integer and uses CRC-64 to generate key.

Types

type Hasher

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

Hasher represents a jump consistent Hasher using a string as key.

func New

func New(n int) *Hasher

New returns a new instance of of Hasher.

func (*Hasher) Hash

func (h *Hasher) Hash(key string) int

Hash returns the integer hash for the given key.

func (*Hasher) N

func (h *Hasher) N() int

N returns the number of buckets the hasher can assign to.

Jump to

Keyboard shortcuts

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