Complete the code to define the hash ring size in consistent hashing.
hash_ring_size = 2[1]32
Consistent hashing uses a hash ring, often sized as 2 to the power of 32 for a 32-bit hash space.
Complete the code to find the next node clockwise on the hash ring.
next_node = sorted_nodes[bisect.bisect_right(sorted_nodes, key_hash) [1] len(sorted_nodes)]
Modulo '%' is used to wrap around the ring when the key's hash is beyond the last node.
Fix the error in the code to correctly add virtual nodes to the hash ring.
for i in range(num_virtual_nodes): virtual_node_key = f"{node}-VN[1]" hash_value = hash_function(virtual_node_key) hash_ring[hash_value] = node
The loop index 'i' is used to create unique virtual node keys by appending it to the node name.
Fill both blanks to complete the code that finds the responsible node for a given key.
key_hash = hash_function(key) index = bisect.bisect_right(sorted_hashes, key_hash) [1] len(sorted_hashes) responsible_node = hash_ring[sorted_hashes[index [2]]]
The modulo operator '%' wraps the index around the ring, and '-' subtracts 1 to get the correct index in the list.
Fill both blanks to complete the code that reassigns keys when a node is removed.
for key in keys_to_reassign: key_hash = hash_function(key) new_index = bisect.bisect_right(sorted_hashes, key_hash) [1] len(sorted_hashes) new_node = hash_ring[sorted_hashes[new_index [2]]] key_node_map[key] = new_node
Modulo '%' wraps the index, '-' adjusts the index to the correct node, and no extra operator is needed after assignment.