aboutsummaryrefslogtreecommitdiff
path: root/core/hash.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/hash.go')
-rw-r--r--core/hash.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/core/hash.go b/core/hash.go
new file mode 100644
index 0000000..af15546
--- /dev/null
+++ b/core/hash.go
@@ -0,0 +1,19 @@
+package core
+
+import "hash/fnv"
+
+const DefaultMaxParallelism = 128
+
+func AssignToKeyGroup(key string, maxParallelism int) int {
+
+ if maxParallelism <= 0 {
+ maxParallelism = DefaultMaxParallelism
+ }
+
+ // hash
+ h := fnv.New32a()
+ h.Write([]byte(key))
+ hash := h.Sum32()
+
+ return int(hash % uint32(maxParallelism))
+}