def draw_ring(ring: ConsistentHashRing, dist: Dict[str, int], title: str):
node_ids = sorted(ring.nodes.keys())
plt.figure(figsize=(8, 8))
ax = plt.gca()
ax.set_title(title)
if not node_ids:
plt.text(0.5, 0.5, "Ring is empty", ha="center", va="center")
plt.axis("off")
plt.show()
return
G = nx.Graph()
for nid in node_ids:
G.add_node(nid)
for i in range(len(node_ids)):
G.add_edge(node_ids[i], node_ids[(i + 1) % len(node_ids)])
pos = nx.circular_layout(G)
vnode_counts = ring.snapshot()
labels = {
nid: f"{nid}\nkeys={dist.get(nid,0)}\nvnodes={vnode_counts.get(nid,0)}"
for nid in node_ids
}
nx.draw_networkx_edges(G, pos, alpha=0.4, width=2)
nx.draw_networkx_nodes(G, pos, node_size=2200)
nx.draw_networkx_labels(G, pos, labels=labels, font_size=9)
plt.axis("off")
plt.show()
Thursday, February 26
Trending
- Medical Educating Establishment MTI Peshawar Job 2026 2026 Job Commercial Pakistan
- Vassell leads Spurs past Raptors 110-107
- Hiba Bukhari breaks silence on her viral PTV clip
- Pakistan ladies register their highest-ever ODI whole
- US cybersecurity company CISA reportedly in dire form amid Trump cuts and layoffs
- BOI hyperlinks export push to finish of subsidies
- Who’s up for induction in ‘Rock & Roll Corridor of Fame’ in 2026?
- Ethereum Roadmap Targets 2-Second Blocks and Quantum Security
- Indie Co-Op Games That Are Actually Better Than AAA Blockbusters
- Meezan Bank Vacancies in Karachi February 2026 Advertisement
