1 个不稳定版本
0.0.1 | 2023年6月17日 |
---|
#5 in #bit-pack
24KB
447 行
bitpack-vec
一个密集的位打包无符号整数向量类型。
use bitpack_vec::BitpackVec;
let mut bv = BitpackVec::new(5); // 5-bit integers
for i in 0..12 {
bv.push(i);
}
assert_eq!(bv.at(6), 6);
assert_eq!(bv.at(9), 9);
use deepsize::DeepSizeOf;
assert_eq!(bv.as_raw().len(), 1); // underlying vector length is just 1 (60 bits)
// total in-memory size (not strictly specified by Rust):
assert_eq!(
bv.deep_size_of(),
std::mem::size_of::<Vec<u64>>() // size of the vector structure
+ std::mem::size_of::<usize>() // the length counter (separate from the Vec's)
+ std::mem::size_of::<u8>() // the bitwidth of the structure
+ 15 // padding
);
O(1)
随机访问单个元素O(1)
弹出O(1)
设置- 平均
O(1)
添加(与RustVec
相同) - 任何从1到63位的位长
- Serde序列化
此包以“你预期的”方式进行整数位打包,没有使用复杂的SIMD或额外压缩。值存储在 Vec<u64>
中,因此不会浪费超过63位的空间。值可以重叠 u64
值。
与其他Rust位打包包相比
bitpacking
使用SIMD压缩将值打包成块,但必须解压缩整个块才能访问值。如果你不关心随机访问,bitpacking
可能是你要找的。vorbis_bitpack
允许使用Vorbis格式对打包整数进行流式压缩和解压缩。没有随机访问,但具有流式读取器/写入器。parquet
实现了许多Apache支持的格式(feather、arrow、parquet),其中许多支持位打包和其他类型的压缩。
许可证
此代码可在GPL-3.0(或更高版本)许可的条款下使用。
依赖关系
~0.5–1MB
~24K SLoC