jmphash

package module
v0.0.0-...-2d58f23 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2014 License: MIT Imports: 0 Imported by: 1

README

jmphash

Implementation of the Jump Consistent Hash algorithm in Go. This algorithm performs consistent hashing on integer keys and maps them to integer buckets.

Usage

To use jmphash, simply create a Hasher with the number of buckets you want to map to and then call the Hash() function with your key. This function will return the bucket that your key is mapped to.

import "github.com/benbjohnson/jmphash"

func main() {
	// Create a hash with 100 buckets.
	h := jmphash.NewHasher(100)

	// Map keys to their appropriate buckets.
	bucket := h.Hash(12387)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hasher

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

Hasher represents a Jump Consistent Hasher.

func NewHasher

func NewHasher(n int) *Hasher

NewHasher returns a new instance of Hasher. If the number of of buckets is less than or equal to zero then one bucket is used.

func (*Hasher) Hash

func (h *Hasher) Hash(key uint64) 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