class HashRing::HashRing

Defined in:

hash_ring.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(nodes : Array(String), replicate : Int32 = 512) #

Initializes HashRing nodes is an array of node name and replicate is number of each node in the hash ring array.

HashRing::HashRing.new(["node1", "node2", "node3"])

[View source]

Instance Method Detail

def add(node : String) : Bool #

Appends a node to tail of the hash ring array. Time complexity of this method is O(n log n) because sort the hash ring array whenever call this method.

hash_ring = HashRing::Hashring.new(["node1", "node2", "node3"])
hash_ring.add("node4")

[View source]
def get(node : String) : String #

Returns a node name.

hash_ring = HashRing::Hashring.new(["node1", "node2", "node3"])
hash_ring.get("user1") # => "node3"

[View source]
def remove(node : String) : Bool #

Removes node by a node name from the hash ring array. Time complexity of this method is O(n log n) because sort the hash ring array whenever call this method.

hash_ring = HashRing::Hashring.new(["node1", "node2", "node3"])
hash_ring.remove("node4")

[View source]