Build a consistent hash ring:
h(s) = int(hashlib.md5(s.encode()).hexdigest()[:8], 16).vnodes points at h(f"{node}#{i}") for i in 0..vnodes-1.Assign every key, then remove the node remove and assign again. Return
{"assignment": {key: node}, "counts": {node: n}, "moved": n} where assignment/counts describe the
ring before removal, and moved is how many keys changed node.
Implement hash_ring. Input: nodes: list[str], vnodes: int, keys: list[str], remove: str. Returns: dict.
import hashlib
def hash_ring(nodes, vnodes, keys, remove):
assignment = {k: nodes[hash(k) % len(nodes)] for k in keys}
return {"assignment": assignment, "counts": {}, "moved": 0}
Run executes the public tests. Submit grades against public and hidden tests.
Build a consistent hash ring:
h(s) = int(hashlib.md5(s.encode()).hexdigest()[:8], 16).vnodes points at h(f"{node}#{i}") for i in 0..vnodes-1.Assign every key, then remove the node remove and assign again. Return
{"assignment": {key: node}, "counts": {node: n}, "moved": n} where assignment/counts describe the
ring before removal, and moved is how many keys changed node.
Implement hash_ring. Input: nodes: list[str], vnodes: int, keys: list[str], remove: str. Returns: dict.
import hashlib
def hash_ring(nodes, vnodes, keys, remove):
assignment = {k: nodes[hash(k) % len(nodes)] for k in keys}
return {"assignment": assignment, "counts": {}, "moved": 0}
Run executes the public tests. Submit grades against public and hidden tests.