Z60

Consistent Hashing Ring Simulation

Staff / Principal Engineer
Target Time: 40 - 50 Minutes
Type: ARRAY

Problem Statement & Objective

Simulate a distributed consistent hashing ring with virtual nodes (vnodes) supporting dynamic node additions, removals, and key lookup routing.

Function Signature (Python)

consistent_hashing_ring_simulation(num_virtual_nodes: int, operations: list) -> list

Input & Output Contract

Output Rule:İşlem sonuçları listesi (None veya string).

System Constraints

1 <= sanal_dugum_sayisi <= 20
1 <= islemler.length <= 1000
Sunucu ve anahtar isimleri alfanümeriktir

Example Execution Walkthrough

sanal_dugum_sayisi = 3, islemler = [['add_node', 'ServerA'], ['add_node', 'ServerB'], ['get_node', 'user123'], ['remove_node', 'ServerA'], ['get_node', 'user123']]
ServerA ve ServerB eklenir.
user123 sunuculardan birine atanır.
ServerA silinince user123 zorunlu olarak ServerB'ye atanır.
Cevap: [None, None, 'ServerB', None, 'ServerB'] (örnek simülasyon)

Example Test Scenarios (3)

Example 1: Sunucu Silme ve Yönlendirme
Input:[3,[["add_node","A"],["add_node","B"],["get_node","k1"],["remove_node","A"],["get_node","k1"]]]
Expected Output:[null,null,"A",null,"B"]
Example 2: Boş Halka
Input:[2,[["get_node","empty"]]]
Expected Output:[null]
Example 3: Tek Sunucu
Input:[1,[["add_node","SingleServer"],["get_node","any_key"]]]
Expected Output:[null,"SingleServer"]
Loading Python Editor...
Input Parameters
[
  3,
  [
    [
      "add_node",
      "A"
    ],
    [
      "add_node",
      "B"
    ],
    [
      "get_node",
      "k1"
    ],
    [
      "remove_node",
      "A"
    ],
    [
      "get_node",
      "k1"
    ]
  ]
]
Expected Output
[
  null,
  null,
  "A",
  null,
  "B"
]