Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/coverage/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/coverage/__pycache__/numbits.cpython-311.pyc

�

�܋f=��z�dZddlmZddlZddlZddlmZddlmZm	Z	dd
�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zd d�ZdS)!a�
Functions to manipulate packed binary representations of number sets.

To save space, coverage stores sets of line numbers in SQLite using a packed
binary representation called a numbits.  A numbits is a set of positive
integers.

A numbits is stored as a blob in the database.  The exact meaning of the bytes
in the blobs should be considered an implementation detail that might change in
the future.  Use these functions to work with those binary blobs of data.

�)�annotationsN)�zip_longest)�Iterable�List�nums�
Iterable[int]�return�bytesc���	t|��dzdz}n#t$rYdSwxYwt|��}|D]}||dzxxd|dzzzcc<�t|��S)z�Convert `nums` into a numbits.

    Arguments:
        nums: a reusable iterable of integers, the line numbers to store.

    Returns:
        A binary blob.
    ���)�max�
ValueError�	bytearrayr
)r�nbytes�b�nums    �c/builddir/build/BUILD/cloudlinux-venv-1.0.6/venv/lib64/python3.11/site-packages/coverage/numbits.py�nums_to_numbitsrs�����T���a��!�#���������s�s�����	�&���A��"�"��	�#�q�&�	�	�	�Q�#��'�\�!�	�	�	�	���8�8�Os��
&�&�numbits�	List[int]c��g}t|��D]:\}}td��D]%}|d|zzr|�|dz|z���&�;|S)a$Convert a numbits into a list of numbers.

    Arguments:
        numbits: a binary blob, the packed number set.

    Returns:
        A list of ints.

    When registered as a SQLite function by :func:`register_sqlite_functions`,
    this returns a string, a JSON-encoded list of ints.

    rr
)�	enumerate�range�append)rr�byte_i�byte�bit_is     r�numbits_to_numsr .sr���D�!�'�*�*�0�0�����1�X�X�	0�	0�E���U�
�#�
0����F�Q�J��.�/�/�/��	0��Kr�numbits1�numbits2c�X�t||d���}td�|D����S)zsCompute the union of two numbits.

    Returns:
        A new numbits, the union of `numbits1` and `numbits2`.
    r��	fillvaluec3�&K�|]\}}||zV��
dS�N���.0�b1�b2s   r�	<genexpr>z numbits_union.<locals>.<genexpr>Js*����2�2�V�R���b��2�2�2�2�2�2r)rr
�r!r"�
byte_pairss   r�
numbits_unionr0Cs5���X�x�1�=�=�=�J��2�2�z�2�2�2�2�2�2rc��t||d���}td�|D����}|�d��S)z~Compute the intersection of two numbits.

    Returns:
        A new numbits, the intersection `numbits1` and `numbits2`.
    rr$c3�&K�|]\}}||zV��
dSr'r(r)s   rr-z'numbits_intersection.<locals>.<genexpr>Ts*����@�@�6�2�r�r�B�w�@�@�@�@�@�@r�)rr
�rstrip)r!r"r/�intersection_bytess    r�numbits_intersectionr6MsI���X�x�1�=�=�=�J��@�@�Z�@�@�@�@�@���$�$�U�+�+�+r�boolc�X�t||d���}td�|D����S)a
Is there any number that appears in both numbits?

    Determine whether two number sets have a non-empty intersection. This is
    faster than computing the intersection.

    Returns:
        A bool, True if there is any number in both `numbits1` and `numbits2`.
    rr$c3�&K�|]\}}||zV��
dSr'r(r)s   rr-z+numbits_any_intersection.<locals>.<genexpr>bs*����0�0�6�2�r�r�B�w�0�0�0�0�0�0r)r�anyr.s   r�numbits_any_intersectionr;Xs5���X�x�1�=�=�=�J��0�0�Z�0�0�0�0�0�0rr�intc��t|d��\}}|t|��krdSt||d|zz��S)zvDoes the integer `num` appear in `numbits`?

    Returns:
        A bool, True if `num` is a member of `numbits`.
    rFr
)�divmod�lenr7)rr�nbyte�nbits    r�num_in_numbitsrBesF����a�.�.�K�E�4���G������u�����!�t�)�,�-�-�-r�
connection�sqlite3.Connection�Nonec��|�ddt��|�ddt��|�ddt��|�ddt��|�ddd���d	S)
a�
    Define numbits functions in a SQLite connection.

    This defines these functions for use in SQLite statements:

    * :func:`numbits_union`
    * :func:`numbits_intersection`
    * :func:`numbits_any_intersection`
    * :func:`num_in_numbits`
    * :func:`numbits_to_nums`

    `connection` is a :class:`sqlite3.Connection <python:sqlite3.Connection>`
    object.  After creating the connection, pass it to this function to
    register the numbits functions.  Then you can use numbits functions in your
    queries::

        import sqlite3
        from coverage.numbits import register_sqlite_functions

        conn = sqlite3.connect("example.db")
        register_sqlite_functions(conn)
        c = conn.cursor()
        # Kind of a nonsense query:
        # Find all the files and contexts that executed line 47 in any file:
        c.execute(
            "select file_id, context_id from line_bits where num_in_numbits(?, numbits)",
            (47,)
        )
    r0�r6r;rBr r
c�D�tjt|����Sr')�json�dumpsr )rs r�<lambda>z+register_sqlite_functions.<locals>.<lambda>�s��t�z�/�Z[�J\�J\�?]�?]�rN)�create_functionr0r6r;rB)rCs r�register_sqlite_functionsrMqs���<�����=�A�A�A����5�q�:N�O�O�O����9�1�>V�W�W�W����/��N�C�C�C����0�!�5]�5]�^�^�^�^�^r)rrr	r
)rr
r	r)r!r
r"r
r	r
)r!r
r"r
r	r7)rr<rr
r	r7)rCrDr	rE)�__doc__�
__future__rrI�sqlite3�	itertoolsr�typingrrrr r0r6r;rBrMr(rr�<module>rSs�����#�"�"�"�"�"���������!�!�!�!�!�!�!�!�!�!�!�!�!�!�����(����*3�3�3�3�,�,�,�,�
1�
1�
1�
1�	.�	.�	.�	.�"_�"_�"_�"_�"_�"_r

Hacked By AnonymousFox1.0, Coded By AnonymousFox