HardPro challengePythonJavaScriptTypeScript

Consistent Hashing Ring

Node.jsDistributedHashing

Place each node at hash(node) on a circular ring (mod 2^32). Each key
maps to the first node clockwise from hash(key).

Use FNV-1a 32-bit. solve(nodes, keys) returns array of assigned node names.

Sample tests

Test #1Single node
Input: [["n1"],["x","y"]]
Output: ["n1","n1"]
Test #2Self-keys (deterministic)
Input: [["a","b","c"],["a","b","c"]]
Output: ["a","b","c"]
Test #3No keys
Input: [["n1","n2"],[]]
Output: []
Test #4All map to single node
Input: [["a"],["k1","k2","k3"]]
Output: ["a","a","a"]
Test #5Key assigned to clockwise node
Input: [["x","y"],["k"]]
Output: ["y"]