HEX
Server: LiteSpeed
System: Linux srv146.niagahoster.com 4.18.0-553.30.1.lve.el8.x86_64 #1 SMP Tue Dec 3 01:21:19 UTC 2024 x86_64
User: kodi1989 (1633)
PHP: 8.1.34
Disabled: symlink,shell_exec,exec,popen,system,dl,passthru,escapeshellarg,escapeshellcmd,show_source,pcntl_exec
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/uhashring/__pycache__/ring_meta.cpython-37.pyc
B

��f��@s*ddlmZddlmZGdd�d�ZdS)�)�Counter)�md5c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�MetaRingz,Implement a tunable consistent hashing ring.cCsBt�|_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 functioncSsttt|��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__szMetaRing.__init__cCs
|�|�S)z>Returns an integer derived from the md5 hash of the given key.)r)rrrrr
�hashiszMetaRing.hashic	Csrx\|D]T\}}xJtd|d|d�D]0}|j|d7<||j|�|�d|���<q&WqWt|j���|_dS)z,Generate a ketama compatible continuum/ring.r�vnodes�weight��-N)�rangerrr�sorted�keysr)rZnodes�	node_name�	node_conf�wrrr
�_create_rings
"zMetaRing._create_ringc	Cs�y|j�|�}Wn*tk
r:td�||j�����YnVX|j�|�x6td|d|d�D]}|j|�	|�d|���=q`Wt
|j���|_dS)zaRemove the given node from the continuum/ring.

        :param node_name: the node name.
        z(node '{}' not found, available nodes: {}rrrrN)r�pop�	Exception�KeyError�formatr rrrrrr)rr!r"r#rrr
�_remove_node"szMetaRing._remove_nodeN)�__name__�
__module__�__qualname__�__doc__rrr$r)rrrr
rs
rN)�collectionsr�hashlibrrrrrr
�<module>s