File: default.go

package info (click to toggle)
golang-github-codesenberg-concurrent 0.0~git20180531.64560cf-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 192 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 586 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package histogram

func hashString(s string) uint32 {
	// fnv32 hash
	const prime32 = 16777619
	hash := uint32(2166136261)
	for _, c := range []byte(s) {
		hash *= prime32
		hash ^= uint32(c)
	}
	return hash
}

// WithDefaultHash creates histogram with specified shardCount and
// reasonable sharding function.
func WithDefaultHash(shardsCount uint32) (*Histogram, error) {
	return New(shardsCount, hashString)
}

// Default creates histogram with reasonable defaults.
func Default() *Histogram {
	// We can safely ignore the error in this case
	h, _ := WithDefaultHash(32)
	return h
}