pyroaring

repository·master·Indexed 42 days ago

https://github.com/ezibenroc/pyroaringbitmap

A high-performance Python wrapper for the CRoaring C library that provides efficient, ordered sets of 32-bit and 64-bit integers using Roaring Bitmaps. It features BitMap and BitMap64 classes supporting membership testing, addition, and set operations such as intersection, union, and difference.

Tokens
980
Snippets
8
Records
8
Agent score
4%

What's inside pyroaring

  1. Install pyroaring from source with uv

    master

    To build and test from source using uv:

    1. Clone the repository.
    2. Build the package without installing:
      uv build
    3. Run tests:
       ```bash
    uv run --with=pytest --with=hypothesis --with="$(ls dist/pyroaring-*.whl)" pytest test.py

    Note: Windows users require a different way to specify the wheel in the test command.

  2. Install pyroaring via pip

    master

    Install pyroaring from PyPI using pip.

    Supported Systems: Linux, MacOS, or Windows. Requirements: Python 3.9 or higher (older versions may work but are not tested).

    It is recommended to use a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    pip install pyroaring
    pip install pyroaring
  3. Install pyroaring from source with pip

    master

    To compile and install from source (useful for modifying Cython sources), you need an appropriate C compiler.

    1. Clone the repository:
      git clone https://github.com/Ezibenroc/PyRoaringBitMap.git
      cd PyRoaringBitMap
    2. Create and activate a virtual environment.
    3. Install using pip:
      python -m pip install .
      This will automatically install Cython if missing, cythonize source files, and compile the package.

    Quick Recompilation for Testing: To recompile the package in place without a full reinstall:

    python setup.py build_clib
    python setup.py build_ext -i

    Note: build_clib compiles croaring only and only needs to be run once.

    git clone https://github.com/Ezibenroc/PyRoaringBitMap.git
    python -m pip install .
  4. Optimize builds for x64 (Linux)

    master

    On recent Intel and AMD (x64) processors under Linux, you can achieve better performance by building CRoaring specifically for your machine's architecture.

    Warning: The resulting binary may only run on your specific machine.

    ARCHI=native pip install pyroaring --no-binary :all:

    Note: This approach may not work under macOS.

    ARCHI=native pip install pyroaring  --no-binary :all:
  5. Use BitMap and BitMap64 for efficient integer sets

    master

    The pyroaring library provides an efficient, lightweight ordered set of integers by wrapping the CRoaring C library. You can use it similarly to a standard Python set.

    • Use BitMap for 32-bit integers (values from 0 to $2^{32}-1$).
    • Use BitMap64 for 64-bit integers (values from 0 to $2^{64}-1$).

    Supported operations include membership testing (in), addition (add), and set operations like intersection (&), union (|), and difference.

    from pyroaring import BitMap
    
    # Initialize and add elements
    bm1 = BitMap()
    bm1.add(3)
    bm1.add(18)
    
    # Membership testing
    print("has 3:", 3 in bm1)
    print("has 4:", 4 in bm1)
    
    # Initialize from list
    bm2 = BitMap([3, 27, 42])
    
    # Set operations
    print("bm1       = %s" % bm1)
    print("bm2       = %s" % bm2)
    print("bm1 & bm2 = %s" % (bm1&bm2))
    print("bm1 | bm2 = %s" % (bm1|bm2))
  6. Compile with DEBUG or specific ARCHI flags

    master

    When building from source, you can use environment variables to control compilation:

    • DEBUG=1: Build in debug mode.
    • ARCHI=<cpu-type>: Build for a specific platform using keywords compatible with the -march option of gcc.

    Example:

    DEBUG=1 ARCHI=x86-64 python setup.py build_ext