class HashRing::HashRing
- HashRing::HashRing
- Reference
- Object
Defined in:
hash_ring.crConstructors
-
.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.
Instance Method Summary
-
#add(node : String) : Bool
Appends a node to tail of the hash ring array.
-
#get(node : String) : String
Returns a node name.
-
#remove(node : String) : Bool
Removes node by a node name from the hash ring array.
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"])
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")
def get(node : String) : String
#
Returns a node name.
hash_ring = HashRing::Hashring.new(["node1", "node2", "node3"])
hash_ring.get("user1") # => "node3"
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")