Skip to content

Instantly share code, notes, and snippets.

@orrchen
orrchen / buckets.go
Last active February 7, 2017 10:37
Distribute strings uniformly between buckets with murmur3 hash algorithm implementation. Inspired by http://stats.stackexchange.com/questions/26344/how-to-uniformly-project-a-hash-to-a-fixed-number-of-buckets
import (
"github.com/spaolacci/murmur3"
"math"
)
/**
Places a string in a bucket in a uniform distribution where B is the number of bucket using Murmur hashing function for 64 bit
**/
func PlaceInUniformBucket(str string, B int) (int, error) {
h64 := murmur3.New64()
_, err := h64.Write([]byte(str))
@orrchen
orrchen / elastic.v3_issue_241_test_case.go
Last active March 7, 2016 22:12
Test case for issue number 241 in github.com/olivere/elastic : https://github.com/olivere/elastic/issues/241
package main
import (
"gopkg.in/olivere/elastic.v3"
"log"
"os"
"time"
"math"
)
type Obj struct {