• Stars
    star
    214
  • Rank 178,496 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚡ Fast, minimal memory, consistent hash algorithm

Jump Consistent Hash

Build Status Godoc

Go implementation of the jump consistent hash algorithm[1] by John Lamping and Eric Veach.

[1] http://arxiv.org/pdf/1406.2294v1.pdf

Usage

import jump "github.com/lithammer/go-jump-consistent-hash"

func main() {
    h := jump.Hash(256, 1024)  // h = 520
}

Includes a helper function for using a string as key instead of an uint64. This requires a hasher that computes the string into a format accepted by Hash(). Such a hasher that uses CRC-64 (ECMA) is also included for convenience.

h := jump.HashString("127.0.0.1", 8, jump.NewCRC64())  // h = 7

In reality though you probably want to use a Hasher so you won't have to repeat the bucket size and which key hasher used. It also uses more convenient types, like int instead of int32.

hasher := jump.New(8, jump.NewCRC64())
h := hasher.Hash("127.0.0.1")  // h = 7

If you want to use your own algorithm, you must implement the KeyHasher interface, which is a subset of the hash.Hash64 interface available in the standard library.

Here's an example of a custom KeyHasher that uses Google's FarmHash algorithm (the successor of CityHash) to compute the final key.

type FarmHash struct {
    buf bytes.Buffer
}

func (f *FarmHash) Write(p []byte) (n int, err error) {
    return f.buf.Write(p)
}

func (f *FarmHash) Reset() {
    f.buf.Reset()
}

func (f *FarmHash) Sum64() uint64 {
    // https://github.com/dgryski/go-farm
    return farm.Hash64(f.buf.Bytes())
}

hasher := jump.New(8, &FarmHash{})
h := hasher.Hash("127.0.0.1")  // h = 5

License

MIT

More Repositories

1

shortuuid

🍄 A generator library for concise, unambiguous and URL-safe UUIDs
Go
1,084
star
2

fuzzysearch

🐷 Tiny and fast fuzzy search in Go
Go
979
star
3

go-wiki

A simple HTTP server rendering Markdown styled documents
Go
300
star
4

NeavUI

Development branch of Neav UI
Lua
96
star
5

dedent

Remove any common leading whitespace from multiline strings
Go
89
star
6

python-jump-consistent-hash

Fast, minimal memory, consistent hash algorithm
Python
37
star
7

passbook_flask_example

An example Implementation of a Passbook Webservice in Flask, based on mattt's passbook_rails_example
Python
19
star
8

homebrew-deadsnakes

Homebrew tap with old and new Python versions for macOS
Ruby
12
star
9

nvim-diagnosticls

diagnostic-languageserver configuration for Neovim's language server client
Lua
10
star
10

vim-eighties

A simplified and optimized base16-eighties color scheme for Vim
Vim Script
10
star
11

webassets-browserify

Browserify filter for webassets
Python
5
star
12

dotfiles

config files etc.
Shell
4
star
13

prInformation

A lightweight WoW addon for showing various information (fps, gold, friends online etc.)
Lua
2
star
14

advent_of_code_2022

Advent of Code 2022
Rust
2
star
15

imdb-api

Very basic IMDb scraper written for Flask and Heroku
HTML
1
star
16

nvim-pylance

Add Pylance support to nvim-lspconfig
Lua
1
star
17

prButler

Making your life simpler in World of Warcraft
Lua
1
star
18

nSpellTracker

Simple buff, debuff and cooldown tracking based on rFilter3 by Zork
Lua
1
star
19

nFilger

Buff, debuff and cooldown tracker for Neav UI, based on Filger by Nils Ruesch
Lua
1
star
20

prExecute

Plays a notification sound ("Quad damage!" from Quake) when entering execution range for all classes/specs, also plays a tick sound for Drain Soul
Lua
1
star
21

webassets

A webservice to compile and compress various web assets
JavaScript
1
star