Edit File: numbits.cpython-311.pyc
� ����q�d=����������������������z�����d�Z�ddlmZ�ddlZddlZddlmZ�ddlmZm Z �dd �Z dd �Zdd�Zdd�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����������|�������������dz��dz���}n#�t����������$�r�Y�dS�w�xY�wt����������|������������}|�D�]}||dz��xx���������d|dz��z��z��cc<����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.2/venv/lib64/python3.11/site-packages/coverage/numbits.py�nums_to_numbitsr������s���������T���a��!�#������������s�s������ �&���A���"��"�� �#�q�&� � � �Q�#��'�\�!� � � � ���8�8�Os������ &�&�numbits� List[int]c����������������������g�}t����������|�������������D�]:\��}}t����������d������������D�]%}|d|z��z��r|���������������������|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)r���r����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�������������}t����������d��|D���������������������������S�)zsCompute the union of two numbits. Returns: A new numbits, the union of `numbits1` and `numbits2`. r����� fillvaluec��������������3���&���K����|�]\��}}||z��V���� d�S��N����.0�b1�b2s��� r���� <genexpr>z numbits_union.<locals>.<genexpr>J���s*����������2�2�V�R���b��2�2�2�2�2�2r���)r���r ����r!���r"���� byte_pairss��� r���� numbits_unionr0���C���s5��������X�x�1�=�=�=�J��2�2�z�2�2�2�2�2�2r���c����������������������t����������|�|d�������������}t����������d��|D���������������������������}|���������������������d������������S�)z~Compute the intersection of two numbits. Returns: A new numbits, the intersection `numbits1` and `numbits2`. r���r$���c��������������3���&���K����|�]\��}}||z��V���� d�S�r'���r(���r)���s��� r���r-���z'numbits_intersection.<locals>.<genexpr>T���s*����������@�@�6�2�r�r�B�w�@�@�@�@�@�@r��������)r���r ����rstrip)r!���r"���r/����intersection_bytess��� r����numbits_intersectionr6���M���sI��������X�x�1�=�=�=�J��@�@�Z�@�@�@�@�@���$�$�U�+�+�+r����boolc�����������������X�����t����������|�|d�������������}t����������d��|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`. r���r$���c��������������3���&���K����|�]\��}}||z��V���� d�S�r'���r(���r)���s��� r���r-���z+numbits_any_intersection.<locals>.<genexpr>b���s*����������0�0�6�2�r�r�B�w�0�0�0�0�0�0r���)r����anyr.���s��� r����numbits_any_intersectionr;���X���s5��������X�x�1�=�=�=�J��0�0�Z�0�0�0�0�0�0r���r����intc����������������������t����������|�d������������\��}}|t����������|������������k����rdS�t����������||���������d|z��z��������������S�)zvDoes the integer `num` appear in `numbits`? Returns: A bool, True if `num` is a member of `numbits`. r���Fr ���)�divmod�lenr7���)r���r����nbyte�nbits��� r����num_in_numbitsrB���e���sF���������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�������r6���r;���rB���r ���r ���c�����������������D�����t����������j��������t����������|�������������������������S�r'���)�json�dumpsr ���)r���s��� r����<lambda>z+register_sqlite_functions.<locals>.<lambda>����s������t�z�/�Z[�J\�J\�?]�?]��r���N)�create_functionr0���r6���r;���rB���)rC���s��� r����register_sqlite_functionsrM���q���s�������<������=�A�A�A����5�q�:N�O�O�O����9�1�>V�W�W�W����/��N�C�C�C����0�!�5]�5]�^�^�^�^�^r���)r���r���r ���r ���)r���r ���r ���r���)r!���r ���r"���r ���r ���r ���)r!���r ���r"���r ���r ���r7���)r���r<���r���r ���r ���r7���)rC���rD���r ���rE���)�__doc__� __future__r���rI����sqlite3� itertoolsr����typingr���r���r���r ���r0���r6���r;���rB���rM���r(���r���r����<module>rS������s����������#��"��"��"��"��"������������!��!��!��!��!��!��!��!��!��!��!��!��!��!��������(�������*3��3��3��3�,��,��,��,� 1�� 1�� 1�� 1� .�� .�� .�� .�"_��"_��"_��"_��"_��"_r���