Consistent hashing ring

Write codeHard35 minAmazon style

Your task

Build a consistent-hashing ring used to assign keys to storage nodes. The ring has 2^16 = 65536 slots. Each physical node is placed at vnodes virtual positions computed deterministically as h(node_id, i) = (i * 2654435761 + sum(ord(c) for c in node_id) * 40503) % 65536 for i in 0..vnodes-1. A key hashes to position k(key) = (sum(ord(c) for c in key) * 2654435761) % 65536. A key is owned by the first node position at or clockwise after k(key) (wrapping around). Process operations: ["add", node_id], ["remove", node_id], and ["owner", key]. Return the list of owner results (the owning node_id, or empty string "" if the ring has no nodes), in order. If two virtual nodes land on the same slot, the one added earlier wins that slot.

Examples

consistent_hash_ring(vnodes: int, ops: list[list]) -> list[str]
Example 1
Inputconsistent_hash_ring(1, [["add", "alpha"], ["add", "beta"], ["owner", "x"], ["owner", "y"]])
Output["alpha", "beta"]