class_docstr: Implement a consistent hashing ring.
class_docstr_tok: ["Implement","a","consistent","hashing","ring","."]
docstr: Create a new HashRing given the implementation.
  
  :param nodes: nodes used to create the continuum (see doc for format).
  :param hash_fn: use this callable function to hash keys, can be set to
                  'ketama' to use the ketama compatible implementation.
  :param vnodes: default number of vnodes per node.
  :param weight_fn: use this function to calculate the node's weight.
docstr_tok: ["Create","a","new","HashRing","given","the","implementation",".",":","param","nodes",":","nodes","used","to","create","the","continuum","(","see","doc","for","format",")",".",":","param","hash_fn",":","use","this","callable","function","to","hash","keys",",","can","be","set","to","'ketama","'","to","use","the","ketama","compatible","implementation",".",":","param","vnodes",":","default","number","of","vnodes","per","node",".",":","param","weight_fn",":","use","this","function","to","calculate","the","node","'s","weight","."]
code: def __init__(self, nodes=[], **kwargs):
      """Create a new HashRing given the implementation.
  
      :param nodes: nodes used to create the continuum (see doc for format).
      :param hash_fn: use this callable function to hash keys, can be set to
                      'ketama' to use the ketama compatible implementation.
      :param vnodes: default number of vnodes per node.
      :param weight_fn: use this function to calculate the node's weight.
      """
      hash_fn = kwargs.get("hash_fn", None)
      vnodes = kwargs.get("vnodes", None)
      weight_fn = kwargs.get("weight_fn", None)
  
      if hash_fn == "ketama":
          if vnodes is None:
              vnodes = 40
          self.runtime = KetamaRing()
      else:
          if vnodes is None:
              vnodes = 160
          self.runtime = MetaRing(hash_fn)
  
      self._default_vnodes = vnodes
      self.hashi = self.runtime.hashi
  
      if weight_fn and not hasattr(weight_fn, "__call__"):
          raise TypeError("weight_fn should be a callable function")
      self._weight_fn = weight_fn
  
      if self._configure_nodes(nodes):
          self.runtime._create_ring(self.runtime._nodes.items())
  
imports: from bisect import bisect
  from .ring_ketama import KetamaRing
  from .ring_meta import MetaRing
label_desc: Use image node_id 1 to create a new HashRing object from inherited base classes: object with example: obj = HashRing(nodes)