bitarray 3.12.0__tar.gz → 3.12.2__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.
Files changed (26) hide show
  1. {bitarray-3.12.0 → bitarray-3.12.2}/PKG-INFO +15 -61
  2. {bitarray-3.12.0 → bitarray-3.12.2}/README.rst +14 -60
  3. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/_bitarray.c +2 -2
  4. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/_util.c +8 -2
  5. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/bitarray.h +6 -5
  6. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/pythoncapi_compat.h +823 -399
  7. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/test_bitarray.py +6 -6
  8. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/test_bitfields.py +7 -7
  9. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray.egg-info/PKG-INFO +15 -61
  10. {bitarray-3.12.0 → bitarray-3.12.2}/LICENSE +0 -0
  11. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/__init__.py +0 -0
  12. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/__init__.pyi +0 -0
  13. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/bitfields.py +0 -0
  14. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/py.typed +0 -0
  15. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/test_281.pickle +0 -0
  16. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/test_free_threading.py +0 -0
  17. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/test_util.py +0 -0
  18. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/util.py +0 -0
  19. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray/util.pyi +0 -0
  20. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray.egg-info/SOURCES.txt +0 -0
  21. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray.egg-info/dependency_links.txt +0 -0
  22. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray.egg-info/not-zip-safe +0 -0
  23. {bitarray-3.12.0 → bitarray-3.12.2}/bitarray.egg-info/top_level.txt +0 -0
  24. {bitarray-3.12.0 → bitarray-3.12.2}/pyproject.toml +0 -0
  25. {bitarray-3.12.0 → bitarray-3.12.2}/setup.cfg +0 -0
  26. {bitarray-3.12.0 → bitarray-3.12.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bitarray
3
- Version: 3.12.0
3
+ Version: 3.12.2
4
4
  Summary: efficient arrays of booleans -- C extension
5
5
  Home-page: https://github.com/ilanschnell/bitarray
6
6
  Author: Ilan Schnell
@@ -57,11 +57,12 @@ Key features
57
57
  their in-place versions ``&=``, ``|=``, ``^=``, ``<<=``, ``>>=``).
58
58
  * `Free-threading support <https://github.com/ilanschnell/bitarray/blob/master/doc/free_threading.rst>`__
59
59
  (for GIL-disabled CPython 3.14 and later)
60
- * Fast methods for encoding and decoding variable-length prefix codes.
60
+ * Fast methods for encoding and decoding variable-length
61
+ `prefix codes <https://github.com/ilanschnell/bitarray/blob/master/doc/prefix_codes.rst>`__.
61
62
  * Bitarray objects support the `buffer protocol <https://github.com/ilanschnell/bitarray/blob/master/doc/buffer.rst>`__
62
63
  (both importing and exporting buffers).
63
64
  * Efficient packing and unpacking for interoperability with byte-oriented
64
- objects such as NumPy arrays.
65
+ objects such as `NumPy arrays <https://github.com/ilanschnell/bitarray/blob/master/doc/ndarray.rst>`__.
65
66
  * Pickling and unpickling of bitarray objects.
66
67
  * Immutable ``frozenbitarray`` objects which are hashable
67
68
  * Fast searching for bits and bit patterns
@@ -100,8 +101,8 @@ Once you have installed the package, you may want to test it:
100
101
  $ python -c 'import bitarray; bitarray.test()'
101
102
  bitarray is installed in: /Users/ilan/bitarray/bitarray
102
103
  sys.prefix: /Users/ilan/miniforge
103
- bitarray version: 3.12.0
104
- sys.version: 3.14.5 (main, May 20 2026) [Clang 20.1.8]
104
+ bitarray version: 3.12.2
105
+ sys.version: 3.15.0 (main, Oct 9 2026) [Clang 21.1.8]
105
106
  sys.abiflags: ''
106
107
  sys._is_gil_enabled(): True
107
108
  pointer size: 64 bit
@@ -117,7 +118,7 @@ Once you have installed the package, you may want to test it:
117
118
  ..........s.....................................s........................
118
119
  ......s.........................................................
119
120
  ----------------------------------------------------------------------
120
- Ran 711 tests in 0.196s
121
+ Ran 711 tests in 0.161s
121
122
 
122
123
  OK (skipped=4)
123
124
 
