benbjohnson / benbjohnson/jmphash

What makes it different?

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
153
Forks
5
PR merge metrics
No merged PRs in 30d

Description

these both snippets almost always return the same results:

A
```go
...
func jhTest(buckets int, key uint64) {
// Create a hash with 100 buckets.
h := jmphash.NewHasher(buckets)

// Map keys to their appropriate buckets.
count := make(map[int]int)
for key = 1; key <= 97; key++ {
bucket := h.Hash(key)
if _, ok := count[bucket]; ok {
count[bucket]++
} else {
count[bucket] = 1
}
}
fmt.Println("buckets[bucket_id][keys]: ", count)

}...
```

B
```go
...
func modHash(buckets, key int) {
count := make(map[int]int)
var h int
for key = 1; key <= 97; key++ {
h = key
bucket := h % buckets
if _, ok := count[bucket]; ok {
count[bucket]++
} else {
count[bucket] = 1
}
}
fmt.Println("buckets[bucket_id][keys]: ", count)
}
...
```
main.go
```go
func main(){
jhTest(2, 97)
jhTest(3, 97)

modHash(2, 97)
modHash(3, 97)
}
```
results:
A: buckets[bucket_id][keys]: map[0:49 1:48]
A: buckets[bucket_id][keys]: map[0:34 1:32 2:31]
B: buckets[bucket_id][keys]: map[0:48 1:49]
B: buckets[bucket_id][keys]: map[0:32 1:33 2:32]

Why should I use jump consistent hashing if it can be achieved the same result wit modular operation ?
Am I missing a core concept of jump consistent hashing ?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Go snippets and the main.go example, then inspect the repository documentation for how jmphash is intended to be used. Compare the bucket-count results with the stated hashing goals and explain the distinction between jump consistent hashing and modulo hashing, including when the library should be preferred.】【。

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.