From ba9dede646d6b95bc63f7955a1700744d76d0e28 Mon Sep 17 00:00:00 2001 From: Srar Date: Fri, 17 Jul 2020 22:19:30 +0800 Subject: [PATCH] add feature: Get node by pos --- hashring.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hashring.go b/hashring.go index a4921da..6df8cf6 100644 --- a/hashring.go +++ b/hashring.go @@ -144,6 +144,13 @@ func (h *HashRing) GetNode(stringKey string) (node string, ok bool) { return h.ring[h.sortedKeys[pos]], true } +func (h* HashRing) GetNodeWithPos(pos int) (node string, ok bool) { + if pos < 0 || pos >= len(h.sortedKeys) { + return "",false + } + return h.ring[h.sortedKeys[pos]], true +} + func (h *HashRing) GetNodePos(stringKey string) (pos int, ok bool) { if len(h.ring) == 0 { return 0, false