From 4d62f01af159fddd56585b3dce19b8a0f47369c1 Mon Sep 17 00:00:00 2001 From: SangTran-127 Date: Sun, 9 Aug 2026 01:11:31 +0700 Subject: feat: implement memory state backend with key group assignment and value state interface --- core/hash.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 core/hash.go (limited to 'core/hash.go') 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)) +} -- cgit v1.2.3