默认 makefile 在 x86 上假定支持 AVX,老 CPU 需自行调整编译选项;在 GCC 下可能需要手动加 -msse2;Windows 需在 Visual Studio 的 Developer Powershell 中运行 nmake -f .\makefile.vc,产物为 simdcomp_a.lib。
SIMDCompressionAndIntersection
fast-packApache-2.0更新放缓用 SIMD 指令压缩有序整数列表并求交集的 C++ 库,适合倒排索引、搜索引擎等需要快速处理大量整数集合的场景。
A C++ library to compress and intersect sorted lists of integers using SIMD instructions
make
./unitx86/x64 需支持 SSE2(Pentium 4 及以上),推荐 SSE 4.1(Penryn 及以后);默认 makefile 假定支持 AVX,但 AVX 并非必需。64 位 ARM(AArch64,如 Apple Silicon 和 ARM 服务器)通过 neon_sse.h 映射到 NEON,无需 x86 硬件。README 未提及显存或 GPU 要求。
用 SIMD 指令压缩和求交有序整数列表的 C++ 库,解码速度远超通用压缩
用 SIMD 指令压缩有序整数列表并求交集的 C++ 库,适合倒排索引、搜索引擎等需要快速处理大量整数集合的场景。
核心能力
- 用 SIMD 指令压缩有序整数列表,侧重差分编码
- 提供 SIMD Galloping 等 SIMD 求交方案
- 解码速度可达每秒 40 亿整数、约 15 GB/s
- 同时提供 Makefile 与 CMake 构建,可安装为静态库
- 在 AArch64 上把 SSE intrinsics 映射到 ARM NEON
容易踩的坑
- v0.2.0Version 0.2.0最新正式版2026-06-07 · 2026-06-07 21:42 UTC
What's Changed
- use quote instead of bracket include by @yonik in https://github.com/fast-pack/SIMDCompressionAndIntersection/pull/25
- fix buggy use of 32 bit ctzl that resulted in crashes with recent MSVC by @yonik in https://github.com/fast-pack/SIMDCompressionAndIntersection/pull/26
- library fixes: move functions out of headers or make them inline by @yonik in https://github.com/fast-pack/SIMDCompressionAndIntersection/pull/27
- add mutualPartitioningIntersect by @byronhe in https://github.com/fast-pack/SIMDCompressionAndIntersection/pull/29
- Adding ubuntu tests. by @lemire in https://github.com/fast-pack/SIMDCompressionAndIntersection/pull/31
- Better documentation for visual studio by @lemire in https://github.com/fast-pack/SIMDCompressionAndIntersection/pull/33
New Contributors
- @yonik made their first contribution in https://github.com/fast-pack/SIMDCompressionAndIntersection/pull/25
- @byronhe made their first contribution in https://github.com/fast-pack/SIMDCompressionAndIntersection/pull/29
- @lemire made their first contribution in https://github.com/fast-pack/SIMDCompressionAndIntersection/pull/31
Full Changelog: https://github.com/fast-pack/SIMDCompressionAndIntersection/compare/v0.1.1...v0.2.0
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
SIMDCompressionAndIntersection
As the name suggests, this is a C/C++ library for fast compression and intersection of lists of sorted integers using SIMD instructions. The library focuses on innovative techniques and very fast schemes, with particular attention to differential coding. It introduces new SIMD intersections schemes such as SIMD Galloping.
This library can decode at least 4 billions of compressed integers per second on most desktop or laptop processors. That is, it can decompress data at a rate of 15 GB/s. This is significantly faster than generic codecs like gzip, LZO, Snappy or LZ4.
Authors: Leonid Boystov, Nathan Kurz, Daniel Lemire, Owen Kaser, Andrew Consroe, Shlomi Vaknin, Christoph Rupp, Bradley Grainger, and others.
Documentation
- Daniel Lemire, Nathan Kurz, Christoph Rupp, Stream VByte: Faster Byte-Oriented Integer Compression, Information Processing Letters 130, 2018 https://arxiv.org/abs/1709.08990
- Daniel Lemire, Leonid Boytsov, Nathan Kurz, SIMD Compression and the Intersection of Sorted Integers, Software Practice & Experience 46 (6), 2016 http://arxiv.org/abs/1401.6399
- Daniel Lemire and Leonid Boytsov, Decoding billions of integers per second through vectorization, Software Practice & Experience 45 (1), 2015. http://arxiv.org/abs/1209.2137 http://onlinelibrary.wiley.com/doi/10.1002/spe.2203/abstract
- Jeff Plaisance, Nathan Kurz, Daniel Lemire, Vectorized VByte Decoding, International Symposium on Web Algorithms 2015, 2015. http://arxiv.org/abs/1503.07387
- Wayne Xin Zhao, Xudong Zhang, Daniel Lemire, Dongdong Shan, Jian-Yun Nie, Hongfei Yan, Ji-Rong Wen, A General SIMD-based Approach to Accelerating Compression Algorithms, ACM Transactions on Information Systems 33 (3), 2015. http://arxiv.org/abs/1502.01916
This work has also inspired other work such as...
- P. Damme, D. Habich, J. Hildebrandt, W. Lehner, Lightweight Data Compression Algorithms: An Experimental Survey (Experiments and Analyses), EDBT 2017 http://openproceedings.org/2017/conf/edbt/paper-146.pdf
- P. Damme, D. Habich, J. Hildebrandt, W. Lehner, Insights into the Comparative Evaluation of Lightweight Data Compression Algorithms, EDBT 2017 http://openproceedings.org/2017/conf/edbt/paper-414.pdf
- T. D. Wu, Bitpacking techniques for indexing genomes: I. Hash tables, Algorithms for Molecular Biology 11 (5), 2016. http://almob.biomedcentral.com/articles/10.1186/s13015-016-0069-5
- Jianguo Wang, Chunbin Lin, Yannis Papakonstantinou, Steven Swanson, An Experimental Study of Bitmap Compression vs. Inverted List Compression, SIGMOD 2017 http://db.ucsd.edu/wp-content/uploads/2017/03/sidm338-wangA.pdf
Simple demo
Check out example.cpp
You can run it like so (e.g., under Linux or macOS):
Usage (Linux, macOS and similar systems)
make
./unit
A static library file is built as libSIMDCompressionAndIntersection.a which you can use in your
own projects along with our header files located in the include subdirectory.
You may also build and run our example:
make example
./example
To run tests, you can do
./testcodecs
(follow the instructions)
Building and installing with CMake
A CMake build is also provided. It works on x86/x64 (SSE/AVX) and on 64-bit ARM (the SSE intrinsics are mapped to ARM NEON), and it builds the same library and tests as the Makefile.
cmake -S . -B build
cmake --build build
ctest --test-dir build # runs the unit tests
To install the library, headers and a CMake package configuration:
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/your/prefix -DSIMDCOMP_BUILD_TESTS=OFF
cmake --build build
cmake --install build
Downstream CMake projects can then locate it with find_package and link the
imported target:
find_package(SIMDCompressionAndIntersection REQUIRED)
target_link_libraries(yourapp PRIVATE
SIMDCompressionAndIntersection::SIMDCompressionAndIntersection)
The installed headers live under <prefix>/include/SIMDCompressionAndIntersection
and are added to your include path by the imported target, so #include <codecfactory.h> works directly. Useful options: -DSIMDCOMP_BUILD_TESTS=OFF
to skip the tests/benchmarks and -DSIMDCOMP_INSTALL=OFF to disable install
rules (handy when consuming the project via add_subdirectory).
Usage (Windows users)
Windows users wishing to build using Visual Studio should go into a Developer Powershell, which is accessible through the menus in the Visual Studio interface, and run the following from the directory of the project:
nmake -f .\makefile.vc
.\example.exe
.\unit.exe
Under Windows, the static library is built as the file simdcomp_a.lib which you can use in your
own projects, along with our header files located in the include subdirectory.
For a simple C library
This library is a C++ research library. For something simpler, written in C, see:
https://github.com/lemire/simdcomp
Comparison with the FastPFOR C++ library
The FastPFOR C++ Library available at https://github.com/lemire/FastPFor implements some of the same compression schemes except that it is not optimized for the compression of sorted lists of integers.
Other recommended libraries
- libvbyte: A fast implementation for varbyte 32bit/64bit integer compression https://github.com/cruppstahl/libvbyte
- TurboPFor is a C library that offers lots of interesting optimizations. Well worth checking! (GPL license) https://github.com/powturbo/TurboPFor
- Oroch is a C++ library that offers a usable API (MIT license) https://github.com/ademakov/Oroch
- CSharpFastPFOR: A C# integer compression library https://github.com/Genbox/CSharpFastPFOR
- JavaFastPFOR: A java integer compression library https://github.com/lemire/JavaFastPFOR
- Encoding: Integer Compression Libraries for Go https://github.com/zhenjl/encoding
- FrameOfReference is a C++ library dedicated to frame-of-reference (FOR) compression: https://github.com/lemire/FrameOfReference
Licensing
Apache License, Version 2.0
As far as the authors know, this work is patent-free.
Requirements
On x86/x64, a CPU (AMD or Intel) with support for SSE2 (Pentium 4 or better) is required while a CPU with SSE 4.1* (Penryn [2007] processors or better) is recommended.
On 64-bit ARM (AArch64, e.g. Apple Silicon and ARM servers), the SSE intrinsics
are mapped to ARM NEON via include/neon_sse.h, so no x86 hardware is needed.
NEON is baseline on AArch64, so no special compiler flag is required.
A recent GCC (4.7 or better), Clang, Intel or Visual C++ compiler.
On x86, a processor supporting AVX (Intel or AMD) is assumed by the default makefile (but AVX is not required, see below).
Tested on Linux, MacOS and Windows, on both x64 and ARM64. It should be portable to other platforms.
*- On x86, the default makefile might assume AVX support, but AVX is not
required. For GCC compilers, you might need the -msse2 flag, but you will not
need the -mavx flag. On ARM64 the makefile automatically drops the x86 -mavx
flag.
For advanced benchmarking, please see
advancedbenchmarking/README.md
where there is additional information as well as links to real data sets.
Acknowledgement
Thanks to Kelly Sommers for useful feedback.
This work was supported by NSERC grant number 26143.