Package: pyroaring
An efficient and light-weight ordered set of 32 bits integers.
This is a Python wrapper for the C libraryCRoaring.ExampleYou can use a bitmap nearly as the classical Python set in your code:frompyroaringimportBitMapbm1=BitMap()bm1.add(3)bm1.add(18)print("has 3:",3inbm1)print("has 4:",4inbm1)bm2=BitMap([3,27,42])print("bm1       =%s"%bm1)print("bm2       =%s"%bm2)print("bm1 & bm2 =%s"%(bm1&bm2))print("bm1 | bm2 =%s"%(bm1|bm2))Output:has 3: True
has 4: False
bm1       = BitMap([3, 18])
bm2       = BitMap([3, 27, 42])
bm1 & bm2 = BitMap([3])
bm1 | bm2 = BitMap([3, 18, 27, 42])Installation from PypiSupported systems: Linux, MacOS or Windows, Python 3.7 or higher. Note that pyroaring might still work with older Python
versions, but they are not tested anymore.To install pyroaring on your local account, use the following command:pipinstallpyroaring--userFor a system-wide installation, use the following command:pipinstallpyroaringNaturally, the latter may require superuser rights (consider prefixing
the commands bysudo).If you want to use Python 3 and your system defaults on Python 2.7, you
may need to adjust the above commands, e.g., replacepipbypip3.Installation from conda-forgeConda users can install the package fromconda-forge:condainstall-cconda-forgepyroaring(Supports Python 3.6 or higher; Mac/Linux/Windows)Installation from SourceIf you want to compile (and install) pyroaring by yourself, for instance
to modify the Cython sources you can follow the following instructions.
Note that these examples will install in your currently active python
virtual environment. Installing this way will require an appropriate
C compiler to be installed on your system.First clone this repository.gitclonehttps://github.com/Ezibenroc/PyRoaringBitMap.gitTo install from Cython via source, for example during development run the following from the root of the above repository:python-mpipinstall.This will automatically install Cython if it not present for the build, cythonise the source files and compile everything for you.If you just want to recompile the package in place for quick testing you can
try the following:pythonsetup.pybuild_clibpythonsetup.pybuild_ext-iNote that the build_clib compiles croaring only, and only needs to be run once.Then you can test the new code using tox - this will install all the other
dependencies needed for testing and test in an isolated environment:python-mpipinstalltoxtoxIf you just want to run the tests directly from the root of the repository:python-mpipinstallhypothesis# This will test in three ways: via installation from source,
# via cython directly, and creation of a wheelpythontest.pyPackage pyroaring as an sdist and wheel. Note that building wheels that have
wide compatibility can be tricky - for releases we rely oncibuildwheelto do the heavy lifting across platforms.python-mpipinstallbuildpython-mbuild.For all the above commands, two environment variables can be used to control the compilation.DEBUG=1to build pyroaring in debug mode.ARCHI=<cpu-type>to build pyroaring for the given platform. The platform may be any keyword
given to the-marchoption of gcc (see thedocumentation).
Note that cross-compiling for a 32-bit architecture from a 64-bit architecture is not supported.Example of use:DEBUG=1ARCHI=x86-64pythonsetup.pybuild_extOptimizing the builds for your machine (x64)For recent Intel and AMD (x64) processors under Linux, you may get better performance by requesting that
CRoaring be built for your machine, specifically, when building from source.
Be mindful that when doing so, the generated binary may only run on your machine.ARCHI=nativepipinstallpyroaring--no-binary:all:This approach may not work under macOS.Development NotesUpdating CRoaringThe download_amalgamation.py script can be used to download a specific version
of the official CRoaring amalgamation:pythondownload_amalgamation.pyv0.7.2This will update roaring.c and roaring.h. This also means that the dependency
is vendored in and tracked as part of the source repository now. Note that the
__croaring_version__ in version.pxi will need to be updated to match the new
version.Tracking Package and CRoaring versionsThe package version is maintained in the filepyroaring/version.pxi- this
can be manually incremented in preparation for releases. This file is read
from in setup.py to specify the version.The croaring version is tracked inpyroaring/croaring_version.pxi- this is
updated automatically when downloading a new amalgamation.BenchmarkPyroaringis compared with the built-insetand other implementations:APython wrapperof CRoaring calledpython-croaringACython implementationof Roaring bitmaps calledroaringbitmapA Python implementation ofordered setscalledsortedcontainersThe scriptquick_bench.pymeasures the time of different set
operations. It uses randomly generated sets of size 1e6 and density
0.125. For each operation, the average time (in seconds) of 30 tests
is reported.The results have been obtained with:CPU Intel Xeon CPU E5-2630 v3CPython version 3.5.3gcc version 6.3.0Cython version 0.28.3pyroaring commitdcf448apython-croaring commit3aa61ddroaringbitmap commit502d78dsortedcontainers commit7d6a28coperationpyroaringpython-croaringroaringbitmapsetsortedcontainersrange constructor3.09e-041.48e-048.72e-057.29e-022.08e-01ordered list constructor3.45e-026.93e-021.45e-011.86e-015.74e-01list constructor1.23e-011.33e-011.55e-011.12e-015.12e-01ordered array constructor5.06e-036.42e-032.89e-019.82e-023.01e-01array constructor1.13e-011.18e-014.63e-011.45e-015.08e-01element addition3.08e-078.26e-072.21e-071.50e-071.18e-06element removal3.44e-078.17e-072.61e-071.78e-074.26e-07membership test1.24e-071.00e-061.50e-071.00e-075.72e-07union1.61e-041.96e-041.44e-042.15e-011.11e+00intersection9.08e-049.48e-049.26e-045.22e-021.65e-01difference1.57e-041.97e-041.43e-041.56e-014.84e-01symmetric diference1.62e-042.01e-041.44e-042.62e-019.13e-01equality test7.80e-057.82e-055.89e-051.81e-021.81e-02subset test7.92e-058.12e-058.22e-051.81e-021.81e-02conversion to list4.71e-022.78e-014.35e-025.77e-025.32e-02pickle dump & load4.02e-046.27e-045.08e-042.41e-015.75e-01“naive” conversion to array5.12e-022.92e-014.75e-021.20e-011.18e-01“optimized” conversion to array1.27e-033.40e-02nannannanselection1.77e-065.33e-051.14e-06nan1.64e-05contiguous slice9.38e-059.51e-056.99e-05nan2.04e-02slice2.88e-033.04e-011.00e-01nan4.74e-01small slice8.93e-053.00e-013.60e-03nan1.79e-02