Bitsets
This package provides a memory-efficient pure-python immutable ordered set data type for working with large numbers of subsets from a predetermined pool of objects.
Given a name and a tuple of hashable objects, the bitset()-function returns a custom integer subclass for creating ordered subsets from the object pool. Each instance is a Python integer where the presence/absence of the nth pool item is its nth bit being set/unset (a.k.a. bit strings, powers of two, rank in colexicographical order).
Being just a regular (arbitrary precision) integer with some convenience methods for translating between unique object collections and bit patterns allows to perform certain tasks in a more natural way, e.g. sorting a collection of sets lexicographically, or enumerating possible combinations in an ordered fashion.
Links
GitHub: https://github.com/xflr6/bitsets
Documentation: https://bitsets.readthedocs.io
Changelog: https://bitsets.readthedocs.io/en/latest/changelog.html
Issue Tracker: https://github.com/xflr6/bitsets/issues
Download: https://pypi.org/project/bitsets/#files
Installation
This package runs under Python 3.10+ and has no required dependencies, use pip to install:
$ pip install bitsets
Quickstart
Create a class for sets taken from your pool of objects:
>>> from bitsets import bitset
>>> PYTHONS = ('Chapman', 'Cleese', 'Gilliam', 'Idle', 'Jones', 'Palin')
>>> Pythons = bitset('Pythons', PYTHONS)
Access its maximal and minimal instances. Retrieve instance members in definition order:
>>> Pythons.supremum
Pythons(['Chapman', 'Cleese', 'Gilliam', 'Idle', 'Jones', 'Palin'])
>>> Pythons.infimum
Pythons()
>>> Pythons(['Idle', 'Gilliam', 'Idle', 'Idle']).members()
('Gilliam', 'Idle')
Translate to/from bit string, boolean sequence, and int:
>>> Pythons(['Chapman', 'Gilliam']).bits()
'101000'
>>> Pythons.frombits('101000')
Pythons(['Chapman', 'Gilliam'])
>>> Pythons(['Chapman', 'Gilliam']).bools()
(True, False, True, False, False, False)
>>> Pythons.frombools([True, None, 1, False, 0])
Pythons(['Chapman', 'Gilliam'])
>>> int(Pythons(['Chapman', 'Gilliam']))
5
>>> Pythons.fromint(5)
Pythons(['Chapman', 'Gilliam'])
Set operation and comparison methods (cf. build-in frozenset):
>>> Pythons(['Jones', 'Cleese', 'Idle']).intersection(Pythons(['Idle']))
Pythons(['Idle'])
>>> Pythons(['Idle']).union(Pythons(['Jones', 'Cleese']))
Pythons(['Cleese', 'Idle', 'Jones'])
>>> Pythons.supremum.difference(Pythons(['Chapman', 'Cleese']))
Pythons(['Gilliam', 'Idle', 'Jones', 'Palin'])
>>> Pythons(['Palin', 'Jones']).symmetric_difference(Pythons(['Cleese', 'Jones']))
Pythons(['Cleese', 'Palin'])
>>> Pythons(['Gilliam']).issubset(Pythons(['Cleese', 'Palin']))
False
>>> Pythons(['Cleese', 'Palin']).issuperset(Pythons())
True
Further reading
See also
bitarray – efficient boolean array implemented as C extension
bitstring – pure-Python bit string based on bytearray
BitVector – pure-Python bit array based on unsigned short array
Bitsets – Cython interface to fast bitsets in Sage
bitfield – Cython positive integer sets
intbitset – integer bit sets as C extension
gmpy2 – fast arbitrary precision integer arithmetic
License
Bitsets is distributed under the MIT license.
Metadata
Release files for bitsets 0.9.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bitsets-0.9.1.tar.gz | 106.8 kB | Without provenance | Details for bitsets-0.9.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bitsets-0.9.1-py3-none-any.whl | Python 3 | none | any | Details for bitsets-0.9.1-py3-none-any.whl |
Total release size: 120.7 kB
Release files / bitsets-0.9.1.tar.gz
| Download URL | bitsets-0.9.1.tar.gz |
|---|---|
| Size | 106.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4268875468ed3ba8657b1e09a984c74c88622dd7d29fa1d8d0d474b7e2daff9
|
|
BLAKE2b-256 checksum How to use checksums |
45d39f6b7e955c23655c2b9051f1a221c7fa5caad7a695bcecc90cbf6b1fe8db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / bitsets-0.9.1-py3-none-any.whl
| Download URL | bitsets-0.9.1-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b80c6e2d377fbf835f9d053e5546f10aa0f1b4bbd0e93e09329247dd8adc1922
|
|
BLAKE2b-256 checksum How to use checksums |
4c3fbf1ff4c8394fcb7a7a55e216af0394cc3a8970c5db5ebb0d351d06333c6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for bitsets 0.9.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.