@@ -289,59 +290,6 @@ this topic, please read `buffer protocol <https://github.com/ilanschnell/bitarra
289
290
  to memory-map a file to a bitarray: `mmapped-file.py <https://github.com/ilanschnell/bitarray/blob/master/examples/mmapped-file.py>`__
290
291
 
291
292
 
292
- Variable-length prefix codes
293
- ----------------------------
294
-
295
- The ``.encode()`` method takes a dictionary mapping symbols to bitarrays
296
- and an iterable, and extends the bitarray object with the encoded symbols
297
- found while iterating. For example:
298
-
299
- .. code-block:: python
300
-
301
- >>> d = {'H':bitarray('111'), 'e':bitarray('0'),
302
- ... 'l':bitarray('110'), 'o':bitarray('10')}
303
- ...
304
- >>> a = bitarray()
305
- >>> a.encode(d, 'Hello')
306
- >>> a
307
- bitarray('111011011010')
308
-
309
- Note that the string ``'Hello'`` is an iterable, but the symbols are not
310
- limited to characters, in fact any immutable Python object can be a symbol.
311
- Taking the same dictionary, we can apply the ``.decode()`` method which will
312
- return an iterable of the symbols:
313
-
314
- .. code-block:: python
315
-
316
- >>> list(a.decode(d))
317
- ['H', 'e', 'l', 'l', 'o']
318
- >>> ''.join(a.decode(d))
319
- 'Hello'
320
-
321
- Symbols are not limited to being characters.
322
- The above dictionary ``d`` can be efficiently constructed using the function
323
- ``bitarray.util.huffman_code()``. I also wrote `Huffman coding in Python
324
- using bitarray <http://ilan.schnell-web.net/prog/huffman/>`__ for more
325
- background information.
326
-
327
- When the codes are large, and you have many decode calls, most time will
328
- be spent creating the (same) internal decode tree objects. In this case,
329
- it will be much faster to create a ``decodetree`` object, which can be
330
- passed to bitarray's ``.decode()`` method, instead of passing the prefix
331
- code dictionary to those methods itself:
332
-
333
- .. code-block:: python
334
-
335
- >>> from bitarray import bitarray, decodetree
336
- >>> t = decodetree({'a': bitarray('0'), 'b': bitarray('1')})
337
- >>> a = bitarray('0110')
338
- >>> list(a.decode(t))
339
- ['a', 'b', 'b', 'a']
340
-
341
- The sole purpose of the immutable ``decodetree`` object is to be passed
342
- to bitarray's ``.decode()`` method.
343
-
344
-
345
293
  Frozenbitarrays
346
294
  ---------------
347
295
 
@@ -364,7 +312,7 @@ and can therefore be used as a dictionary key:
364
312
  Reference
365
313
  =========
366
314
 
367
- bitarray version: 3.12.0 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
315
+ bitarray version: 3.12.2 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
368
316
 
369
317
  In the following, ``item`` and ``value`` are usually a single bit -
370
318
  an integer 0 or 1.
@@ -475,7 +423,7 @@ bitarray methods:
475
423
  corresponding symbols.
476
424
  The prefix code length cannot exceed 256 bits.
477
425
 
478
- See also: `Bitarray 3 transition <https://github.com/ilanschnell/bitarray/blob/master/doc/bitarray3.rst>`__
426
+ See also: `Bitarray 3 transition <https://github.com/ilanschnell/bitarray/blob/master/doc/bitarray3.rst>`__, `Variable-length prefix codes <https://github.com/ilanschnell/bitarray/blob/master/doc/prefix_codes.rst>`__
479
427
 
480
428
  New in version 3.0: returns iterator (equivalent to past ``.iterdecode()``)
481
429
 
@@ -487,6 +435,8 @@ bitarray methods:
487
435
  iterate over the iterable object with symbols, and extend bitarray
488
436
  with corresponding bitarray for each symbol.
489
437
 
438
+ See also: `Variable-length prefix codes <https://github.com/ilanschnell/bitarray/blob/master/doc/prefix_codes.rst>`__
439
+
490
440
 
491
441
  ``extend(iterable, /)``
492
442
  Append items from iterable to the end of the bitarray.
@@ -725,6 +675,8 @@ Other objects:
725
675
  create a binary tree object to be passed to ``.decode()``.
726
676
  The prefix code length cannot exceed 256 bits.
