bitarray 3.11.0__tar.gz → 3.12.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bitarray-3.11.0 → bitarray-3.12.0}/PKG-INFO +100 -21
- {bitarray-3.11.0 → bitarray-3.12.0}/README.rst +98 -20
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/__init__.pyi +1 -1
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/_bitarray.c +48 -10
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/_util.c +62 -40
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/bitarray.h +1 -8
- bitarray-3.12.0/bitarray/bitfields.py +447 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/pythoncapi_compat.h +2 -2
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/test_bitarray.py +73 -9
- bitarray-3.12.0/bitarray/test_bitfields.py +721 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/test_util.py +5 -1
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/util.py +36 -25
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray.egg-info/PKG-INFO +100 -21
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray.egg-info/SOURCES.txt +2 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/setup.py +1 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/LICENSE +0 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/__init__.py +0 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/py.typed +0 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/test_281.pickle +0 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/test_free_threading.py +0 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray/util.pyi +0 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray.egg-info/dependency_links.txt +0 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray.egg-info/not-zip-safe +0 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/bitarray.egg-info/top_level.txt +0 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/pyproject.toml +0 -0
- {bitarray-3.11.0 → bitarray-3.12.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bitarray
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.12.0
|
|
4
4
|
Summary: efficient arrays of booleans -- C extension
|
|
5
5
|
Home-page: https://github.com/ilanschnell/bitarray
|
|
6
6
|
Author: Ilan Schnell
|
|
@@ -19,6 +19,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
22
23
|
Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
|
|
23
24
|
Classifier: Topic :: Utilities
|
|
24
25
|
Requires-Python: >=3.7
|
|
@@ -54,17 +55,20 @@ Key features
|
|
|
54
55
|
operations ``+``, ``*``, ``+=``, ``*=``, the ``in`` operator, ``len()``
|
|
55
56
|
* Bitwise operations: ``~``, ``&``, ``|``, ``^``, ``<<``, ``>>`` (as well as
|
|
56
57
|
their in-place versions ``&=``, ``|=``, ``^=``, ``<<=``, ``>>=``).
|
|
57
|
-
* Free-threading support
|
|
58
|
+
* `Free-threading support <https://github.com/ilanschnell/bitarray/blob/master/doc/free_threading.rst>`__
|
|
59
|
+
(for GIL-disabled CPython 3.14 and later)
|
|
58
60
|
* Fast methods for encoding and decoding variable-length prefix codes.
|
|
59
|
-
* Bitarray objects support the buffer protocol
|
|
60
|
-
exporting buffers).
|
|
61
|
+
* Bitarray objects support the `buffer protocol <https://github.com/ilanschnell/bitarray/blob/master/doc/buffer.rst>`__
|
|
62
|
+
(both importing and exporting buffers).
|
|
61
63
|
* Efficient packing and unpacking for interoperability with byte-oriented
|
|
62
64
|
objects such as NumPy arrays.
|
|
63
65
|
* Pickling and unpickling of bitarray objects.
|
|
64
66
|
* Immutable ``frozenbitarray`` objects which are hashable
|
|
65
67
|
* Fast searching for bits and bit patterns
|
|
68
|
+
* ``bitfields`` sub-module for packing and unpacking fixed-width
|
|
69
|
+
`bit-field structures <https://github.com/ilanschnell/bitarray/blob/master/doc/bitfields.rst>`__
|
|
66
70
|
* Type hinting
|
|
67
|
-
* Extensive test suite with over
|
|
71
|
+
* Extensive test suite with over 700 unit tests
|
|
68
72
|
* Utility module ``bitarray.util``:
|
|
69
73
|
|
|
70
74
|
* conversion to and from hexadecimal strings
|
|
@@ -72,7 +76,7 @@ Key features
|
|
|
72
76
|
* pretty printing
|
|
73
77
|
* conversion to and from integers
|
|
74
78
|
* creating Huffman codes
|
|
75
|
-
* compression of sparse bitarrays
|
|
79
|
+
* `compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__
|
|
76
80
|
* run-length encoding
|
|
77
81
|
* serialization and deserialization
|
|
78
82
|
* various count functions
|
|
@@ -96,7 +100,7 @@ Once you have installed the package, you may want to test it:
|
|
|
96
100
|
$ python -c 'import bitarray; bitarray.test()'
|
|
97
101
|
bitarray is installed in: /Users/ilan/bitarray/bitarray
|
|
98
102
|
sys.prefix: /Users/ilan/miniforge
|
|
99
|
-
bitarray version: 3.
|
|
103
|
+
bitarray version: 3.12.0
|
|
100
104
|
sys.version: 3.14.5 (main, May 20 2026) [Clang 20.1.8]
|
|
101
105
|
sys.abiflags: ''
|
|
102
106
|
sys._is_gil_enabled(): True
|
|
@@ -113,7 +117,7 @@ Once you have installed the package, you may want to test it:
|
|
|
113
117
|
..........s.....................................s........................
|
|
114
118
|
......s.........................................................
|
|
115
119
|
----------------------------------------------------------------------
|
|
116
|
-
Ran
|
|
120
|
+
Ran 711 tests in 0.196s
|
|
117
121
|
|
|
118
122
|
OK (skipped=4)
|
|
119
123
|
|
|
@@ -360,7 +364,7 @@ and can therefore be used as a dictionary key:
|
|
|
360
364
|
Reference
|
|
361
365
|
=========
|
|
362
366
|
|
|
363
|
-
bitarray version: 3.
|
|
367
|
+
bitarray version: 3.12.0 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
|
|
364
368
|
|
|
365
369
|
In the following, ``item`` and ``value`` are usually a single bit -
|
|
366
370
|
an integer 0 or 1.
|
|
@@ -396,7 +400,7 @@ The bitarray object:
|
|
|
396
400
|
|
|
397
401
|
|
|
398
402
|
bitarray methods:
|
|
399
|
-
|
|
403
|
+
^^^^^^^^^^^^^^^^^
|
|
400
404
|
|
|
401
405
|
``all()`` -> bool
|
|
402
406
|
Return ``True`` when all bits in bitarray are 1.
|
|
@@ -492,9 +496,12 @@ bitarray methods:
|
|
|
492
496
|
New in version 3.4: allow ``bytes`` object
|
|
493
497
|
|
|
494
498
|
|
|
495
|
-
``fill()`` -> int
|
|
499
|
+
``fill(m=8, /)`` -> int
|
|
496
500
|
Add zeros to the end of the bitarray, such that the length will be
|
|
497
|
-
a multiple of
|
|
501
|
+
a multiple of the positive integer ``m``, and return the number of bits
|
|
502
|
+
added (in ``range(m)``).
|
|
503
|
+
|
|
504
|
+
New in version 3.12: add optional alignment argument
|
|
498
505
|
|
|
499
506
|
|
|
500
507
|
``find(sub_bitarray, start=0, stop=<end>, /, right=False)`` -> int
|
|
@@ -640,10 +647,10 @@ bitarray methods:
|
|
|
640
647
|
using the specified mapping.
|
|
641
648
|
|
|
642
649
|
|
|
643
|
-
bitarray
|
|
644
|
-
|
|
650
|
+
bitarray attributes:
|
|
651
|
+
^^^^^^^^^^^^^^^^^^^^
|
|
645
652
|
|
|
646
|
-
|
|
653
|
+
Attributes were added in version 2.6.
|
|
647
654
|
|
|
648
655
|
``endian`` -> str
|
|
649
656
|
bit-endianness as Unicode string
|
|
@@ -664,7 +671,7 @@ Data descriptors were added in version 2.6.
|
|
|
664
671
|
|
|
665
672
|
|
|
666
673
|
decodeiterator methods:
|
|
667
|
-
|
|
674
|
+
^^^^^^^^^^^^^^^^^^^^^^^
|
|
668
675
|
|
|
669
676
|
``skipbits(n, /)`` -> bitarray
|
|
670
677
|
Skip over the next ``n`` bits and return them.
|
|
@@ -673,8 +680,8 @@ decodeiterator methods:
|
|
|
673
680
|
New in version 3.9
|
|
674
681
|
|
|
675
682
|
|
|
676
|
-
decodeiterator
|
|
677
|
-
|
|
683
|
+
decodeiterator attributes:
|
|
684
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
678
685
|
|
|
679
686
|
``index`` -> int
|
|
680
687
|
current bit position to be decoded by subsequent ``next``
|
|
@@ -683,7 +690,7 @@ decodeiterator data descriptors:
|
|
|
683
690
|
|
|
684
691
|
|
|
685
692
|
decodetree methods:
|
|
686
|
-
|
|
693
|
+
^^^^^^^^^^^^^^^^^^^
|
|
687
694
|
|
|
688
695
|
``nodes()`` -> tuple
|
|
689
696
|
Return tuple with number of:
|
|
@@ -785,7 +792,7 @@ This sub-module was added in version 1.2.
|
|
|
785
792
|
Bitarray of base ``n`` ASCII representation.
|
|
786
793
|
Allowed values for ``n`` are 2, 4, 8, 16, 32 and 64.
|
|
787
794
|
For ``n=32`` the RFC 4648 Base32 alphabet is used, and for ``n=64`` the
|
|
788
|
-
standard base 64 alphabet is used.
|
|
795
|
+
standard base 64 alphabet is used. ASCII whitespace is ignored.
|
|
789
796
|
|
|
790
797
|
See also: `Bitarray representations <https://github.com/ilanschnell/bitarray/blob/master/doc/represent.rst>`__
|
|
791
798
|
|
|
@@ -893,7 +900,7 @@ This sub-module was added in version 1.2.
|
|
|
893
900
|
``hex2ba(hexstr, /, endian=None)`` -> bitarray
|
|
894
901
|
Bitarray of hexadecimal representation. hexstr may contain any number
|
|
895
902
|
(including odd numbers) of hex digits (upper or lower case).
|
|
896
|
-
|
|
903
|
+
ASCII whitespace is ignored.
|
|
897
904
|
|
|
898
905
|
New in version 3.3: ignore whitespace
|
|
899
906
|
|
|
@@ -1099,3 +1106,75 @@ This sub-module was added in version 1.2.
|
|
|
1099
1106
|
bit-endianness (``little`` or ``big``).
|
|
1100
1107
|
|
|
1101
1108
|
|
|
1109
|
+
The `bitarray.bitfields` module:
|
|
1110
|
+
--------------------------------
|
|
1111
|
+
|
|
1112
|
+
This sub-module was added in version 3.12.
|
|
1113
|
+
For a detailed description, see: `Bit-field structures <https://github.com/ilanschnell/bitarray/blob/master/doc/bitfields.rst>`__
|
|
1114
|
+
|
|
1115
|
+
``Struct(format)`` -> compiled struct object
|
|
1116
|
+
Central class for packing and unpacking bit-level structures.
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
``calcsize(format)`` -> int
|
|
1120
|
+
Return the size (in bits) of the struct corresponding to the format string.
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
``compile(format)`` -> Struct
|
|
1124
|
+
Compile given format string and return a compiled format object that
|
|
1125
|
+
can be used to pack and/or unpack data multiple times.
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
``pack(format, v1, v2, ...)`` -> bitarray
|
|
1129
|
+
Return a bitarray containing the values v1, v2, ... packed according
|
|
1130
|
+
to the format string.
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
``pack_into(format, bitarray, offset, v1, v2, ...)`` -> None
|
|
1134
|
+
Pack the values v1, v2, ... into the writable bitarray starting at bit
|
|
1135
|
+
offset ``offset``. A negative offset counts from the end of bitarray.
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
``unpack(format, bitarray)`` -> tuple
|
|
1139
|
+
Return a tuple containing values unpacked according to the format string.
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
``unpack_from(format, bitarray, offset=0)`` -> tuple
|
|
1143
|
+
Unpack values from bitarray starting at bit offset ``offset``, and return a
|
|
1144
|
+
tuple. A negative offset counts from the end of bitarray.
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
Struct methods:
|
|
1148
|
+
^^^^^^^^^^^^^^^
|
|
1149
|
+
|
|
1150
|
+
``format()`` -> str
|
|
1151
|
+
Return the canonical format string reconstructed from this compiled format.
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
``pack(v1, v2, ...)`` -> bitarray
|
|
1155
|
+
Return a bitarray containing the values v1, v2, ... packed according to this
|
|
1156
|
+
compiled format.
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
``pack_into(bitarray, offset, v1, v2, ...)`` -> None
|
|
1160
|
+
Pack the values v1, v2, ... into the writable bitarray starting at bit
|
|
1161
|
+
offset ``offset``. A negative offset counts from the end of bitarray.
|
|
1162
|
+
|
|
1163
|
+
|
|
1164
|
+
``unpack(bitarray)`` -> tuple
|
|
1165
|
+
Return a tuple containing values unpacked according to this compiled format.
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
``unpack_from(bitarray, offset=0)`` -> tuple
|
|
1169
|
+
Unpack values from bitarray starting at bit offset ``offset``, and return a
|
|
1170
|
+
tuple. A negative offset counts from the end of bitarray.
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
Struct attributes:
|
|
1174
|
+
^^^^^^^^^^^^^^^^^^
|
|
1175
|
+
|
|
1176
|
+
``width`` -> int
|
|
1177
|
+
Total number of bits in the compiled structure.
|
|
1178
|
+
|
|
1179
|
+
``values`` -> int
|
|
1180
|
+
Number of values consumed by ``pack()`` and returned by ``unpack()``.
|
|
@@ -19,17 +19,20 @@ Key features
|
|
|
19
19
|
operations ``+``, ``*``, ``+=``, ``*=``, the ``in`` operator, ``len()``
|
|
20
20
|
* Bitwise operations: ``~``, ``&``, ``|``, ``^``, ``<<``, ``>>`` (as well as
|
|
21
21
|
their in-place versions ``&=``, ``|=``, ``^=``, ``<<=``, ``>>=``).
|
|
22
|
-
* Free-threading support
|
|
22
|
+
* `Free-threading support <https://github.com/ilanschnell/bitarray/blob/master/doc/free_threading.rst>`__
|
|
23
|
+
(for GIL-disabled CPython 3.14 and later)
|
|
23
24
|
* Fast methods for encoding and decoding variable-length prefix codes.
|
|
24
|
-
* Bitarray objects support the buffer protocol
|
|
25
|
-
exporting buffers).
|
|
25
|
+
* Bitarray objects support the `buffer protocol <https://github.com/ilanschnell/bitarray/blob/master/doc/buffer.rst>`__
|
|
26
|
+
(both importing and exporting buffers).
|
|
26
27
|
* Efficient packing and unpacking for interoperability with byte-oriented
|
|
27
28
|
objects such as NumPy arrays.
|
|
28
29
|
* Pickling and unpickling of bitarray objects.
|
|
29
30
|
* Immutable ``frozenbitarray`` objects which are hashable
|
|
30
31
|
* Fast searching for bits and bit patterns
|
|
32
|
+
* ``bitfields`` sub-module for packing and unpacking fixed-width
|
|
33
|
+
`bit-field structures <https://github.com/ilanschnell/bitarray/blob/master/doc/bitfields.rst>`__
|
|
31
34
|
* Type hinting
|
|
32
|
-
* Extensive test suite with over
|
|
35
|
+
* Extensive test suite with over 700 unit tests
|
|
33
36
|
* Utility module ``bitarray.util``:
|
|
34
37
|
|
|
35
38
|
* conversion to and from hexadecimal strings
|
|
@@ -37,7 +40,7 @@ Key features
|
|
|
37
40
|
* pretty printing
|
|
38
41
|
* conversion to and from integers
|
|
39
42
|
* creating Huffman codes
|
|
40
|
-
* compression of sparse bitarrays
|
|
43
|
+
* `compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__
|
|
41
44
|
* run-length encoding
|
|
42
45
|
* serialization and deserialization
|
|
43
46
|
* various count functions
|
|
@@ -61,7 +64,7 @@ Once you have installed the package, you may want to test it:
|
|
|
61
64
|
$ python -c 'import bitarray; bitarray.test()'
|
|
62
65
|
bitarray is installed in: /Users/ilan/bitarray/bitarray
|
|
63
66
|
sys.prefix: /Users/ilan/miniforge
|
|
64
|
-
bitarray version: 3.
|
|
67
|
+
bitarray version: 3.12.0
|
|
65
68
|
sys.version: 3.14.5 (main, May 20 2026) [Clang 20.1.8]
|
|
66
69
|
sys.abiflags: ''
|
|
67
70
|
sys._is_gil_enabled(): True
|
|
@@ -78,7 +81,7 @@ Once you have installed the package, you may want to test it:
|
|
|
78
81
|
..........s.....................................s........................
|
|
79
82
|
......s.........................................................
|
|
80
83
|
----------------------------------------------------------------------
|
|
81
|
-
Ran
|
|
84
|
+
Ran 711 tests in 0.196s
|
|
82
85
|
|
|
83
86
|
OK (skipped=4)
|
|
84
87
|
|
|
@@ -325,7 +328,7 @@ and can therefore be used as a dictionary key:
|
|
|
325
328
|
Reference
|
|
326
329
|
=========
|
|
327
330
|
|
|
328
|
-
bitarray version: 3.
|
|
331
|
+
bitarray version: 3.12.0 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
|
|
329
332
|
|
|
330
333
|
In the following, ``item`` and ``value`` are usually a single bit -
|
|
331
334
|
an integer 0 or 1.
|
|
@@ -361,7 +364,7 @@ The bitarray object:
|
|
|
361
364
|
|
|
362
365
|
|
|
363
366
|
bitarray methods:
|
|
364
|
-
|
|
367
|
+
^^^^^^^^^^^^^^^^^
|
|
365
368
|
|
|
366
369
|
``all()`` -> bool
|
|
367
370
|
Return ``True`` when all bits in bitarray are 1.
|
|
@@ -457,9 +460,12 @@ bitarray methods:
|
|
|
457
460
|
New in version 3.4: allow ``bytes`` object
|
|
458
461
|
|
|
459
462
|
|
|
460
|
-
``fill()`` -> int
|
|
463
|
+
``fill(m=8, /)`` -> int
|
|
461
464
|
Add zeros to the end of the bitarray, such that the length will be
|
|
462
|
-
a multiple of
|
|
465
|
+
a multiple of the positive integer ``m``, and return the number of bits
|
|
466
|
+
added (in ``range(m)``).
|
|
467
|
+
|
|
468
|
+
New in version 3.12: add optional alignment argument
|
|
463
469
|
|
|
464
470
|
|
|
465
471
|
``find(sub_bitarray, start=0, stop=<end>, /, right=False)`` -> int
|
|
@@ -605,10 +611,10 @@ bitarray methods:
|
|
|
605
611
|
using the specified mapping.
|
|
606
612
|
|
|
607
613
|
|
|
608
|
-
bitarray
|
|
609
|
-
|
|
614
|
+
bitarray attributes:
|
|
615
|
+
^^^^^^^^^^^^^^^^^^^^
|
|
610
616
|
|
|
611
|
-
|
|
617
|
+
Attributes were added in version 2.6.
|
|
612
618
|
|
|
613
619
|
``endian`` -> str
|
|
614
620
|
bit-endianness as Unicode string
|
|
@@ -629,7 +635,7 @@ Data descriptors were added in version 2.6.
|
|
|
629
635
|
|
|
630
636
|
|
|
631
637
|
decodeiterator methods:
|
|
632
|
-
|
|
638
|
+
^^^^^^^^^^^^^^^^^^^^^^^
|
|
633
639
|
|
|
634
640
|
``skipbits(n, /)`` -> bitarray
|
|
635
641
|
Skip over the next ``n`` bits and return them.
|
|
@@ -638,8 +644,8 @@ decodeiterator methods:
|
|
|
638
644
|
New in version 3.9
|
|
639
645
|
|
|
640
646
|
|
|
641
|
-
decodeiterator
|
|
642
|
-
|
|
647
|
+
decodeiterator attributes:
|
|
648
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
643
649
|
|
|
644
650
|
``index`` -> int
|
|
645
651
|
current bit position to be decoded by subsequent ``next``
|
|
@@ -648,7 +654,7 @@ decodeiterator data descriptors:
|
|
|
648
654
|
|
|
649
655
|
|
|
650
656
|
decodetree methods:
|
|
651
|
-
|
|
657
|
+
^^^^^^^^^^^^^^^^^^^
|
|
652
658
|
|
|
653
659
|
``nodes()`` -> tuple
|
|
654
660
|
Return tuple with number of:
|
|
@@ -750,7 +756,7 @@ This sub-module was added in version 1.2.
|
|
|
750
756
|
Bitarray of base ``n`` ASCII representation.
|
|
751
757
|
Allowed values for ``n`` are 2, 4, 8, 16, 32 and 64.
|
|
752
758
|
For ``n=32`` the RFC 4648 Base32 alphabet is used, and for ``n=64`` the
|
|
753
|
-
standard base 64 alphabet is used.
|
|
759
|
+
standard base 64 alphabet is used. ASCII whitespace is ignored.
|
|
754
760
|
|
|
755
761
|
See also: `Bitarray representations <https://github.com/ilanschnell/bitarray/blob/master/doc/represent.rst>`__
|
|
756
762
|
|
|
@@ -858,7 +864,7 @@ This sub-module was added in version 1.2.
|
|
|
858
864
|
``hex2ba(hexstr, /, endian=None)`` -> bitarray
|
|
859
865
|
Bitarray of hexadecimal representation. hexstr may contain any number
|
|
860
866
|
(including odd numbers) of hex digits (upper or lower case).
|
|
861
|
-
|
|
867
|
+
ASCII whitespace is ignored.
|
|
862
868
|
|
|
863
869
|
New in version 3.3: ignore whitespace
|
|
864
870
|
|
|
@@ -1064,3 +1070,75 @@ This sub-module was added in version 1.2.
|
|
|
1064
1070
|
bit-endianness (``little`` or ``big``).
|
|
1065
1071
|
|
|
1066
1072
|
|
|
1073
|
+
The `bitarray.bitfields` module:
|
|
1074
|
+
--------------------------------
|
|
1075
|
+
|
|
1076
|
+
This sub-module was added in version 3.12.
|
|
1077
|
+
For a detailed description, see: `Bit-field structures <https://github.com/ilanschnell/bitarray/blob/master/doc/bitfields.rst>`__
|
|
1078
|
+
|
|
1079
|
+
``Struct(format)`` -> compiled struct object
|
|
1080
|
+
Central class for packing and unpacking bit-level structures.
|
|
1081
|
+
|
|
1082
|
+
|
|
1083
|
+
``calcsize(format)`` -> int
|
|
1084
|
+
Return the size (in bits) of the struct corresponding to the format string.
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
``compile(format)`` -> Struct
|
|
1088
|
+
Compile given format string and return a compiled format object that
|
|
1089
|
+
can be used to pack and/or unpack data multiple times.
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
``pack(format, v1, v2, ...)`` -> bitarray
|
|
1093
|
+
Return a bitarray containing the values v1, v2, ... packed according
|
|
1094
|
+
to the format string.
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
``pack_into(format, bitarray, offset, v1, v2, ...)`` -> None
|
|
1098
|
+
Pack the values v1, v2, ... into the writable bitarray starting at bit
|
|
1099
|
+
offset ``offset``. A negative offset counts from the end of bitarray.
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
``unpack(format, bitarray)`` -> tuple
|
|
1103
|
+
Return a tuple containing values unpacked according to the format string.
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
``unpack_from(format, bitarray, offset=0)`` -> tuple
|
|
1107
|
+
Unpack values from bitarray starting at bit offset ``offset``, and return a
|
|
1108
|
+
tuple. A negative offset counts from the end of bitarray.
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
Struct methods:
|
|
1112
|
+
^^^^^^^^^^^^^^^
|
|
1113
|
+
|
|
1114
|
+
``format()`` -> str
|
|
1115
|
+
Return the canonical format string reconstructed from this compiled format.
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
``pack(v1, v2, ...)`` -> bitarray
|
|
1119
|
+
Return a bitarray containing the values v1, v2, ... packed according to this
|
|
1120
|
+
compiled format.
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
``pack_into(bitarray, offset, v1, v2, ...)`` -> None
|
|
1124
|
+
Pack the values v1, v2, ... into the writable bitarray starting at bit
|
|
1125
|
+
offset ``offset``. A negative offset counts from the end of bitarray.
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
``unpack(bitarray)`` -> tuple
|
|
1129
|
+
Return a tuple containing values unpacked according to this compiled format.
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
``unpack_from(bitarray, offset=0)`` -> tuple
|
|
1133
|
+
Unpack values from bitarray starting at bit offset ``offset``, and return a
|
|
1134
|
+
tuple. A negative offset counts from the end of bitarray.
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
Struct attributes:
|
|
1138
|
+
^^^^^^^^^^^^^^^^^^
|
|
1139
|
+
|
|
1140
|
+
``width`` -> int
|
|
1141
|
+
Total number of bits in the compiled structure.
|
|
1142
|
+
|
|
1143
|
+
``values`` -> int
|
|
1144
|
+
Number of values consumed by ``pack()`` and returned by ``unpack()``.
|
|
@@ -64,7 +64,7 @@ class bitarray:
|
|
|
64
64
|
code: Union[CodeDict, decodetree]) -> decodeiterator: ...
|
|
65
65
|
|
|
66
66
|
def extend(self, x: Union[str, Iterable[int]]) -> None: ...
|
|
67
|
-
def fill(self) -> int: ...
|
|
67
|
+
def fill(self, m: int = ...) -> int: ...
|
|
68
68
|
def find(self,
|
|
69
69
|
sub_bitarray: Union[bitarray, int],
|
|
70
70
|
start: int = ...,
|
|
@@ -1291,28 +1291,66 @@ If `iterable` is a (Unicode) string, each `0` and `1` are appended as\n\
|
|
|
1291
1291
|
bits (ignoring whitespace and underscore).");
|
|
1292
1292
|
|
|
1293
1293
|
|
|
1294
|
-
static
|
|
1295
|
-
|
|
1294
|
+
static Py_ssize_t
|
|
1295
|
+
bitarray_fill_lock_held(bitarrayobject *self, Py_ssize_t m)
|
|
1296
1296
|
{
|
|
1297
|
+
const Py_ssize_t nbits = self->nbits;
|
|
1297
1298
|
Py_ssize_t p;
|
|
1298
1299
|
|
|
1300
|
+
assert(m > 0);
|
|
1301
|
+
assert(self->readonly == 0);
|
|
1302
|
+
|
|
1303
|
+
p = nbits % m;
|
|
1304
|
+
if (p)
|
|
1305
|
+
p = m - p;
|
|
1306
|
+
|
|
1307
|
+
if (p > PY_SSIZE_T_MAX - nbits) {
|
|
1308
|
+
PyErr_SetString(PyExc_OverflowError, "bitarray size overflow");
|
|
1309
|
+
return -1;
|
|
1310
|
+
}
|
|
1311
|
+
if (p > PADBITS(self)) {
|
|
1312
|
+
if (resize(self, nbits + p) < 0)
|
|
1313
|
+
return -1;
|
|
1314
|
+
set_span(self, nbits, nbits + p, 0);
|
|
1315
|
+
}
|
|
1316
|
+
else if (p) {
|
|
1317
|
+
/* Extending into existing pad bits does not require resize().
|
|
1318
|
+
Avoiding it allows fill() to work on imported or exported buffers
|
|
1319
|
+
when the buffer size remains unchanged. */
|
|
1320
|
+
set_padbits(self);
|
|
1321
|
+
self->nbits += p;
|
|
1322
|
+
}
|
|
1323
|
+
return p;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
static PyObject *
|
|
1327
|
+
bitarray_fill(bitarrayobject *self, PyObject *args)
|
|
1328
|
+
{
|
|
1329
|
+
Py_ssize_t m = 8, p;
|
|
1330
|
+
|
|
1299
1331
|
RAISE_IF_READONLY(self, NULL);
|
|
1332
|
+
if (!PyArg_ParseTuple(args, "|n:fill", &m))
|
|
1333
|
+
return NULL;
|
|
1334
|
+
if (m <= 0) {
|
|
1335
|
+
PyErr_SetString(PyExc_ValueError, "m must be a positive integer");
|
|
1336
|
+
return NULL;
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1300
1339
|
Py_BEGIN_CRITICAL_SECTION(self);
|
|
1301
|
-
p =
|
|
1302
|
-
set_padbits(self);
|
|
1303
|
-
/* there is no reason to call resize() - .fill() will not raise
|
|
1304
|
-
BufferError when buffer is imported or exported */
|
|
1305
|
-
self->nbits += p;
|
|
1340
|
+
p = bitarray_fill_lock_held(self, m);
|
|
1306
1341
|
Py_END_CRITICAL_SECTION();
|
|
1307
1342
|
|
|
1343
|
+
if (p < 0)
|
|
1344
|
+
return NULL;
|
|
1308
1345
|
return PyLong_FromSsize_t(p);
|
|
1309
1346
|
}
|
|
1310
1347
|
|
|
1311
1348
|
PyDoc_STRVAR(fill_doc,
|
|
1312
|
-
"fill() -> int\n\
|
|
1349
|
+
"fill(m=8, /) -> int\n\
|
|
1313
1350
|
\n\
|
|
1314
1351
|
Add zeros to the end of the bitarray, such that the length will be\n\
|
|
1315
|
-
a multiple of
|
|
1352
|
+
a multiple of the positive integer `m`, and return the number of bits\n\
|
|
1353
|
+
added (in `range(m)`).");
|
|
1316
1354
|
|
|
1317
1355
|
|
|
1318
1356
|
static PyObject *
|
|
@@ -4580,7 +4618,7 @@ static PyMethodDef bitarray_methods[] = {
|
|
|
4580
4618
|
encode_doc},
|
|
4581
4619
|
{"extend", (PyCFunction) bitarray_extend, METH_O,
|
|
4582
4620
|
extend_doc},
|
|
4583
|
-
{"fill", (PyCFunction) bitarray_fill,
|
|
4621
|
+
{"fill", (PyCFunction) bitarray_fill, METH_VARARGS,
|
|
4584
4622
|
fill_doc},
|
|
4585
4623
|
{"find", (PyCFunction) bitarray_find, METH_VARARGS |
|
|
4586
4624
|
METH_KEYWORDS,
|