HEX
Server: LiteSpeed
System: Linux cpir1.prohostdns.com 4.18.0-553.123.2.lve.el8.x86_64 #1 SMP Thu May 7 23:17:13 UTC 2026 x86_64
User: pelakir (2976)
PHP: 8.2.31
Disabled: exec, shell_exec, system, passthru, proc_open, proc_close, proc_terminate, proc_get_status, popen, pclose, pcntl_exec
Upload Files
File: //usr/local/lib/python3.6/site-packages/uhashring/__pycache__/ring_meta.cpython-36.pyc
3

U�`�@s*ddlmZddlmZGdd�d�ZdS)�)�Counter)�md5c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�MetaRingz,Implement a tunable consistent hashing ring.cCsDt�|_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 functioncSsttt|�jd��j�d�S)Nzutf-8�)�intr�str�encode�	hexdigest)�key�r�=/usr/local/lib/python3.6/site-packages/uhashring/ring_meta.py�<lambda>sz#MetaRing.__init__.<locals>.<lambda>N)r�
_distribution�_keys�_nodes�_ring�hasattr�	TypeError�_hash_fn)�selfZhash_fnrrr
�__init__szMetaRing.__init__cCs
|j|�S)z>Returns an integer derived from the md5 hash of the given key.)r)rrrrr
�hashiszMetaRing.hashicCsrx\|D]T\}}xJtd|d|d�D]0}|j|d7<||j|j|�d|���<q&WqWt|jj��|_dS)z,Generate a ketama compatible continuum/ring.r�vnodes�weight��-N)�rangerrr�sorted�keysr)r�nodes�	node_name�	node_conf�wrrr
�_create_rings
"zMetaRing._create_ringcCs�y|jj|�}Wn*tk
r:tdj||jj����YnVX|jj|�x6td|d|d�D]}|j|j	|�d|���=q`Wt
|jj��|_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�formatrrrrrrr)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