Skip to content

Commit bf5c165

Browse files
authored
chore: rename c++ codecs and use portable C++ submodule (#76)
* no code changes - just rename all C++ codecs to `Cpp*` without the `Codec` suffix. * bump C++ dependency to the latest main - i think this is the reason the last release didn't handle portable C++ properly
1 parent 6ba6e0b commit bf5c165

12 files changed

Lines changed: 214 additions & 225 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ Feature selection can be overridden with the `FASTPFOR_SIMD_MODE` environment va
9090
### Using C++ Wrapper
9191

9292
```rust
93-
use fastpfor::{AnyLenCodec as _, cpp};
93+
use fastpfor::AnyLenCodec as _;
94+
use fastpfor::cpp::CppSimdFastPFor128;
9495

9596
fn main() {
96-
let mut codec = cpp::SimdFastPFor128Codec::new();
97+
let mut codec = CppSimdFastPFor128::new();
9798

9899
let input = vec![1u32, 2, 3, 4, 5];
99100
let mut compressed = Vec::new();

benches/bench_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::num::NonZeroU32;
1616
#[cfg(feature = "cpp")]
1717
use fastpfor::AnyLenCodec as _;
1818
#[cfg(feature = "cpp")]
19-
use fastpfor::cpp;
19+
use fastpfor::cpp::CppFastPFor128;
2020
pub use fastpfor::rust::{BLOCK_SIZE_128, BLOCK_SIZE_256, DEFAULT_PAGE_SIZE, FastPFOR, Integer};
2121
use rand::rngs::StdRng;
2222
use rand::{RngExt as _, SeedableRng};
@@ -171,15 +171,15 @@ fn prepare_compressed_data(data: &[u32], block_size: NonZeroU32) -> Vec<u32> {
171171
// ---------------------------------------------------------------------------
172172

173173
#[cfg(feature = "cpp")]
174-
pub fn cpp_encode(codec: &mut cpp::FastPFor128Codec, data: &[u32]) -> Vec<u32> {
174+
pub fn cpp_encode(codec: &mut CppFastPFor128, data: &[u32]) -> Vec<u32> {
175175
let mut out = Vec::new();
176176
codec.encode(data, &mut out).unwrap();
177177
out
178178
}
179179

180180
#[cfg(feature = "cpp")]
181181
pub fn cpp_decode(
182-
codec: &mut cpp::FastPFor128Codec,
182+
codec: &mut CppFastPFor128,
183183
compressed: &[u32],
184184
decompressed: &mut [u32],
185185
) -> usize {
@@ -275,7 +275,7 @@ pub struct CppDecodeFixture {
275275
impl CppDecodeFixture {
276276
fn new(name: &'static str, generator: DataGeneratorFn, size: usize) -> Self {
277277
let data = generator(size);
278-
let mut codec = cpp::FastPFor128Codec::new();
278+
let mut codec = CppFastPFor128::new();
279279
let cpp_compressed = cpp_encode(&mut codec, &data);
280280
let rust_compressed = prepare_compressed_data(&data, BLOCK_SIZE_128);
281281
Self {

benches/fastpfor_benchmark.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use bench_utils::{
1414
#[cfg(feature = "cpp")]
1515
use bench_utils::{cpp_decode, cpp_decode_fixtures, cpp_encode};
1616
#[cfg(feature = "cpp")]
17-
use fastpfor::cpp;
17+
use fastpfor::cpp::CppFastPFor128;
1818

1919
const SIZES: &[usize] = &[1024, 4096];
2020

@@ -153,7 +153,7 @@ fn benchmark_cpp_vs_rust(c: &mut Criterion) {
153153
BenchmarkId::new(format!("cpp/{}", fix.name), size),
154154
&fix.data,
155155
|b, data| {
156-
let mut codec = cpp::FastPFor128Codec::new();
156+
let mut codec = CppFastPFor128::new();
157157
b.iter(|| black_box(cpp_encode(&mut codec, black_box(data))));
158158
},
159159
);
@@ -175,7 +175,7 @@ fn benchmark_cpp_vs_rust(c: &mut Criterion) {
175175
BenchmarkId::new(format!("cpp/{}", fix.name), size),
176176
&fix.cpp_compressed,
177177
|b, compressed| {
178-
let mut codec = cpp::FastPFor128Codec::new();
178+
let mut codec = CppFastPFor128::new();
179179
let mut out = vec![0u32; fix.original_len];
180180
b.iter(|| black_box(cpp_decode(&mut codec, black_box(compressed), &mut out)));
181181
},

fuzz/fuzz_targets/common.rs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use fastpfor::{AnyLenCodec, cpp, rust};
1+
use fastpfor::cpp::*;
2+
use fastpfor::{AnyLenCodec, rust};
23

34
pub type BoxedCppCodec = Box<dyn AnyLenCodec>;
45

@@ -78,42 +79,40 @@ pub enum CppCodec {
7879
impl From<CppCodec> for BoxedCppCodec {
7980
fn from(codec: CppCodec) -> Self {
8081
match codec {
81-
CppCodec::BP32 => Box::new(cpp::BP32Codec::default()),
82-
CppCodec::Copy => Box::new(cpp::CopyCodec::default()),
83-
CppCodec::FastBinaryPacking8 => Box::new(cpp::FastBinaryPacking8Codec::default()),
84-
CppCodec::FastPFor128 => Box::new(cpp::FastPFor128Codec::default()),
85-
CppCodec::FastPFor256 => Box::new(cpp::FastPFor256Codec::default()),
86-
CppCodec::FastBinaryPacking16 => Box::new(cpp::FastBinaryPacking16Codec::default()),
87-
CppCodec::FastBinaryPacking32 => Box::new(cpp::FastBinaryPacking32Codec::default()),
88-
CppCodec::MaskedVByte => Box::new(cpp::MaskedVByteCodec::default()),
89-
CppCodec::NewPFor => Box::new(cpp::NewPForCodec::default()),
90-
CppCodec::OptPFor => Box::new(cpp::OptPForCodec::default()),
91-
CppCodec::PFor2008 => Box::new(cpp::PFor2008Codec::default()),
92-
CppCodec::PFor => Box::new(cpp::PForCodec::default()),
93-
CppCodec::SimdBinaryPacking => Box::new(cpp::SimdBinaryPackingCodec::default()),
94-
CppCodec::SimdFastPFor128 => Box::new(cpp::SimdFastPFor128Codec::default()),
95-
CppCodec::SimdFastPFor256 => Box::new(cpp::SimdFastPFor256Codec::default()),
96-
CppCodec::SimdGroupSimple => Box::new(cpp::SimdGroupSimpleCodec::default()),
97-
CppCodec::SimdGroupSimpleRingBuf => {
98-
Box::new(cpp::SimdGroupSimpleRingBufCodec::default())
99-
}
100-
CppCodec::SimdNewPFor => Box::new(cpp::SimdNewPForCodec::default()),
101-
CppCodec::SimdOptPFor => Box::new(cpp::SimdOptPForCodec::default()),
102-
CppCodec::SimdPFor => Box::new(cpp::SimdPForCodec::default()),
103-
CppCodec::SimdSimplePFor => Box::new(cpp::SimdSimplePForCodec::default()),
104-
// CppCodec::Simple16 => Box::new(cpp::Simple16Codec::default()),
105-
// CppCodec::Simple8b => Box::new(cpp::Simple8bCodec::default()),
106-
// CppCodec::Simple8bRle => Box::new(cpp::Simple8bRleCodec::default()),
107-
// CppCodec::Simple9 => Box::new(cpp::Simple9Codec::default()),
108-
// CppCodec::Simple9Rle => Box::new(cpp::Simple9RleCodec::default()),
109-
// CppCodec::SimplePFor => Box::new(cpp::SimplePForCodec::default()),
110-
// CppCodec::Snappy => Box::new(cpp::SnappyCodec::default()),
111-
CppCodec::StreamVByte => Box::new(cpp::StreamVByteCodec::default()),
112-
CppCodec::VByte => Box::new(cpp::VByteCodec::default()),
113-
CppCodec::VarInt => Box::new(cpp::VarIntCodec::default()),
114-
// CppCodec::VarIntG8iu => Box::new(cpp::VarIntG8iuCodec::default()),
115-
CppCodec::VarIntGb => Box::new(cpp::VarIntGbCodec::default()),
116-
// CppCodec::VsEncoding => Box::new(cpp::VsEncodingCodec::default()),
82+
CppCodec::BP32 => Box::new(CppBP32::default()),
83+
CppCodec::Copy => Box::new(CppCopy::default()),
84+
CppCodec::FastBinaryPacking8 => Box::new(CppFastBinaryPacking8::default()),
85+
CppCodec::FastPFor128 => Box::new(CppFastPFor128::default()),
86+
CppCodec::FastPFor256 => Box::new(CppFastPFor256::default()),
87+
CppCodec::FastBinaryPacking16 => Box::new(CppFastBinaryPacking16::default()),
88+
CppCodec::FastBinaryPacking32 => Box::new(CppFastBinaryPacking32::default()),
89+
CppCodec::MaskedVByte => Box::new(CppMaskedVByte::default()),
90+
CppCodec::NewPFor => Box::new(CppNewPFor::default()),
91+
CppCodec::OptPFor => Box::new(CppOptPFor::default()),
92+
CppCodec::PFor2008 => Box::new(CppPFor2008::default()),
93+
CppCodec::PFor => Box::new(CppPFor::default()),
94+
CppCodec::SimdBinaryPacking => Box::new(CppSimdBinaryPacking::default()),
95+
CppCodec::SimdFastPFor128 => Box::new(CppSimdFastPFor128::default()),
96+
CppCodec::SimdFastPFor256 => Box::new(CppSimdFastPFor256::default()),
97+
CppCodec::SimdGroupSimple => Box::new(CppSimdGroupSimple::default()),
98+
CppCodec::SimdGroupSimpleRingBuf => Box::new(CppSimdGroupSimpleRingBuf::default()),
99+
CppCodec::SimdNewPFor => Box::new(CppSimdNewPFor::default()),
100+
CppCodec::SimdOptPFor => Box::new(CppSimdOptPFor::default()),
101+
CppCodec::SimdPFor => Box::new(CppSimdPFor::default()),
102+
CppCodec::SimdSimplePFor => Box::new(CppSimdSimplePFor::default()),
103+
// CppCodec::Simple16 => Box::new(CppSimple16::default()),
104+
// CppCodec::Simple8b => Box::new(CppSimple8b::default()),
105+
// CppCodec::Simple8bRle => Box::new(CppSimple8bRle::default()),
106+
// CppCodec::Simple9 => Box::new(CppSimple9::default()),
107+
// CppCodec::Simple9Rle => Box::new(CppSimple9Rle::default()),
108+
// CppCodec::SimplePFor => Box::new(CppSimplePFor::default()),
109+
// CppCodec::Snappy => Box::new(CppSnappy::default()),
110+
CppCodec::StreamVByte => Box::new(CppStreamVByte::default()),
111+
CppCodec::VByte => Box::new(CppVByte::default()),
112+
CppCodec::VarInt => Box::new(CppVarInt::default()),
113+
// CppCodec::VarIntG8iu => Box::new(CppVarIntG8iu::default()),
114+
CppCodec::VarIntGb => Box::new(CppVarIntGb::default()),
115+
// CppCodec::VsEncoding => Box::new(CppVsEncoding::default()),
117116
}
118117
}
119118
}

fuzz/fuzz_targets/rust_compress_oracle.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#![no_main]
22

3-
use fastpfor::{AnyLenCodec, CodecToSlice, cpp, rust};
3+
use fastpfor::{AnyLenCodec, CodecToSlice, rust};
44
use libfuzzer_sys::fuzz_target;
55
mod common;
66
use common::*;
7+
use fastpfor::cpp::*;
78

89
fuzz_target!(|data: FuzzInput<RustCodec>| {
910
let input = data.data;
@@ -40,16 +41,16 @@ fuzz_target!(|data: FuzzInput<RustCodec>| {
4041
// Compress with C++ implementation (`AnyLenCodec` / Vec API)
4142
let mut cpp_compressed = Vec::new();
4243
match data.codec {
43-
RustCodec::FastPFOR256 => cpp::FastPFor256Codec::new()
44+
RustCodec::FastPFOR256 => CppFastPFor256::new()
4445
.encode(input, &mut cpp_compressed)
4546
.expect("C++ compression failed"),
46-
RustCodec::FastPFOR128 => cpp::FastPFor128Codec::new()
47+
RustCodec::FastPFOR128 => CppFastPFor128::new()
4748
.encode(input, &mut cpp_compressed)
4849
.expect("C++ compression failed"),
49-
RustCodec::VariableByte => cpp::MaskedVByteCodec::new()
50+
RustCodec::VariableByte => CppMaskedVByte::new()
5051
.encode(input, &mut cpp_compressed)
5152
.expect("C++ compression failed"),
52-
RustCodec::JustCopy => cpp::CopyCodec::new()
53+
RustCodec::JustCopy => CppCopy::new()
5354
.encode(input, &mut cpp_compressed)
5455
.expect("C++ compression failed"),
5556
}

fuzz/fuzz_targets/rust_decompress_oracle.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#![no_main]
22

3-
use fastpfor::{AnyLenCodec, CodecToSlice, cpp, rust};
3+
use fastpfor::{AnyLenCodec, CodecToSlice, rust};
44
use libfuzzer_sys::fuzz_target;
55
mod common;
66
use common::*;
7+
use fastpfor::cpp::*;
78

89
fuzz_target!(|data: FuzzInput<RustCodec>| {
910
let input = data.data;
@@ -31,16 +32,16 @@ fuzz_target!(|data: FuzzInput<RustCodec>| {
3132
// First, compress with C++ implementation to get valid compressed data
3233
let mut cpp_compressed = Vec::new();
3334
match data.codec {
34-
RustCodec::FastPFOR256 => cpp::FastPFor256Codec::new()
35+
RustCodec::FastPFOR256 => CppFastPFor256::new()
3536
.encode(input, &mut cpp_compressed)
3637
.expect("C++ compression failed"),
37-
RustCodec::FastPFOR128 => cpp::FastPFor128Codec::new()
38+
RustCodec::FastPFOR128 => CppFastPFor128::new()
3839
.encode(input, &mut cpp_compressed)
3940
.expect("C++ compression failed"),
40-
RustCodec::VariableByte => cpp::MaskedVByteCodec::new()
41+
RustCodec::VariableByte => CppMaskedVByte::new()
4142
.encode(input, &mut cpp_compressed)
4243
.expect("C++ compression failed"),
43-
RustCodec::JustCopy => cpp::CopyCodec::new()
44+
RustCodec::JustCopy => CppCopy::new()
4445
.encode(input, &mut cpp_compressed)
4546
.expect("C++ compression failed"),
4647
}

justfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,15 @@ fmt:
8585
#!/usr/bin/env bash
8686
set -euo pipefail
8787
for dir in "./" "fuzz"; do
88-
cd "$dir"
88+
pushd "$dir"
8989
if (rustup toolchain list | grep nightly && rustup component list --toolchain nightly | grep rustfmt) &> /dev/null; then
9090
echo "Reformatting Rust code using nightly Rust fmt to sort imports in $dir"
9191
cargo +nightly fmt --all -- --config imports_granularity=Module,group_imports=StdExternalCrate
9292
else
9393
echo "Reformatting Rust with the stable cargo fmt in $dir. Install nightly with \`rustup install nightly\` for better results"
9494
cargo fmt --all
9595
fi
96-
if [ -f .git ]; then
97-
cd ..
98-
fi
96+
popd
9997
done
10098

10199
# Reformat all Cargo.toml files using cargo-sort

0 commit comments

Comments
 (0)