Last active
December 16, 2015 21:59
-
-
Save alexmoore/5504173 to your computer and use it in GitHub Desktop.
Little helper class to figure out on which vnodes a particular hash resides.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VNodeHelper | |
attr_reader :ring_size, :n_val | |
def initialize(ring_size, n_val) | |
@ring_size = ring_size | |
@n_val = n_val | |
@vnode_size = (2 ** 160 / @ring_size) | |
end | |
def get_vnode_addresses(hash) | |
home_vnode = get_home_vnode_index(hash) | |
(0...@n_val).map { |i| ((home_vnode + i) * @vnode_size) % 2 ** 160 } | |
end | |
def get_home_vnode_index(hash) | |
(hash / @vnode_size) + 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment