File: //usr/local/lib/python3.6/site-packages/uhashring/__pycache__/ring_meta.cpython-36.pyc
3
U�` � @ 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 sD t � | _g | _i | _i | _|r2t|d� r2td��|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| �jd��j� d�S )Nzutf-8� )�intr �str�encode� hexdigest)�key� r �=/usr/local/lib/python3.6/site-packages/uhashring/ring_meta.py�<lambda> s 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
| j |�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 <