727
677
 
678
+ See also: `Variable-length prefix codes <https://github.com/ilanschnell/bitarray/blob/master/doc/prefix_codes.rst>`__
679
+
728
680
  New in version 1.6
729
681
 
730
682
 
@@ -911,6 +863,8 @@ This sub-module was added in version 1.2.
911
863
  frozenbitarrays (with given bit-endianness). Note that the symbols are not
912
864
  limited to being strings. Symbols may be any hashable object.
913
865
 
866
+ See also: `Variable-length prefix codes <https://github.com/ilanschnell/bitarray/blob/master/doc/prefix_codes.rst>`__
867
+
914
868
  New in version 3.10: return a codedict mapping to frozenbitarrays
915
869
 
916
870
 
@@ -21,11 +21,12 @@ Key features
21
21
  their in-place versions ``&=``, ``|=``, ``^=``, ``<<=``, ``>>=``).
22
22
  * `Free-threading support <https://github.com/ilanschnell/bitarray/blob/master/doc/free_threading.rst>`__
23
23
  (for GIL-disabled CPython 3.14 and later)
24
- * Fast methods for encoding and decoding variable-length prefix codes.
24
+ * Fast methods for encoding and decoding variable-length
25
+ `prefix codes <https://github.com/ilanschnell/bitarray/blob/master/doc/prefix_codes.rst>`__.
25
26
  * Bitarray objects support the `buffer protocol <https://github.com/ilanschnell/bitarray/blob/master/doc/buffer.rst>`__
26
27
  (both importing and exporting buffers).
27
28
  * Efficient packing and unpacking for interoperability with byte-oriented
28
- objects such as NumPy arrays.
29
+ objects such as `NumPy arrays <https://github.com/ilanschnell/bitarray/blob/master/doc/ndarray.rst>`__.
29
30
  * Pickling and unpickling of bitarray objects.
30
31
  * Immutable ``frozenbitarray`` objects which are hashable
31
32
  * Fast searching for bits and bit patterns
@@ -64,8 +65,8 @@ Once you have installed the package, you may want to test it:
64
65
  $ python -c 'import bitarray; bitarray.test()'
65
66
  bitarray is installed in: /Users/ilan/bitarray/bitarray
66
67
  sys.prefix: /Users/ilan/miniforge
67
- bitarray version: 3.12.0
68
- sys.version: 3.14.5 (main, May 20 2026) [Clang 20.1.8]
68
+ bitarray version: 3.12.2
69
+ sys.version: 3.15.0 (main, Oct 9 2026) [Clang 21.1.8]
69
70
  sys.abiflags: ''
70
71
  sys._is_gil_enabled(): True
71
72
  pointer size: 64 bit
@@ -81,7 +82,7 @@ Once you have installed the package, you may want to test it:
81
82
  ..........s.....................................s........................
82
83
  ......s.........................................................
83
84
  ----------------------------------------------------------------------
84
- Ran 711 tests in 0.196s
85
+ Ran 711 tests in 0.161s
85
86
 
86
87
  OK (skipped=4)
87
88
 
@@ -253,59 +254,6 @@ this topic, please read `buffer protocol <https://github.com/ilanschnell/bitarra
253
254
  to memory-map a file to a bitarray: `mmapped-file.py <https://github.com/ilanschnell/bitarray/blob/master/examples/mmapped-file.py>`__
254
255
 
255
256
 
