File: //opt/alt/python37/lib/python3.7/site-packages/uhashring/__pycache__/ring_meta.cpython-37.pyc
B
��f� � @ s* d dl mZ d dlmZ G dd� d�ZdS )� )�Counter)�md5c @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
S )�MetaRingz,Implement a tunable consistent hashing ring.c C sB t � | _g | _i | _i | _|r0t|d�s0td��|p:dd� | _dS )zaCreate a new HashRing.
:param hash_fn: use this callable function to hash keys.
�__call__z%hash_fn should be a callable functionc S s t tt| ��d���� d�S )Nzutf-8� )�intr �str�encode� hexdigest)�key� r �D/opt/alt/python37/lib/python3.7/site-packages/uhashring/ring_meta.py�<lambda> � z#MetaRing.__init__.<locals>.<lambda>N)r �
_distribution�_keys�_nodes�_ring�hasattr� TypeError�_hash_fn)�selfZhash_fnr r r
�__init__ s zMetaRing.__init__c C s
| � |�S )z>Returns an integer derived from the md5 hash of the given key.)r )r r r r r
�hashi s zMetaRing.hashic C sr x\|D ]T\}}xJt d|d |d �D ]0}| j| d7 <