HEX
Server: LiteSpeed
System: Linux altar40.supremepanel40.com 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: sescorpcl (4477)
PHP: 8.2.32
Disabled: NONE
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