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_ketama.cpython-36.pyc
3

��x`
�@s6ddlmZddlmZddlmZGdd�d�ZdS)�)�insort)�Counter)�md5c@sHeZdZdZddd�Zddd�Zdd	�Zed
d��Zdd
�Z	dd�Z
dS)�
KetamaRingz6Implement a ketama compatible consistent hashing ring.�cCs.t�|_g|_i|_||_i|_dd�|_dS)zCreate a new HashRing.cSs|S)N�)�xrr�?/usr/local/lib/python3.6/site-packages/uhashring/ring_ketama.py�<lambda>sz%KetamaRing.__init__.<locals>.<lambda>N)r�
_distribution�_keys�_nodes�	_replicas�_ring�
_listbytes)�selfZreplicasrrr	�__init__	szKetamaRing.__init__rcCs`|jtt|�jd��j��}|d}|d|d>|d|d>B|d|d>B|d	|BS)
z4Returns a ketama compatible hash from the given key.zutf-8r������r)rr�str�encode�digest)r�key�replicaZdhZrdrrr	�hashiszKetamaRing.hashiccsl|dt|j�|d|j}xFtd|�D]8}|�d|��}x$td|j�D]}|j||d�VqLWq,WdS)z�Calculate the weight factor of the given node and
        yield its hash key for every configured replica.

        :param node_name: the node name.
        Zvnodes�weightr�-)rN)�lenr
�_weight_sum�rangerr)r�	node_name�	node_conf�ks�wZw_node_name�irrr	�_hashi_weight_generatorsz"KetamaRing._hashi_weight_generatorcCs
tt|�S)ziPython 2 compatible int iterator from str.

        :param data: the string to int iterate upon.
        )�map�ord)�datarrr	r'szKetamaRing._listbytesc	Cs�d}x|jj�D]}||d7}qW||_t�}g}i}xN|jj�D]@\}}x6|j||�D]&}|||<t||�||d7<qZWqDW||_||_||_	dS)z,Generate a ketama compatible continuum/ring.rrrN)
r
�valuesr"r�itemsr)rrrr)	r�nodesr"r%rrrr$�hrrr	�_create_ring/s
zKetamaRing._create_ringcCsLy|jj|�Wn*tk
r:tdj||jj����YnX|j|j�dS)zaRemove the given node from the continuum/ring.

        :param node_name: the node name.
        z(node '{}' not found, available nodes: {}N)r
�pop�	Exception�KeyError�format�keysr1)rr$rrr	�_remove_nodeBszKetamaRing._remove_nodeN)r)r)�__name__�
__module__�__qualname__�__doc__rrr)�staticmethodrr1r7rrrr	rs


rN)�bisectr�collectionsr�hashlibrrrrrr	�<module>s