diff options
| author | sangtran <tranquangsang12.7@gmail.com> | 2026-08-29 01:08:28 +0700 |
|---|---|---|
| committer | sangtran <tranquangsang12.7@gmail.com> | 2026-08-29 01:08:28 +0700 |
| commit | 96c07bab1086510a55a004e9a1b90c30bc723a5c (patch) | |
| tree | 7abbc615c51667e111fdef7b2ef69a9fc663f2ca /core/hash.go | |
| signature | Verified sangtran <tranquangsang12.7@gmail.com> Key: 8DD79823D235E1BB ultimate trust | |
| download | flux-96c07bab1086510a55a004e9a1b90c30bc723a5c.tar.gz flux-96c07bab1086510a55a004e9a1b90c30bc723a5c.zip | |
Verified feat: init base draft support window
Diffstat (limited to 'core/hash.go')
| -rw-r--r-- | core/hash.go | 19 |
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 @@ | |||
| 1 | package core | ||
| 2 | |||
| 3 | import "hash/fnv" | ||
| 4 | |||
| 5 | const DefaultMaxParallelism = 128 | ||
| 6 | |||
| 7 | func AssignToKeyGroup(key string, maxParallelism int) int { | ||
| 8 | |||
| 9 | if maxParallelism <= 0 { | ||
| 10 | maxParallelism = DefaultMaxParallelism | ||
| 11 | } | ||
| 12 | |||
| 13 | // hash | ||
| 14 | h := fnv.New32a() | ||
| 15 | h.Write([]byte(key)) | ||
| 16 | hash := h.Sum32() | ||
| 17 | |||
| 18 | return int(hash % uint32(maxParallelism)) | ||
| 19 | } | ||
