File: //usr/local/lib/python3.6/site-packages/uhashring/__pycache__/ring.cpython-36.pyc
3
��x`�+ � @ s6 d dl m Z d dlmZ d dlmZ G dd� d�ZdS )� )�bisect)�
KetamaRing)�MetaRingc @ s8 e Zd ZdZg fdd�Zdd� Zdd� ZeZdd � ZeZ d
difdd
�Z
e
Zdd� Zdd� Z
dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zd d!� Zd"d#� Zd$d%� Zd&d'� Zd@d)d*�Zd+d,� ZdAd.d/�Zd0d1� Zed2d3� �ZeZed4d5� �Z ed6d7� �Z!e!Z"ed8d9� �Z#ed:d;� �Z$ed<d=� �Z%ed>d?� �Z&d-S )B�HashRingz$Implement a consistent hashing ring.c K s� |j dd�}|j dd�}|j dd�}|dkrXdd� |j� D �}|dkrJd}tf |�| _n|dkrdd }t|�| _|| _| jj| _|r�t|d
� r�td��|| _ | j
|�r�| jj| jjj� � dS )a� 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_fnN�vnodes� weight_fnZketamac S s i | ]\}}|dkr||�qS )�replicas)r � )�.0�k�vr
r
�8/usr/local/lib/python3.6/site-packages/uhashring/ring.py�
<dictcomp> s z%HashRing.__init__.<locals>.<dictcomp>�( � �__call__z'weight_fn should be a callable function)
�get�itemsr �runtimer �_default_vnodes�hashi�hasattr� TypeError�
_weight_fn�_configure_nodes�_create_ring�_nodes)�self�nodes�kwargsr r r Zketama_argsr
r
r �__init__
s$
zHashRing.__init__c
C s< t |t�r|g}n t |ttf�s2tdjt|����d}� x�|D ]�}|d|d| jdd�}| jj j
|i �}|}|srd}t |t�� r�|| }t |t�r�||d<