256
- Variable-length prefix codes
257
- ----------------------------
258
-
259
- The ``.encode()`` method takes a dictionary mapping symbols to bitarrays
260
- and an iterable, and extends the bitarray object with the encoded symbols
261
- found while iterating. For example:
262
-
263
- .. code-block:: python
264
-
265
- >>> d = {'H':bitarray('111'), 'e':bitarray('0'),
266
- ... 'l':bitarray('110'), 'o':bitarray('10')}
267
- ...
268
- >>> a = bitarray()
269
- >>> a.encode(d, 'Hello')
270
- >>> a
271
- bitarray('111011011010')
272
-
273
- Note that the string ``'Hello'`` is an iterable, but the symbols are not
274
- limited to characters, in fact any immutable Python object can be a symbol.
275
- Taking the same dictionary, we can apply the ``.decode()`` method which will
276
- return an iterable of the symbols:
277
-
278
- .. code-block:: python
279
-
280
- >>> list(a.decode(d))
281
- ['H', 'e', 'l', 'l', 'o']
282
- >>> ''.join(a.decode(d))
283
- 'Hello'
284
-
285
- Symbols are not limited to being characters.
286
- The above dictionary ``d`` can be efficiently constructed using the function
287
- ``bitarray.util.huffman_code()``. I also wrote `Huffman coding in Python
288
- using bitarray <http://ilan.schnell-web.net/prog/huffman/>`__ for more
289
- background information.
290
-
291
- When the codes are large, and you have many decode calls, most time will
292
- be spent creating the (same) internal decode tree objects. In this case,
293
- it will be much faster to create a ``decodetree`` object, which can be
294
- passed to bitarray's ``.decode()`` method, instead of passing the prefix
295
- code dictionary to those methods itself:
296
-
297
- .. code-block:: python
298
-
299
- >>> from bitarray import bitarray, decodetree
300
- >>> t = decodetree({'a': bitarray('0'), 'b': bitarray('1')})
301
- >>> a = bitarray('0110')
302
- >>> list(a.decode(t))
303
- ['a', 'b', 'b', 'a']
304
-
305
- The sole purpose of the immutable ``decodetree`` object is to be passed
306
- to bitarray's ``.decode()`` method.
307
-
308
-
309
257
  Frozenbitarrays
310
258
  ---------------
311
259
 
@@ -328,7 +276,7 @@ and can therefore be used as a dictionary key:
328
276
  Reference
329
277
  =========
330
278
 
331
- bitarray version: 3.12.0 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
279
+ bitarray version: 3.12.2 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
332
280
 
333
281
  In the following, ``item`` and ``value`` are usually a single bit -
334
282
  an integer 0 or 1.
@@ -439,7 +387,7 @@ bitarray methods:
439
387
  corresponding symbols.
440
388
  The prefix code length cannot exceed 256 bits.
441
389
 
442
- See also: `Bitarray 3 transition <https://github.com/ilanschnell/bitarray/blob/master/doc/bitarray3.rst>`__
390
+ See also: `Bitarray 3 transition <https://github.com/ilanschnell/bitarray/blob/master/doc/bitarray3.rst>`__, `Variable-length prefix codes <https://github.com/ilanschnell/bitarray/blob/master/doc/prefix_codes.rst>`__
443
391
 
444
392
  New in version 3.0: returns iterator (equivalent to past ``.iterdecode()``)
445
393
 
@@ -451,6 +399,8 @@ bitarray methods:
451
399
  iterate over the iterable object with symbols, and extend bitarray
452
400
  with corresponding bitarray for each symbol.
453
401
 
402
+ See also: `Variable-length prefix codes <https://github.com/ilanschnell/bitarray/blob/master/doc/prefix_codes.rst>`__
403
+
454
404
 
455
405
  ``extend(iterable, /)``
456
406
  Append items from iterable to the end of the bitarray.
@@ -689,6 +639,8 @@ Other objects:
689
639
  create a binary tree object to be passed to ``.decode()``.
690
640
  The prefix code length cannot exceed 256 bits.
691
641
 
642
+ See also: `Variable-length prefix codes <https://github.com/ilanschnell/bitarray/blob/master/doc/prefix_codes.rst>`__
643
+
692
644
  New in version 1.6
693
645
 
694
646
 
@@ -875,6 +827,8 @@ This sub-module was added in version 1.2.
875
827
  frozenbitarrays (with given bit-endianness). Note that the symbols are not
876
828
  limited to being strings. Symbols may be any hashable object.
877
829
 
830
+ See also: `Variable-length prefix codes <https://github.com/ilanschnell/bitarray/blob/master/doc/prefix_codes.rst>`__
831
+
878
832
  New in version 3.10: return a codedict mapping to frozenbitarrays
879
833
 
880
834
 
@@ -236,7 +236,7 @@ shift_r8le(unsigned char *buff, Py_ssize_t n, int k)
236
236
  if (n || w) /* add shifted next lower byte */
237
237
  buff[i] |= buff[i - 1] >> (8 - k);
238
238
  }
