Skip to main content

A C++ implementation with Python bindings of StreamVByte.

Project description


libstreamvbyte


Table of Contents
  1. About The Project
  2. Getting Started
  3. Roadmap
  4. Contributing
  5. License
  6. Reference
  7. Contact

About The Project

libstreamvbyte is a C++ implementation of StreamVByte, with Python bindings using pybind11.

StreamVByte is a integer compression technique that use SIMD instructions (vectorization) to improve performance. The library is optimized for CPUs with the SSSE3 instruction set (which is supported by most x86_64 processors), and can also be used with ARM processors and other 32-bit architectures, although it will fall back to scalar implementations in those cases.

With libstreamvbyte, you can quickly and efficiently compress integer sequences, reducing the amount of storage space and network bandwidth required. The library is easy to use and integrates seamlessly with Python via pybind11 bindings. Whether you're working with large datasets or building a distributed computing system, libstreamvbyte can help you improve performance and reduce the resources needed to handle your data.

Currently supports Python 3.10+ on Windows, Linux (manylinux_2_17, musllinux_1_1) and macOS (universal2).

(back to top)

Getting Started

Installation

For Python

Install from PyPI using pip.

pip install libstreamvbyte

Or install from .whl file.

pip install "path/to/your/downloaded/whl"

To find appropriate .whl file, please visit releases.

For C++

You must have CMake installed on your system.

# clone the repo
git clone https://github.com/wst24365888/libstreamvbyte
cd libstreamvbyte

# build and install
cmake .
make
sudo make install

Usage

For Python

Import libstreamvbyte first.

import libstreamvbyte as svb

And here are the APIs.

# Encode an array of unsigned integers into a byte array.
encode(arg0: numpy.ndarray[numpy.uint32]) -> numpy.ndarray[numpy.uint8]

# Decode a byte array into an array of unsigned integers.
decode(arg0: numpy.ndarray[numpy.uint8], arg1: int) -> numpy.ndarray[numpy.uint32]

# Encode an array of signed integers into an array of unsigned integers.
encode_zigzag(arg0: numpy.ndarray[numpy.int32]) -> numpy.ndarray[numpy.uint32]

# Decode an array of unsigned integers into an array of signed integers.
decode_zigzag(arg0: numpy.ndarray[numpy.uint32]) -> numpy.ndarray[numpy.int32]

For C++

Include streamvbyte.h first.

#include "streamvbyte.h"

For the APIs, please refer to include/streamvbyte.h.

Example

For Python

import libstreamvbyte as svb

N = 2**20 + 2

# type(original_data) == np.ndarray
# original_data.dtype == np.int32
original_data = np.random.randint(-2**31, 2**31, N, dtype=np.int32)

# type(compressed_bytes) == np.ndarray
# compressed_bytes.dtype == np.uint8
compressed_bytes = svb.encode(svb.encode_zigzag(original_data))

# type(recovered_data) == np.ndarray
# recovered_data.dtype == np.int32
recovered_data = svb.decode_zigzag(svb.decode(compressed_bytes, N))

For C++

#include "streamvbyte.h"

int main() {
    std::size_t N = (1 << 20) + 2;

    std::vector<int32_t> original_data(N);
    for (std::size_t i = 0; i < N; ++i) {
        original_data[i] = rand() - rand();
    }

    std::vector<uint8_t> compressed_bytes = streamvbyte::encode(streamvbyte::encode_zigzag(original_data));
    std::vector<int32_t> recovered_data = streamvbyte::decode_zigzag(streamvbyte::decode(compressed_bytes, N));

    return 0;
}

Compile it with linking to libstreamvbyte.

g++ -o example example.cpp -lstreamvbyte

(back to top)

Roadmap

  • Zigzag encoding/decoding.
  • Support ARM processors with NEON intrinsics.
  • Differential coding (delta encoding/decoding).

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feat/amazing-feature)
  3. Commit your Changes with Conventional Commits
  4. Push to the Branch (git push origin feat/amazing-feature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Reference

(back to top)

Contact

Author

Project Link

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libstreamvbyte-0.2.1.tar.gz (761.8 kB view hashes)

Uploaded Source

Built Distributions

libstreamvbyte-0.2.1-cp311-cp311-win_amd64.whl (60.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

libstreamvbyte-0.2.1-cp311-cp311-win32.whl (47.8 kB view hashes)

Uploaded CPython 3.11 Windows x86

libstreamvbyte-0.2.1-cp311-cp311-musllinux_1_1_x86_64.whl (606.2 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

libstreamvbyte-0.2.1-cp311-cp311-musllinux_1_1_i686.whl (661.8 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

libstreamvbyte-0.2.1-cp311-cp311-musllinux_1_1_aarch64.whl (586.7 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

libstreamvbyte-0.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (82.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

libstreamvbyte-0.2.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (86.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

libstreamvbyte-0.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (75.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

libstreamvbyte-0.2.1-cp311-cp311-macosx_10_9_universal2.whl (105.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

libstreamvbyte-0.2.1-cp310-cp310-win_amd64.whl (60.3 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

libstreamvbyte-0.2.1-cp310-cp310-win32.whl (47.8 kB view hashes)

Uploaded CPython 3.10 Windows x86

libstreamvbyte-0.2.1-cp310-cp310-musllinux_1_1_x86_64.whl (606.2 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

libstreamvbyte-0.2.1-cp310-cp310-musllinux_1_1_i686.whl (661.8 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

libstreamvbyte-0.2.1-cp310-cp310-musllinux_1_1_aarch64.whl (586.7 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

libstreamvbyte-0.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (81.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

libstreamvbyte-0.2.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (86.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

libstreamvbyte-0.2.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (75.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

libstreamvbyte-0.2.1-cp310-cp310-macosx_10_9_universal2.whl (105.9 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page