HEX
Server: Apache
System: Linux a16-asgard6.hospedagemuolhost.com.br 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: maoristu4c3dbd03 (1436)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib64/python3.9/site-packages/rhsm/__pycache__/huffman.cpython-39.opt-1.pyc
a

X�Zh*�@s:ddlZddlZddlmZmZmZmZGdd�d�ZdS)�N)�Optional�List�Union�Tuplec@s eZdZdZd$eeeeefedededdd�dd�Z	e
dddd�dd��Zee
d	�d
d��Zeed	�dd
��Zeed	�dd��Ze
eddd�dd��Zde
d�dd�Zde
d�dd�Zde
d�dd�Zde
d�dd�Zde
d�dd�Zde
d�dd�Zed	�d d!�Zed	�d"d#�ZdS)%�HuffmanNodez.
    Represents a node in a Huffman tree.
    N)�weight�value�left�right�parent�returncCs"||_||_||_||_||_dS)a�
        :param weight:  number representing the weight/priority of this node
        :param value:   any value carried by this node, such as a symbol to be
                        used in reconstructing (decompressing) some data.
        :param left:    child node on the left, should have weight <= right
        :param right:   child node on the right, should have weight >= left
        :param parent:  parent node
        N)rrr	r
r)�selfrrr	r
r�r�2/usr/lib64/python3.9/site-packages/rhsm/huffman.py�__init__s
zHuffmanNode.__init__)r	r
rcCs&||j|jd||�}||_||_|S)a(
        Combine two nodes according to Huffman's tree-building algorithm. The
        weight of the left node should be <= that of the right node. If weights
        are equal, left should be the node that was in the queue longer. This
        creates a new node and sets it as the parent attribute of each child.

        :param left:    child node on the left, should have weight <= right
        :param right:   child node on the right, should have weight >= left

        :return:        new node that is the combination of left and right
        N)rr)�clsr	r
�noderrr�combine.s
zHuffmanNode.combine)rcCs|jduo|jduS)zJ
        :return:    True iff left and right are None, else False
        N)r
r	�r
rrr�is_leaf@szHuffmanNode.is_leafcCs&|jdurt�|jj|urdSdSdS)z[
        :return:    '0' if self is left of its parent, or '1' if right of parent.
        N�0�1)r�AttributeErrorr	rrrr�direction_from_parentGs

z!HuffmanNode.direction_from_parentcCsH|jstd��g}|}|dur>|jdur6|�d|j�|j}qd�|�S)z^
        :return:    Huffman code for this node as a series of characters '0' and '1'
        znode is not a leafNr�)rrr�insertr�join)r
ZturnsZ	next_noderrr�codeSs
zHuffmanNode.code)�nodesrcs~t����fdd�|D�}t�|�t�|�\}}zt�|�\}}WntyZ|YS0t�||�||�t��f�q$dS)z�
        :param nodes:   list of HuffmanNode instances that will become leaves
                        in a Huffman tree.
        :return:        HuffmanNode instance that is the root node of the tree
        csg|]}|t��f�qSr)�next)�.0r�Zcounterrr�
<listcomp>m�z*HuffmanNode.build_tree.<locals>.<listcomp>N)	�	itertools�count�heapq�heapify�heappop�
IndexError�heappushrr)rrZqueuer	r%r
rr!r�
build_treebs	

zHuffmanNode.build_tree)�otherrcCs|j|jkS�N�r�r
r,rrr�__lt__{szHuffmanNode.__lt__cCs|j|jkSr-r.r/rrr�__le__~szHuffmanNode.__le__cCs|j|jkSr-r.r/rrr�__gt__�szHuffmanNode.__gt__cCs|j|jkSr-r.r/rrr�__ge__�szHuffmanNode.__ge__cCst|d�sdS|j|jkS)NrF��hasattrrr/rrr�__eq__�s
zHuffmanNode.__eq__cCst|d�sdS|j|jkS)NrTr4r/rrr�__ne__�s
zHuffmanNode.__ne__cCs|jSr-)rrrrr�__hash__�szHuffmanNode.__hash__cCsd|j|jfS)NzHuffmanNode(%d, "%s"))rrrrrr�__repr__�szHuffmanNode.__repr__)NNNN)�__name__�
__module__�__qualname__�__doc__�intr�str�dictrr�classmethodr�property�boolrrrrr+r0r1r2r3r6r7r8r9rrrrrs>��r)r&r$�typingrrrrrrrrr�<module>s