{"id":17147842,"url":"https://github.com/lithammer/go-jump-consistent-hash","last_synced_at":"2025-04-06T04:15:05.694Z","repository":{"id":28861268,"uuid":"32385386","full_name":"lithammer/go-jump-consistent-hash","owner":"lithammer","description":":zap: Fast, minimal memory, consistent hash algorithm","archived":false,"fork":false,"pushed_at":"2024-01-01T20:50:09.000Z","size":35,"stargazers_count":226,"open_issues_count":0,"forks_count":18,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T03:07:07.690Z","etag":null,"topics":["algorithm","consistent-hash-algorithm","go","jump-consistent-hash"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/lithammer/go-jump-consistent-hash","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lithammer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"lithammer"}},"created_at":"2015-03-17T09:55:52.000Z","updated_at":"2025-03-28T07:24:57.000Z","dependencies_parsed_at":"2024-01-01T23:43:59.364Z","dependency_job_id":null,"html_url":"https://github.com/lithammer/go-jump-consistent-hash","commit_stats":{"total_commits":34,"total_committers":5,"mean_commits":6.8,"dds":0.4411764705882353,"last_synced_commit":"d024fb72c1e8222311aa7338a990815b7606484c"},"previous_names":["renstrom/go-jump-consistent-hash"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lithammer%2Fgo-jump-consistent-hash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lithammer%2Fgo-jump-consistent-hash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lithammer%2Fgo-jump-consistent-hash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lithammer%2Fgo-jump-consistent-hash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lithammer","download_url":"https://codeload.github.com/lithammer/go-jump-consistent-hash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430963,"owners_count":20937875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","consistent-hash-algorithm","go","jump-consistent-hash"],"created_at":"2024-10-14T21:26:15.528Z","updated_at":"2025-04-06T04:15:05.653Z","avatar_url":"https://github.com/lithammer.png","language":"Go","funding_links":["https://github.com/sponsors/lithammer"],"categories":[],"sub_categories":[],"readme":"# Jump Consistent Hash\n\n[![Build Status](https://github.com/lithammer/go-jump-consistent-hash/workflows/Go/badge.svg)](https://github.com/lithammer/go-jump-consistent-hash/actions)\n[![Godoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/lithammer/go-jump-consistent-hash)\n\nGo implementation of the jump consistent hash algorithm[1] by John Lamping and Eric Veach.\n\n[1] http://arxiv.org/pdf/1406.2294v1.pdf\n\n## Usage\n\n```go\nimport jump \"github.com/lithammer/go-jump-consistent-hash\"\n\nfunc main() {\n    h := jump.Hash(256, 1024)  // h = 520\n}\n```\n\nIncludes 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)](https://en.wikipedia.org/wiki/Cyclic_redundancy_check) is also included for convenience.\n\n```go\nh := jump.HashString(\"127.0.0.1\", 8, jump.NewCRC64())  // h = 7\n```\n\nIn 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`.\n\n```go\nhasher := jump.New(8, jump.NewCRC64())\nh := hasher.Hash(\"127.0.0.1\")  // h = 7\n```\n\nIf 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.\n\nHere's an example of a custom `KeyHasher` that uses Google's [FarmHash](https://github.com/google/farmhash) algorithm (the successor of CityHash) to compute the final key.\n\n```go\ntype FarmHash struct {\n    buf bytes.Buffer\n}\n\nfunc (f *FarmHash) Write(p []byte) (n int, err error) {\n    return f.buf.Write(p)\n}\n\nfunc (f *FarmHash) Reset() {\n    f.buf.Reset()\n}\n\nfunc (f *FarmHash) Sum64() uint64 {\n    // https://github.com/dgryski/go-farm\n    return farm.Hash64(f.buf.Bytes())\n}\n\nhasher := jump.New(8, \u0026FarmHash{})\nh := hasher.Hash(\"127.0.0.1\")  // h = 5\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flithammer%2Fgo-jump-consistent-hash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flithammer%2Fgo-jump-consistent-hash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flithammer%2Fgo-jump-consistent-hash/lists"}