pch

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 6 Imported by: 0

README

pch

MIT License GoDoc Go Report Card Releases

Go implementation of Power Consistent Hashing algorithm.

Installation

go get github.com/octu0/pch

Example

import (
    "hash/fnv"

    "github.com/octu0/pch"
)

func main() {
    p := pch.New(512, fnv.New64()) // 512 buckets, hash function fnv.New64()
    p.Hash("hello world")
}

Benchmark

$ go test -bench=Benchmark .
goos: linux
goarch: amd64
pkg: github.com/octu0/pch
cpu: Intel(R) Xeon(R) W-11955M CPU @ 2.60GHz
Benchmark/jump/512-16           15240927                76.51 ns/op
Benchmark/jump/1024-16          14898984                79.36 ns/op
Benchmark/jump/2048-16          14624468                81.27 ns/op
Benchmark/jump/4096-16          14171553                84.87 ns/op
Benchmark/jump/8192-16          13739763                86.91 ns/op
Benchmark/power/512-16           9934183               117.4 ns/op
Benchmark/power/1024-16         10374721               119.1 ns/op
Benchmark/power/2048-16         10252898               117.2 ns/op
Benchmark/power/4096-16         10489959               118.0 ns/op
Benchmark/power/8192-16         10361293               117.0 ns/op
PASS

License

MIT, see LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FNV1  hash.Hash64 = fnv.New64()
	FNV1a hash.Hash64 = fnv.New64a()
)

Functions

This section is empty.

Types

type PowerConsistentHash

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

func New

func New(n uint32, hasher hash.Hash64) *PowerConsistentHash

func (*PowerConsistentHash) Hash

func (p *PowerConsistentHash) Hash(key string) uint32

Jump to

Keyboard shortcuts

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