Skip to content

Instantly share code, notes, and snippets.

@alexmoore
Last active Dec 16, 2015
Embed
What would you like to do?
Little helper class to figure out on which vnodes a particular hash resides.
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