239
- assert(w == 0 || ((uintptr_t) buff) % 4 == 0);
239
+ assert(w == 0 || ((uintptr_t) buff) % 8 == 0);
240
240
  while (w--) { /* shift in word-range(0, w) */
241
241
  uint64_t *p = ((uint64_t *) buff) + w;
242
242
  #if HAVE_BUILTIN_BSWAP64 && PY_BIG_ENDIAN
@@ -266,7 +266,7 @@ shift_r8be(unsigned char *buff, Py_ssize_t n, int k)
266
266
  if (n || w) /* add shifted next lower byte */
267
267
  buff[i] |= buff[i - 1] << (8 - k);
268
268
  }
269
- assert(w == 0 || ((uintptr_t) buff) % 4 == 0);
269
+ assert(w == 0 || ((uintptr_t) buff) % 8 == 0);
270
270
  while (w--) { /* shift in word-range(0, w) */
271
271
  uint64_t *p = ((uint64_t *) buff) + w;
272
272
  #if HAVE_BUILTIN_BSWAP64 && PY_LITTLE_ENDIAN
@@ -854,6 +854,12 @@ When grouped, the string `sep` is inserted between groups\n\
854
854
  of `group` characters, default is a space.");
855
855
 
856
856
 
857
+ static int
858
+ ascii_isspace(unsigned char c) /* Py_ISSPACE is not defined on PyPy */
859
+ {
860
+ return c == ' ' || ('\t' <= c && c <= '\r');
861
+ }
862
+
857
863
  /* Translate hexadecimal digits from 'hexstr' into the bitarray 'a' buffer,
858
864
  which must be initialized to zeros.
859
865
  Each digit corresponds to 4 bits in the bitarray.
@@ -872,7 +878,7 @@ hex2ba_lock_held(bitarrayobject *a, Py_buffer hexstr)
872
878
  int x = hex_to_int(c);
873
879
 
874
880
  if (x < 0) {
875
- if (Py_ISSPACE(c)) /* ASCII whitespace */
881
+ if (ascii_isspace(c))
876
882
  continue;
877
883
  PyErr_Format(PyExc_ValueError, "invalid digit found for "
878
884
  "base16, got '%c' (0x%02x)", c, c);
@@ -1105,7 +1111,7 @@ base2ba_lock_held(bitarrayobject *a, Py_buffer asciistr, int m)
1105
1111
  int k, x = digit_to_int(m, c);
1106
1112
 
1107
1113
  if (x < 0) {
1108
- if (Py_ISSPACE(c)) /* ASCII whitespace */
1114
+ if (ascii_isspace(c))
1109
1115
  continue;
1110
1116
  PyErr_Format(PyExc_ValueError, "invalid digit found for "
1111
1117
  "base%d, got '%c' (0x%02x)", 1 << m, c, c);
@@ -4,7 +4,7 @@
4
4
 
5
5
  Author: Ilan Schnell
6
6
  */
7
- #define BITARRAY_VERSION "3.12.0"
7
+ #define BITARRAY_VERSION "3.12.2"
8
8
 
9
9
  #ifdef STDC_HEADERS
10
10
  # include <stddef.h>
@@ -247,15 +247,15 @@ setup_table(char *table, char kop)
247
247
  }
248
248
  }
249
249
 
250
- /* Return distance [0..3] to next aligned pointer.
250
+ /* Return distance [0..7] to next aligned pointer.
251
251
  While on modern compilers uint64_t pointers may be misaligned, it may
252
252
  cause problems on older ones. Moreover, it may lead to slowdown (even
253
253
  on modern compilers). */
254
254
  static inline int
255
255
  to_aligned(void *p)
256
256
  {
257
- int r = ((uintptr_t) p) % 4;
258
- return (4 - r) % 4;
257
+ int r = ((uintptr_t) p) % 8;
258
+ return (8 - r) % 8;
259
259
  }
260
260
 
261
261
  /* population count of n words starting at uint64_t pointer w */
@@ -264,7 +264,8 @@ popcnt_words(uint64_t *w, Py_ssize_t n)
264
264
  {
265
265
  Py_ssize_t cnt = 0;
266
266
 
267
- assert(n >= 0 && ((uintptr_t) w) % 4 == 0);
267
+ assert(n >= 0);
268
+ assert(n == 0 || ((uintptr_t) w) % 8 == 0);
268
269
  while (n--)
269
270
  cnt += popcnt_64(*w++);
270
271
  return cnt;