File: //opt/alt/python37/lib/python3.7/site-packages/uhashring/__pycache__/ring.cpython-37.pyc
B
��f�+ � @ 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� |� dd�}|� dd�}|� dd�}|dkrXdd� |�� D �}|dkrJd}tf |�| _n|dkrdd }t|�| _|| _| jj| _|r�t|d
�s�td��|| _ | �
|�r�| j�| jj�� � 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 | ]\}}|d kr||�qS ))Zreplicas� )�.0�k�vr r �?/opt/alt/python37/lib/python3.7/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 s8 t |t�r|g}n t |ttf�s2td�t|����d}x�|D ]�}|d|d| jdd�}| jj �
|i �}|}|spd}t |t�r�|| }t |t�r�||d<