bitarray 3.7.1__tar.gz → 3.7.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.
- {bitarray-3.7.1 → bitarray-3.7.2}/PKG-INFO +11 -9
- {bitarray-3.7.1 → bitarray-3.7.2}/README.rst +9 -8
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/__init__.py +5 -6
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/_bitarray.c +12 -12
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/_util.c +2 -1
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/bitarray.h +3 -2
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/test_bitarray.py +8 -10
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/test_util.py +14 -22
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/util.py +6 -12
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray.egg-info/PKG-INFO +11 -9
- {bitarray-3.7.1 → bitarray-3.7.2}/setup.py +2 -1
- {bitarray-3.7.1 → bitarray-3.7.2}/LICENSE +0 -0
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/__init__.pyi +0 -0
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/py.typed +0 -0
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/pythoncapi_compat.h +0 -0
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/test_281.pickle +0 -0
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray/util.pyi +0 -0
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray.egg-info/SOURCES.txt +0 -0
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray.egg-info/dependency_links.txt +0 -0
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray.egg-info/not-zip-safe +0 -0
- {bitarray-3.7.1 → bitarray-3.7.2}/bitarray.egg-info/top_level.txt +0 -0
- {bitarray-3.7.1 → bitarray-3.7.2}/pyproject.toml +0 -0
- {bitarray-3.7.1 → bitarray-3.7.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bitarray
|
|
3
|
-
Version: 3.7.
|
|
3
|
+
Version: 3.7.2
|
|
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.10
|
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
23
|
Classifier: Topic :: Utilities
|
|
23
24
|
License-File: LICENSE
|
|
24
25
|
Dynamic: author
|
|
@@ -76,7 +77,7 @@ Key features
|
|
|
76
77
|
Installation
|
|
77
78
|
------------
|
|
78
79
|
|
|
79
|
-
Python wheels are are available on PyPI for all
|
|
80
|
+
Python wheels are are available on PyPI for all major platforms and Python
|
|
80
81
|
versions. Which means you can simply:
|
|
81
82
|
|
|
82
83
|
.. code-block:: shell-session
|
|
@@ -89,7 +90,7 @@ Once you have installed the package, you may want to test it:
|
|
|
89
90
|
|
|
90
91
|
$ python -c 'import bitarray; bitarray.test()'
|
|
91
92
|
bitarray is installed in: /Users/ilan/bitarray/bitarray
|
|
92
|
-
bitarray version: 3.7.
|
|
93
|
+
bitarray version: 3.7.2
|
|
93
94
|
sys.version: 3.13.5 (main, Jun 16 2025) [Clang 18.1.8]
|
|
94
95
|
sys.prefix: /Users/ilan/miniforge
|
|
95
96
|
pointer size: 64 bit
|
|
@@ -351,7 +352,7 @@ and can therefore be used as a dictionary key:
|
|
|
351
352
|
Reference
|
|
352
353
|
=========
|
|
353
354
|
|
|
354
|
-
bitarray version: 3.7.
|
|
355
|
+
bitarray version: 3.7.2 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
|
|
355
356
|
|
|
356
357
|
In the following, ``item`` and ``value`` are usually a single bit -
|
|
357
358
|
an integer 0 or 1.
|
|
@@ -729,6 +730,11 @@ This sub-module was added in version 1.2.
|
|
|
729
730
|
Also, ``a`` may be any object that exposes a writable buffer.
|
|
730
731
|
Nothing about this function is specific to bitarray objects.
|
|
731
732
|
|
|
733
|
+
We should mention that Python's ``array.array`` object has a
|
|
734
|
+
method ``.byteswap()`` with similar functionality. However, unlike
|
|
735
|
+
bitarray's ``util.byteswap()`` function, this method is limited to
|
|
736
|
+
swapping 2, 4, or 8 consecutive bytes.
|
|
737
|
+
|
|
732
738
|
New in version 3.4
|
|
733
739
|
|
|
734
740
|
|
|
@@ -870,11 +876,7 @@ This sub-module was added in version 1.2.
|
|
|
870
876
|
set to one. Mathematically equivalent to setting (in a bitarray of
|
|
871
877
|
length ``n``) all bits at indices ``random.sample(range(n), k)`` to one.
|
|
872
878
|
The random bitarrays are reproducible when giving Python's ``random.seed()``
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
This function requires Python 3.9 or higher, as it depends on the standard
|
|
876
|
-
library function ``random.randbytes()``. Raises ``NotImplementedError``
|
|
877
|
-
when Python version is too low.
|
|
879
|
+
a specific seed value.
|
|
878
880
|
|
|
879
881
|
New in version 3.6
|
|
880
882
|
|
|
@@ -44,7 +44,7 @@ Key features
|
|
|
44
44
|
Installation
|
|
45
45
|
------------
|
|
46
46
|
|
|
47
|
-
Python wheels are are available on PyPI for all
|
|
47
|
+
Python wheels are are available on PyPI for all major platforms and Python
|
|
48
48
|
versions. Which means you can simply:
|
|
49
49
|
|
|
50
50
|
.. code-block:: shell-session
|
|
@@ -57,7 +57,7 @@ Once you have installed the package, you may want to test it:
|
|
|
57
57
|
|
|
58
58
|
$ python -c 'import bitarray; bitarray.test()'
|
|
59
59
|
bitarray is installed in: /Users/ilan/bitarray/bitarray
|
|
60
|
-
bitarray version: 3.7.
|
|
60
|
+
bitarray version: 3.7.2
|
|
61
61
|
sys.version: 3.13.5 (main, Jun 16 2025) [Clang 18.1.8]
|
|
62
62
|
sys.prefix: /Users/ilan/miniforge
|
|
63
63
|
pointer size: 64 bit
|
|
@@ -319,7 +319,7 @@ and can therefore be used as a dictionary key:
|
|
|
319
319
|
Reference
|
|
320
320
|
=========
|
|
321
321
|
|
|
322
|
-
bitarray version: 3.7.
|
|
322
|
+
bitarray version: 3.7.2 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
|
|
323
323
|
|
|
324
324
|
In the following, ``item`` and ``value`` are usually a single bit -
|
|
325
325
|
an integer 0 or 1.
|
|
@@ -697,6 +697,11 @@ This sub-module was added in version 1.2.
|
|
|
697
697
|
Also, ``a`` may be any object that exposes a writable buffer.
|
|
698
698
|
Nothing about this function is specific to bitarray objects.
|
|
699
699
|
|
|
700
|
+
We should mention that Python's ``array.array`` object has a
|
|
701
|
+
method ``.byteswap()`` with similar functionality. However, unlike
|
|
702
|
+
bitarray's ``util.byteswap()`` function, this method is limited to
|
|
703
|
+
swapping 2, 4, or 8 consecutive bytes.
|
|
704
|
+
|
|
700
705
|
New in version 3.4
|
|
701
706
|
|
|
702
707
|
|
|
@@ -838,11 +843,7 @@ This sub-module was added in version 1.2.
|
|
|
838
843
|
set to one. Mathematically equivalent to setting (in a bitarray of
|
|
839
844
|
length ``n``) all bits at indices ``random.sample(range(n), k)`` to one.
|
|
840
845
|
The random bitarrays are reproducible when giving Python's ``random.seed()``
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
This function requires Python 3.9 or higher, as it depends on the standard
|
|
844
|
-
library function ``random.randbytes()``. Raises ``NotImplementedError``
|
|
845
|
-
when Python version is too low.
|
|
846
|
+
a specific seed value.
|
|
846
847
|
|
|
847
848
|
New in version 3.6
|
|
848
849
|
|
|
@@ -9,14 +9,13 @@ Please find a description of this package at:
|
|
|
9
9
|
|
|
10
10
|
Author: Ilan Schnell
|
|
11
11
|
"""
|
|
12
|
-
from __future__ import absolute_import
|
|
13
12
|
from collections import namedtuple
|
|
14
13
|
|
|
15
|
-
from bitarray._bitarray import (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
from bitarray._bitarray import (
|
|
15
|
+
bitarray, decodetree, bits2bytes, _bitarray_reconstructor,
|
|
16
|
+
get_default_endian, _set_default_endian, _sysinfo,
|
|
17
|
+
BITARRAY_VERSION as __version__
|
|
18
|
+
)
|
|
20
19
|
|
|
21
20
|
__all__ = ['bitarray', 'frozenbitarray', 'decodetree', 'bits2bytes']
|
|
22
21
|
|
|
@@ -1323,9 +1323,8 @@ bitarray_invert(bitarrayobject *self, PyObject *args)
|
|
|
1323
1323
|
return NULL;
|
|
1324
1324
|
}
|
|
1325
1325
|
self->ob_item[i / 8] ^= BITMASK(self, i);
|
|
1326
|
-
Py_RETURN_NONE;
|
|
1327
1326
|
}
|
|
1328
|
-
if (PySlice_Check(arg)) {
|
|
1327
|
+
else if (PySlice_Check(arg)) {
|
|
1329
1328
|
Py_ssize_t start, stop, step, slicelength;
|
|
1330
1329
|
|
|
1331
1330
|
if (PySlice_GetIndicesEx(arg, self->nbits,
|
|
@@ -1333,15 +1332,15 @@ bitarray_invert(bitarrayobject *self, PyObject *args)
|
|
|
1333
1332
|
return NULL;
|
|
1334
1333
|
adjust_step_positive(slicelength, &start, &stop, &step);
|
|
1335
1334
|
invert_range(self, start, stop, step);
|
|
1336
|
-
Py_RETURN_NONE;
|
|
1337
1335
|
}
|
|
1338
|
-
if (arg == Py_None) {
|
|
1336
|
+
else if (arg == Py_None) {
|
|
1339
1337
|
invert_span(self, 0, self->nbits);
|
|
1340
|
-
Py_RETURN_NONE;
|
|
1341
1338
|
}
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1339
|
+
else {
|
|
1340
|
+
return PyErr_Format(PyExc_TypeError, "index expect, not '%s' object",
|
|
1341
|
+
Py_TYPE(arg)->tp_name);
|
|
1342
|
+
}
|
|
1343
|
+
Py_RETURN_NONE;
|
|
1345
1344
|
}
|
|
1346
1345
|
|
|
1347
1346
|
PyDoc_STRVAR(invert_doc,
|
|
@@ -3613,7 +3612,7 @@ endian_from_string(const char *str)
|
|
|
3613
3612
|
return ENDIAN_BIG;
|
|
3614
3613
|
|
|
3615
3614
|
PyErr_Format(PyExc_ValueError, "bit-endianness must be either "
|
|
3616
|
-
|
|
3615
|
+
"'little' or 'big', not '%s'", str);
|
|
3617
3616
|
return -1;
|
|
3618
3617
|
}
|
|
3619
3618
|
|
|
@@ -4193,7 +4192,8 @@ sysinfo(PyObject *module, PyObject *args)
|
|
|
4193
4192
|
R("DEBUG", 0);
|
|
4194
4193
|
#endif
|
|
4195
4194
|
|
|
4196
|
-
|
|
4195
|
+
PyErr_SetString(PyExc_KeyError, key);
|
|
4196
|
+
return NULL;
|
|
4197
4197
|
#undef R
|
|
4198
4198
|
}
|
|
4199
4199
|
|
|
@@ -4287,8 +4287,8 @@ PyInit__bitarray(void)
|
|
|
4287
4287
|
return NULL;
|
|
4288
4288
|
Py_SET_TYPE(&SearchIter_Type, &PyType_Type);
|
|
4289
4289
|
|
|
4290
|
-
|
|
4291
|
-
|
|
4290
|
+
if (PyModule_AddStringMacro(m, BITARRAY_VERSION) < 0)
|
|
4291
|
+
return NULL;
|
|
4292
4292
|
|
|
4293
4293
|
return m;
|
|
4294
4294
|
}
|
|
@@ -2254,7 +2254,8 @@ PyInit__util(void)
|
|
|
2254
2254
|
Py_SET_TYPE(&CHDI_Type, &PyType_Type);
|
|
2255
2255
|
|
|
2256
2256
|
#ifndef NDEBUG /* expose segment size in debug mode for testing */
|
|
2257
|
-
|
|
2257
|
+
if (PyModule_AddIntConstant(m, "_SEGSIZE", SEGSIZE) < 0)
|
|
2258
|
+
return NULL;
|
|
2258
2259
|
#endif
|
|
2259
2260
|
|
|
2260
2261
|
return m;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Author: Ilan Schnell
|
|
6
6
|
*/
|
|
7
|
-
#define BITARRAY_VERSION "3.7.
|
|
7
|
+
#define BITARRAY_VERSION "3.7.2"
|
|
8
8
|
|
|
9
9
|
#ifdef STDC_HEADERS
|
|
10
10
|
# include <stddef.h>
|
|
@@ -233,7 +233,7 @@ setup_table(char *table, char kop)
|
|
|
233
233
|
for (k = 0; k < 256; k++) {
|
|
234
234
|
char t = 0, j;
|
|
235
235
|
for (j = 0; j < 8; j++) {
|
|
236
|
-
if (k & 1 << j)
|
|
236
|
+
if (k & 1 << j) {
|
|
237
237
|
/* j are the indices of active bits in k (little endian) */
|
|
238
238
|
switch (kop) {
|
|
239
239
|
case 'a': t += j; break; /* add active indices */
|
|
@@ -249,6 +249,7 @@ setup_table(char *table, char kop)
|
|
|
249
249
|
case 'r': t |= 128 >> j; break; /* reverse bits */
|
|
250
250
|
default: Py_UNREACHABLE();
|
|
251
251
|
}
|
|
252
|
+
}
|
|
252
253
|
}
|
|
253
254
|
table[k] = t;
|
|
254
255
|
}
|
|
@@ -7,8 +7,6 @@ Tests for bitarray
|
|
|
7
7
|
|
|
8
8
|
Author: Ilan Schnell
|
|
9
9
|
"""
|
|
10
|
-
from __future__ import absolute_import
|
|
11
|
-
|
|
12
10
|
import re
|
|
13
11
|
import os
|
|
14
12
|
import sys
|
|
@@ -17,7 +15,7 @@ import unittest
|
|
|
17
15
|
import shutil
|
|
18
16
|
import tempfile
|
|
19
17
|
from io import BytesIO, UnsupportedOperation
|
|
20
|
-
from random import choice, getrandbits, randrange, randint, shuffle
|
|
18
|
+
from random import choice, choices, getrandbits, randrange, randint, shuffle
|
|
21
19
|
from string import whitespace
|
|
22
20
|
|
|
23
21
|
# imports needed inside tests
|
|
@@ -1409,7 +1407,7 @@ class GetSequenceIndexTests(unittest.TestCase, Util):
|
|
|
1409
1407
|
def test_random(self):
|
|
1410
1408
|
for a in self.randombitarrays():
|
|
1411
1409
|
n = len(a)
|
|
1412
|
-
lst =
|
|
1410
|
+
lst = choices(range(n), k=n//2)
|
|
1413
1411
|
b = a[lst]
|
|
1414
1412
|
self.assertEqual(b, bitarray(a[i] for i in lst))
|
|
1415
1413
|
self.assertEqual(b.endian, a.endian)
|
|
@@ -1442,7 +1440,7 @@ class SetSequenceIndexTests(unittest.TestCase, Util):
|
|
|
1442
1440
|
def test_bool_random(self):
|
|
1443
1441
|
for a in self.randombitarrays():
|
|
1444
1442
|
n = len(a)
|
|
1445
|
-
lst =
|
|
1443
|
+
lst = choices(range(n), k=n//2)
|
|
1446
1444
|
b = a.copy()
|
|
1447
1445
|
v = getrandbits(1)
|
|
1448
1446
|
a[lst] = v
|
|
@@ -1476,7 +1474,7 @@ class SetSequenceIndexTests(unittest.TestCase, Util):
|
|
|
1476
1474
|
def test_bitarray_random(self):
|
|
1477
1475
|
for a in self.randombitarrays():
|
|
1478
1476
|
n = len(a)
|
|
1479
|
-
lst =
|
|
1477
|
+
lst = choices(range(n), k=n//2)
|
|
1480
1478
|
c = urandom_2(len(lst))
|
|
1481
1479
|
b = a.copy()
|
|
1482
1480
|
|
|
@@ -1547,7 +1545,7 @@ class DelSequenceIndexTests(unittest.TestCase, Util):
|
|
|
1547
1545
|
def test_random(self):
|
|
1548
1546
|
for n in range(100):
|
|
1549
1547
|
a = urandom_2(n)
|
|
1550
|
-
lst =
|
|
1548
|
+
lst = choices(range(n), k=randint(0, n))
|
|
1551
1549
|
b = a.copy()
|
|
1552
1550
|
del a[lst]
|
|
1553
1551
|
self.assertEqual(len(a), n - len(set(lst)))
|
|
@@ -3233,7 +3231,7 @@ class To01Tests(unittest.TestCase, Util):
|
|
|
3233
3231
|
def test_sep(self):
|
|
3234
3232
|
for a in self.randombitarrays():
|
|
3235
3233
|
sep = "".join(chr(randint(32, 126))
|
|
3236
|
-
|
|
3234
|
+
for _ in range(randrange(10)))
|
|
3237
3235
|
self.assertEqual(a.to01(1, sep), sep.join(str(v) for v in a))
|
|
3238
3236
|
|
|
3239
3237
|
a = bitarray("11100111")
|
|
@@ -3445,7 +3443,7 @@ class CountTests(unittest.TestCase, Util):
|
|
|
3445
3443
|
def test_sparse(self):
|
|
3446
3444
|
n = 65536
|
|
3447
3445
|
a = bitarray(n)
|
|
3448
|
-
indices = set(
|
|
3446
|
+
indices = set(choices(range(n), k=256))
|
|
3449
3447
|
a[list(indices)] = 1
|
|
3450
3448
|
self.assertEqual(a.count(1), len(indices))
|
|
3451
3449
|
self.assertEqual(a.count(0), n - len(indices))
|
|
@@ -3636,7 +3634,7 @@ class IndexTests(unittest.TestCase, Util):
|
|
|
3636
3634
|
for _ in range(500):
|
|
3637
3635
|
n = randrange(1, 200)
|
|
3638
3636
|
a = zeros(n)
|
|
3639
|
-
plst = sorted(
|
|
3637
|
+
plst = sorted(choices(range(n), k=9))
|
|
3640
3638
|
a[plst] = 1
|
|
3641
3639
|
# test without start and stop
|
|
3642
3640
|
self.assertEqual(a.find(1, right=0), plst[0])
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
"""
|
|
6
6
|
Tests for bitarray.util module
|
|
7
7
|
"""
|
|
8
|
-
from __future__ import absolute_import
|
|
9
|
-
|
|
10
8
|
import os
|
|
11
9
|
import sys
|
|
12
10
|
import math
|
|
@@ -20,8 +18,8 @@ import tempfile
|
|
|
20
18
|
import unittest
|
|
21
19
|
from io import StringIO
|
|
22
20
|
from functools import reduce
|
|
23
|
-
from random import (choice, getrandbits, randrange, randint, random,
|
|
24
|
-
seed)
|
|
21
|
+
from random import (choice, choices, getrandbits, randrange, randint, random,
|
|
22
|
+
sample, seed)
|
|
25
23
|
from string import hexdigits, whitespace
|
|
26
24
|
from collections import Counter
|
|
27
25
|
|
|
@@ -120,16 +118,6 @@ class URandomTests(unittest.TestCase):
|
|
|
120
118
|
|
|
121
119
|
# ---------------------------- random_k() ---------------------------------
|
|
122
120
|
|
|
123
|
-
HAVE_RANDBYTES = sys.version_info[:2] >= (3, 9)
|
|
124
|
-
|
|
125
|
-
@skipIf(HAVE_RANDBYTES)
|
|
126
|
-
class Random_K_Not_Implemented(unittest.TestCase):
|
|
127
|
-
|
|
128
|
-
def test_not_implemented(self):
|
|
129
|
-
self.assertRaises(NotImplementedError, random_k, 100, 60)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
@skipIf(not HAVE_RANDBYTES)
|
|
133
121
|
class Random_K_Tests(unittest.TestCase):
|
|
134
122
|
|
|
135
123
|
def test_basic(self):
|
|
@@ -189,6 +177,8 @@ class Random_K_Tests(unittest.TestCase):
|
|
|
189
177
|
else:
|
|
190
178
|
self.fail()
|
|
191
179
|
|
|
180
|
+
# test uses math.comb, added in 3.8
|
|
181
|
+
@skipIf(sys.version_info[:2] < (3, 8))
|
|
192
182
|
def test_combinations(self):
|
|
193
183
|
# for entire range of 0 <= k <= n, validate that random_k()
|
|
194
184
|
# generates all possible combinations
|
|
@@ -227,7 +217,8 @@ class Random_K_Tests(unittest.TestCase):
|
|
|
227
217
|
a.append(self.collect_code_branches())
|
|
228
218
|
self.assertEqual(a[0], a[2])
|
|
229
219
|
self.assertEqual(a[1], a[3])
|
|
230
|
-
|
|
220
|
+
for item0, item1 in zip(a[0], a[1]):
|
|
221
|
+
self.assertNotEqual(item0, item1)
|
|
231
222
|
# initialize seed with current system time again
|
|
232
223
|
seed()
|
|
233
224
|
|
|
@@ -341,7 +332,7 @@ class Random_P_Tests(unittest.TestCase):
|
|
|
341
332
|
def collect_code_branches(self):
|
|
342
333
|
# return list of bitarrays from all code branches of random_p()
|
|
343
334
|
res = []
|
|
344
|
-
# for default p=0.5, random_p uses
|
|
335
|
+
# for default p=0.5, random_p uses getrandbits
|
|
345
336
|
res.append(random_p(32))
|
|
346
337
|
# test small p
|
|
347
338
|
res.append(random_p(5_000, 0.002))
|
|
@@ -363,7 +354,8 @@ class Random_P_Tests(unittest.TestCase):
|
|
|
363
354
|
a.append(self.collect_code_branches())
|
|
364
355
|
self.assertEqual(a[0], a[2])
|
|
365
356
|
self.assertEqual(a[1], a[3])
|
|
366
|
-
|
|
357
|
+
for item0, item1 in zip(a[0], a[1]):
|
|
358
|
+
self.assertNotEqual(item0, item1)
|
|
367
359
|
# initialize seed with current system time again
|
|
368
360
|
seed()
|
|
369
361
|
|
|
@@ -1588,7 +1580,7 @@ class BaseTests(unittest.TestCase, Util):
|
|
|
1588
1580
|
self.assertEqual(ba2base(16, a), 'f61')
|
|
1589
1581
|
|
|
1590
1582
|
for n in range(50):
|
|
1591
|
-
s = ''.join(
|
|
1583
|
+
s = ''.join(choices(hexdigits, k=n))
|
|
1592
1584
|
endian = self.random_endian()
|
|
1593
1585
|
a = base2ba(16, s, endian)
|
|
1594
1586
|
self.assertEQUAL(a, hex2ba(s, endian))
|
|
@@ -1884,7 +1876,7 @@ class SC_Tests(unittest.TestCase, Util):
|
|
|
1884
1876
|
|
|
1885
1877
|
def test_block_type3(self):
|
|
1886
1878
|
a = bitarray(16_777_216, 'little')
|
|
1887
|
-
a[
|
|
1879
|
+
a[choices(range(1 << 24), k=255)] = 1
|
|
1888
1880
|
b = bytearray([0x04, 0x00, 0x00, 0x00, 0x01, 0xc3, a.count()])
|
|
1889
1881
|
for i in a.search(1):
|
|
1890
1882
|
b.extend(struct.pack("<I", i)[:3])
|
|
@@ -1897,7 +1889,7 @@ class SC_Tests(unittest.TestCase, Util):
|
|
|
1897
1889
|
# To understand why we cannot have a population larger than 5 for
|
|
1898
1890
|
# an array size 4 times the size of a type 3 block, take a look
|
|
1899
1891
|
# at the cost comparison in sc_encode_block(). (2 + 6 >= 2 * 4)
|
|
1900
|
-
indices = sorted(set(
|
|
1892
|
+
indices = sorted(set(choices(range(len(a)), k=5)))
|
|
1901
1893
|
a[indices] = 1
|
|
1902
1894
|
b = bytearray(b'\x04\x00\x00\x00\x04\xc4')
|
|
1903
1895
|
b.append(len(indices))
|
|
@@ -2607,7 +2599,7 @@ class HuffmanTests(unittest.TestCase):
|
|
|
2607
2599
|
self.check_tree(code)
|
|
2608
2600
|
|
|
2609
2601
|
def test_random_list(self):
|
|
2610
|
-
plain =
|
|
2602
|
+
plain = choices(range(100), k=500)
|
|
2611
2603
|
code = huffman_code(Counter(plain))
|
|
2612
2604
|
a = bitarray()
|
|
2613
2605
|
a.encode(code, plain)
|
|
@@ -2856,7 +2848,7 @@ class CanonicalHuffmanTests(unittest.TestCase, Util):
|
|
|
2856
2848
|
|
|
2857
2849
|
def ensure_round_trip(self, chc, count, symbol):
|
|
2858
2850
|
# create a short test message, encode and decode
|
|
2859
|
-
msg =
|
|
2851
|
+
msg = choices(symbol, k=10)
|
|
2860
2852
|
a = bitarray()
|
|
2861
2853
|
a.encode(chc, msg)
|
|
2862
2854
|
it = canonical_decode(a, count, symbol)
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
"""
|
|
6
6
|
Useful utilities for working with bitarrays.
|
|
7
7
|
"""
|
|
8
|
-
from __future__ import absolute_import
|
|
9
|
-
|
|
10
8
|
import os
|
|
11
9
|
import sys
|
|
12
10
|
import math
|
|
@@ -59,15 +57,8 @@ Return (pseudo-) random bitarray of length `n` with `k` elements
|
|
|
59
57
|
set to one. Mathematically equivalent to setting (in a bitarray of
|
|
60
58
|
length `n`) all bits at indices `random.sample(range(n), k)` to one.
|
|
61
59
|
The random bitarrays are reproducible when giving Python's `random.seed()`
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
This function requires Python 3.9 or higher, as it depends on the standard
|
|
65
|
-
library function `random.randbytes()`. Raises `NotImplementedError`
|
|
66
|
-
when Python version is too low.
|
|
60
|
+
a specific seed value.
|
|
67
61
|
"""
|
|
68
|
-
if sys.version_info[:2] < (3, 9):
|
|
69
|
-
raise NotImplementedError("bitarray.util.random_k() requires "
|
|
70
|
-
"Python 3.9 or higher")
|
|
71
62
|
r = _Random(__n, endian)
|
|
72
63
|
if not isinstance(k, int):
|
|
73
64
|
raise TypeError("int expected, got '%s'" % type(k).__name__)
|
|
@@ -94,6 +85,7 @@ when Python version is too low.
|
|
|
94
85
|
r = _Random(__n, endian)
|
|
95
86
|
return r.random_p(p)
|
|
96
87
|
|
|
88
|
+
|
|
97
89
|
class _Random:
|
|
98
90
|
|
|
99
91
|
# The main reason for this class it to enable testing functionality
|
|
@@ -120,8 +112,10 @@ class _Random:
|
|
|
120
112
|
"""
|
|
121
113
|
Return bitarray with each bit having probability p = 1/2 of being 1.
|
|
122
114
|
"""
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
nbytes = self.nbytes
|
|
116
|
+
# use random module function for reproducibility (not urandom())
|
|
117
|
+
b = random.getrandbits(8 * nbytes).to_bytes(nbytes, 'little')
|
|
118
|
+
a = bitarray(b, self.endian)
|
|
125
119
|
del a[self.n:]
|
|
126
120
|
return a
|
|
127
121
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bitarray
|
|
3
|
-
Version: 3.7.
|
|
3
|
+
Version: 3.7.2
|
|
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.10
|
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
23
|
Classifier: Topic :: Utilities
|
|
23
24
|
License-File: LICENSE
|
|
24
25
|
Dynamic: author
|
|
@@ -76,7 +77,7 @@ Key features
|
|
|
76
77
|
Installation
|
|
77
78
|
------------
|
|
78
79
|
|
|
79
|
-
Python wheels are are available on PyPI for all
|
|
80
|
+
Python wheels are are available on PyPI for all major platforms and Python
|
|
80
81
|
versions. Which means you can simply:
|
|
81
82
|
|
|
82
83
|
.. code-block:: shell-session
|
|
@@ -89,7 +90,7 @@ Once you have installed the package, you may want to test it:
|
|
|
89
90
|
|
|
90
91
|
$ python -c 'import bitarray; bitarray.test()'
|
|
91
92
|
bitarray is installed in: /Users/ilan/bitarray/bitarray
|
|
92
|
-
bitarray version: 3.7.
|
|
93
|
+
bitarray version: 3.7.2
|
|
93
94
|
sys.version: 3.13.5 (main, Jun 16 2025) [Clang 18.1.8]
|
|
94
95
|
sys.prefix: /Users/ilan/miniforge
|
|
95
96
|
pointer size: 64 bit
|
|
@@ -351,7 +352,7 @@ and can therefore be used as a dictionary key:
|
|
|
351
352
|
Reference
|
|
352
353
|
=========
|
|
353
354
|
|
|
354
|
-
bitarray version: 3.7.
|
|
355
|
+
bitarray version: 3.7.2 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
|
|
355
356
|
|
|
356
357
|
In the following, ``item`` and ``value`` are usually a single bit -
|
|
357
358
|
an integer 0 or 1.
|
|
@@ -729,6 +730,11 @@ This sub-module was added in version 1.2.
|
|
|
729
730
|
Also, ``a`` may be any object that exposes a writable buffer.
|
|
730
731
|
Nothing about this function is specific to bitarray objects.
|
|
731
732
|
|
|
733
|
+
We should mention that Python's ``array.array`` object has a
|
|
734
|
+
method ``.byteswap()`` with similar functionality. However, unlike
|
|
735
|
+
bitarray's ``util.byteswap()`` function, this method is limited to
|
|
736
|
+
swapping 2, 4, or 8 consecutive bytes.
|
|
737
|
+
|
|
732
738
|
New in version 3.4
|
|
733
739
|
|
|
734
740
|
|
|
@@ -870,11 +876,7 @@ This sub-module was added in version 1.2.
|
|
|
870
876
|
set to one. Mathematically equivalent to setting (in a bitarray of
|
|
871
877
|
length ``n``) all bits at indices ``random.sample(range(n), k)`` to one.
|
|
872
878
|
The random bitarrays are reproducible when giving Python's ``random.seed()``
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
This function requires Python 3.9 or higher, as it depends on the standard
|
|
876
|
-
library function ``random.randbytes()``. Raises ``NotImplementedError``
|
|
877
|
-
when Python version is too low.
|
|
879
|
+
a specific seed value.
|
|
878
880
|
|
|
879
881
|
New in version 3.6
|
|
880
882
|
|
|
@@ -7,7 +7,7 @@ if sys.version_info[:3] < (3, 6, 1):
|
|
|
7
7
|
sys.exit("""\
|
|
8
8
|
****************************************************************************
|
|
9
9
|
* bitarray requires Python 3.6.1 or later.
|
|
10
|
-
* The last version supporting Python 2 is bitarray 2.9.3.
|
|
10
|
+
* The last bitarray version supporting Python 2.7 is bitarray 2.9.3.
|
|
11
11
|
****************************************************************************
|
|
12
12
|
""")
|
|
13
13
|
|
|
@@ -55,6 +55,7 @@ setup(
|
|
|
55
55
|
"Programming Language :: Python :: 3.11",
|
|
56
56
|
"Programming Language :: Python :: 3.12",
|
|
57
57
|
"Programming Language :: Python :: 3.13",
|
|
58
|
+
"Programming Language :: Python :: 3.14",
|
|
58
59
|
"Topic :: Utilities",
|
|
59
60
|
],
|
|
60
61
|
description = "efficient arrays of booleans -- C extension",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|