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_ketama.cpython-37.pyc
B

��f�	�@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�F/opt/alt/python37/lib/python3.7/site-packages/uhashring/ring_ketama.py�<lambda>�z%KetamaRing.__init__.<locals>.<lambda>N)r�
_distribution�_keys�_nodes�	_replicas�_ring�
_listbytes)�selfZreplicasrrr	�__init__	szKetamaRing.__init__rcCs`|�tt|��d�����}|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�replicaZdh�rdrrr	�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|j��D]}||d7}qW||_t�}g}i}xN|j��D]@\}}x6|�||�D]&}|||<t||�||d7<qZWqDW||_||_||_	dS)z,Generate a ketama compatible continuum/ring.rr!rN)
r�valuesr$r�itemsr+rrr
r)	rZnodesr$r'rr
rr&�hrrr	�_create_ring-s
zKetamaRing._create_ringc	CsLy|j�|�Wn*tk
r:td�||j�����YnX|�|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�keysr2)rr&rrr	�_remove_node@szKetamaRing._remove_nodeN)r)r)�__name__�
__module__�__qualname__�__doc__rr r+�staticmethodrr2r8rrrr	rs


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