diff --git a/README.md b/README.md index b937bbd..24ab790 100644 --- a/README.md +++ b/README.md @@ -90,10 +90,11 @@ Feature selection can be overridden with the `FASTPFOR_SIMD_MODE` environment va ### Using C++ Wrapper ```rust -use fastpfor::{AnyLenCodec as _, cpp}; +use fastpfor::AnyLenCodec as _; +use fastpfor::cpp::CppSimdFastPFor128; fn main() { - let mut codec = cpp::SimdFastPFor128Codec::new(); + let mut codec = CppSimdFastPFor128::new(); let input = vec![1u32, 2, 3, 4, 5]; let mut compressed = Vec::new(); diff --git a/benches/bench_utils.rs b/benches/bench_utils.rs index 6b8be2e..089eeec 100644 --- a/benches/bench_utils.rs +++ b/benches/bench_utils.rs @@ -16,7 +16,7 @@ use std::num::NonZeroU32; #[cfg(feature = "cpp")] use fastpfor::AnyLenCodec as _; #[cfg(feature = "cpp")] -use fastpfor::cpp; +use fastpfor::cpp::CppFastPFor128; pub use fastpfor::rust::{BLOCK_SIZE_128, BLOCK_SIZE_256, DEFAULT_PAGE_SIZE, FastPFOR, Integer}; use rand::rngs::StdRng; use rand::{RngExt as _, SeedableRng}; @@ -171,7 +171,7 @@ fn prepare_compressed_data(data: &[u32], block_size: NonZeroU32) -> Vec { // --------------------------------------------------------------------------- #[cfg(feature = "cpp")] -pub fn cpp_encode(codec: &mut cpp::FastPFor128Codec, data: &[u32]) -> Vec { +pub fn cpp_encode(codec: &mut CppFastPFor128, data: &[u32]) -> Vec { let mut out = Vec::new(); codec.encode(data, &mut out).unwrap(); out @@ -179,7 +179,7 @@ pub fn cpp_encode(codec: &mut cpp::FastPFor128Codec, data: &[u32]) -> Vec { #[cfg(feature = "cpp")] pub fn cpp_decode( - codec: &mut cpp::FastPFor128Codec, + codec: &mut CppFastPFor128, compressed: &[u32], decompressed: &mut [u32], ) -> usize { @@ -275,7 +275,7 @@ pub struct CppDecodeFixture { impl CppDecodeFixture { fn new(name: &'static str, generator: DataGeneratorFn, size: usize) -> Self { let data = generator(size); - let mut codec = cpp::FastPFor128Codec::new(); + let mut codec = CppFastPFor128::new(); let cpp_compressed = cpp_encode(&mut codec, &data); let rust_compressed = prepare_compressed_data(&data, BLOCK_SIZE_128); Self { diff --git a/benches/fastpfor_benchmark.rs b/benches/fastpfor_benchmark.rs index 7fd61b2..212e3a5 100644 --- a/benches/fastpfor_benchmark.rs +++ b/benches/fastpfor_benchmark.rs @@ -14,7 +14,7 @@ use bench_utils::{ #[cfg(feature = "cpp")] use bench_utils::{cpp_decode, cpp_decode_fixtures, cpp_encode}; #[cfg(feature = "cpp")] -use fastpfor::cpp; +use fastpfor::cpp::CppFastPFor128; const SIZES: &[usize] = &[1024, 4096]; @@ -153,7 +153,7 @@ fn benchmark_cpp_vs_rust(c: &mut Criterion) { BenchmarkId::new(format!("cpp/{}", fix.name), size), &fix.data, |b, data| { - let mut codec = cpp::FastPFor128Codec::new(); + let mut codec = CppFastPFor128::new(); b.iter(|| black_box(cpp_encode(&mut codec, black_box(data)))); }, ); @@ -175,7 +175,7 @@ fn benchmark_cpp_vs_rust(c: &mut Criterion) { BenchmarkId::new(format!("cpp/{}", fix.name), size), &fix.cpp_compressed, |b, compressed| { - let mut codec = cpp::FastPFor128Codec::new(); + let mut codec = CppFastPFor128::new(); let mut out = vec![0u32; fix.original_len]; b.iter(|| black_box(cpp_decode(&mut codec, black_box(compressed), &mut out))); }, diff --git a/cpp b/cpp index aa1a6c3..2be1f97 160000 --- a/cpp +++ b/cpp @@ -1 +1 @@ -Subproject commit aa1a6c36efbdee8ef4c3ff71ea455bba0117ac41 +Subproject commit 2be1f976935b8ff9296b029f574d7f964be9d35d diff --git a/fuzz/fuzz_targets/common.rs b/fuzz/fuzz_targets/common.rs index ea6b8d5..c50f080 100644 --- a/fuzz/fuzz_targets/common.rs +++ b/fuzz/fuzz_targets/common.rs @@ -1,4 +1,5 @@ -use fastpfor::{AnyLenCodec, cpp, rust}; +use fastpfor::cpp::*; +use fastpfor::{AnyLenCodec, rust}; pub type BoxedCppCodec = Box; @@ -78,42 +79,40 @@ pub enum CppCodec { impl From for BoxedCppCodec { fn from(codec: CppCodec) -> Self { match codec { - CppCodec::BP32 => Box::new(cpp::BP32Codec::default()), - CppCodec::Copy => Box::new(cpp::CopyCodec::default()), - CppCodec::FastBinaryPacking8 => Box::new(cpp::FastBinaryPacking8Codec::default()), - CppCodec::FastPFor128 => Box::new(cpp::FastPFor128Codec::default()), - CppCodec::FastPFor256 => Box::new(cpp::FastPFor256Codec::default()), - CppCodec::FastBinaryPacking16 => Box::new(cpp::FastBinaryPacking16Codec::default()), - CppCodec::FastBinaryPacking32 => Box::new(cpp::FastBinaryPacking32Codec::default()), - CppCodec::MaskedVByte => Box::new(cpp::MaskedVByteCodec::default()), - CppCodec::NewPFor => Box::new(cpp::NewPForCodec::default()), - CppCodec::OptPFor => Box::new(cpp::OptPForCodec::default()), - CppCodec::PFor2008 => Box::new(cpp::PFor2008Codec::default()), - CppCodec::PFor => Box::new(cpp::PForCodec::default()), - CppCodec::SimdBinaryPacking => Box::new(cpp::SimdBinaryPackingCodec::default()), - CppCodec::SimdFastPFor128 => Box::new(cpp::SimdFastPFor128Codec::default()), - CppCodec::SimdFastPFor256 => Box::new(cpp::SimdFastPFor256Codec::default()), - CppCodec::SimdGroupSimple => Box::new(cpp::SimdGroupSimpleCodec::default()), - CppCodec::SimdGroupSimpleRingBuf => { - Box::new(cpp::SimdGroupSimpleRingBufCodec::default()) - } - CppCodec::SimdNewPFor => Box::new(cpp::SimdNewPForCodec::default()), - CppCodec::SimdOptPFor => Box::new(cpp::SimdOptPForCodec::default()), - CppCodec::SimdPFor => Box::new(cpp::SimdPForCodec::default()), - CppCodec::SimdSimplePFor => Box::new(cpp::SimdSimplePForCodec::default()), - // CppCodec::Simple16 => Box::new(cpp::Simple16Codec::default()), - // CppCodec::Simple8b => Box::new(cpp::Simple8bCodec::default()), - // CppCodec::Simple8bRle => Box::new(cpp::Simple8bRleCodec::default()), - // CppCodec::Simple9 => Box::new(cpp::Simple9Codec::default()), - // CppCodec::Simple9Rle => Box::new(cpp::Simple9RleCodec::default()), - // CppCodec::SimplePFor => Box::new(cpp::SimplePForCodec::default()), - // CppCodec::Snappy => Box::new(cpp::SnappyCodec::default()), - CppCodec::StreamVByte => Box::new(cpp::StreamVByteCodec::default()), - CppCodec::VByte => Box::new(cpp::VByteCodec::default()), - CppCodec::VarInt => Box::new(cpp::VarIntCodec::default()), - // CppCodec::VarIntG8iu => Box::new(cpp::VarIntG8iuCodec::default()), - CppCodec::VarIntGb => Box::new(cpp::VarIntGbCodec::default()), - // CppCodec::VsEncoding => Box::new(cpp::VsEncodingCodec::default()), + CppCodec::BP32 => Box::new(CppBP32::default()), + CppCodec::Copy => Box::new(CppCopy::default()), + CppCodec::FastBinaryPacking8 => Box::new(CppFastBinaryPacking8::default()), + CppCodec::FastPFor128 => Box::new(CppFastPFor128::default()), + CppCodec::FastPFor256 => Box::new(CppFastPFor256::default()), + CppCodec::FastBinaryPacking16 => Box::new(CppFastBinaryPacking16::default()), + CppCodec::FastBinaryPacking32 => Box::new(CppFastBinaryPacking32::default()), + CppCodec::MaskedVByte => Box::new(CppMaskedVByte::default()), + CppCodec::NewPFor => Box::new(CppNewPFor::default()), + CppCodec::OptPFor => Box::new(CppOptPFor::default()), + CppCodec::PFor2008 => Box::new(CppPFor2008::default()), + CppCodec::PFor => Box::new(CppPFor::default()), + CppCodec::SimdBinaryPacking => Box::new(CppSimdBinaryPacking::default()), + CppCodec::SimdFastPFor128 => Box::new(CppSimdFastPFor128::default()), + CppCodec::SimdFastPFor256 => Box::new(CppSimdFastPFor256::default()), + CppCodec::SimdGroupSimple => Box::new(CppSimdGroupSimple::default()), + CppCodec::SimdGroupSimpleRingBuf => Box::new(CppSimdGroupSimpleRingBuf::default()), + CppCodec::SimdNewPFor => Box::new(CppSimdNewPFor::default()), + CppCodec::SimdOptPFor => Box::new(CppSimdOptPFor::default()), + CppCodec::SimdPFor => Box::new(CppSimdPFor::default()), + CppCodec::SimdSimplePFor => Box::new(CppSimdSimplePFor::default()), + // CppCodec::Simple16 => Box::new(CppSimple16::default()), + // CppCodec::Simple8b => Box::new(CppSimple8b::default()), + // CppCodec::Simple8bRle => Box::new(CppSimple8bRle::default()), + // CppCodec::Simple9 => Box::new(CppSimple9::default()), + // CppCodec::Simple9Rle => Box::new(CppSimple9Rle::default()), + // CppCodec::SimplePFor => Box::new(CppSimplePFor::default()), + // CppCodec::Snappy => Box::new(CppSnappy::default()), + CppCodec::StreamVByte => Box::new(CppStreamVByte::default()), + CppCodec::VByte => Box::new(CppVByte::default()), + CppCodec::VarInt => Box::new(CppVarInt::default()), + // CppCodec::VarIntG8iu => Box::new(CppVarIntG8iu::default()), + CppCodec::VarIntGb => Box::new(CppVarIntGb::default()), + // CppCodec::VsEncoding => Box::new(CppVsEncoding::default()), } } } diff --git a/fuzz/fuzz_targets/rust_compress_oracle.rs b/fuzz/fuzz_targets/rust_compress_oracle.rs index ff10ab2..291f9b5 100644 --- a/fuzz/fuzz_targets/rust_compress_oracle.rs +++ b/fuzz/fuzz_targets/rust_compress_oracle.rs @@ -1,9 +1,10 @@ #![no_main] -use fastpfor::{AnyLenCodec, CodecToSlice, cpp, rust}; +use fastpfor::{AnyLenCodec, CodecToSlice, rust}; use libfuzzer_sys::fuzz_target; mod common; use common::*; +use fastpfor::cpp::*; fuzz_target!(|data: FuzzInput| { let input = data.data; @@ -40,16 +41,16 @@ fuzz_target!(|data: FuzzInput| { // Compress with C++ implementation (`AnyLenCodec` / Vec API) let mut cpp_compressed = Vec::new(); match data.codec { - RustCodec::FastPFOR256 => cpp::FastPFor256Codec::new() + RustCodec::FastPFOR256 => CppFastPFor256::new() .encode(input, &mut cpp_compressed) .expect("C++ compression failed"), - RustCodec::FastPFOR128 => cpp::FastPFor128Codec::new() + RustCodec::FastPFOR128 => CppFastPFor128::new() .encode(input, &mut cpp_compressed) .expect("C++ compression failed"), - RustCodec::VariableByte => cpp::MaskedVByteCodec::new() + RustCodec::VariableByte => CppMaskedVByte::new() .encode(input, &mut cpp_compressed) .expect("C++ compression failed"), - RustCodec::JustCopy => cpp::CopyCodec::new() + RustCodec::JustCopy => CppCopy::new() .encode(input, &mut cpp_compressed) .expect("C++ compression failed"), } diff --git a/fuzz/fuzz_targets/rust_decompress_oracle.rs b/fuzz/fuzz_targets/rust_decompress_oracle.rs index 2e4a0f7..4807cd8 100644 --- a/fuzz/fuzz_targets/rust_decompress_oracle.rs +++ b/fuzz/fuzz_targets/rust_decompress_oracle.rs @@ -1,9 +1,10 @@ #![no_main] -use fastpfor::{AnyLenCodec, CodecToSlice, cpp, rust}; +use fastpfor::{AnyLenCodec, CodecToSlice, rust}; use libfuzzer_sys::fuzz_target; mod common; use common::*; +use fastpfor::cpp::*; fuzz_target!(|data: FuzzInput| { let input = data.data; @@ -31,16 +32,16 @@ fuzz_target!(|data: FuzzInput| { // First, compress with C++ implementation to get valid compressed data let mut cpp_compressed = Vec::new(); match data.codec { - RustCodec::FastPFOR256 => cpp::FastPFor256Codec::new() + RustCodec::FastPFOR256 => CppFastPFor256::new() .encode(input, &mut cpp_compressed) .expect("C++ compression failed"), - RustCodec::FastPFOR128 => cpp::FastPFor128Codec::new() + RustCodec::FastPFOR128 => CppFastPFor128::new() .encode(input, &mut cpp_compressed) .expect("C++ compression failed"), - RustCodec::VariableByte => cpp::MaskedVByteCodec::new() + RustCodec::VariableByte => CppMaskedVByte::new() .encode(input, &mut cpp_compressed) .expect("C++ compression failed"), - RustCodec::JustCopy => cpp::CopyCodec::new() + RustCodec::JustCopy => CppCopy::new() .encode(input, &mut cpp_compressed) .expect("C++ compression failed"), } diff --git a/justfile b/justfile index 5fc804e..21c9940 100755 --- a/justfile +++ b/justfile @@ -85,7 +85,7 @@ fmt: #!/usr/bin/env bash set -euo pipefail for dir in "./" "fuzz"; do - cd "$dir" + pushd "$dir" if (rustup toolchain list | grep nightly && rustup component list --toolchain nightly | grep rustfmt) &> /dev/null; then echo "Reformatting Rust code using nightly Rust fmt to sort imports in $dir" cargo +nightly fmt --all -- --config imports_granularity=Module,group_imports=StdExternalCrate @@ -93,9 +93,7 @@ fmt: echo "Reformatting Rust with the stable cargo fmt in $dir. Install nightly with \`rustup install nightly\` for better results" cargo fmt --all fi - if [ -f .git ]; then - cd .. - fi + popd done # Reformat all Cargo.toml files using cargo-sort diff --git a/src/cpp/codecs.rs b/src/cpp/codecs.rs index e8d4743..2ac6750 100644 --- a/src/cpp/codecs.rs +++ b/src/cpp/codecs.rs @@ -12,7 +12,7 @@ use crate::cpp::wrappers::{ // Single macro: all C++ codecs implement AnyLenCodec. Codecs marked with `@ 64` // also implement BlockCodec64 for 64-bit integer support. -/// Macro for C++ codec wrappers: struct + Default + `AnyLenCodec`. +/// Macro for C++ codec wrappers: struct + Default + [`AnyLenCodec`]. macro_rules! implement_cpp_codecs { ($( $(#[$($attrs:tt)*])* @@ -57,103 +57,103 @@ macro_rules! implement_cpp_codecs { // ── All C++ codecs (composite / any-length) ─ implement_cpp_codecs! { /// Binary Packing codec optimized for 32-bit blocks. - BP32Codec => BP32_codec, + CppBP32 => BP32_codec, /// Copy codec that performs no compression. - CopyCodec => copy_codec, + CppCopy => copy_codec, /// Fast binary packing with 8-bit processing blocks. - FastBinaryPacking8Codec => fastbinarypacking8_codec, + CppFastBinaryPacking8 => fastbinarypacking8_codec, /// Fast binary packing with 16-bit processing blocks. - FastBinaryPacking16Codec => fastbinarypacking16_codec, + CppFastBinaryPacking16 => fastbinarypacking16_codec, /// Fast binary packing with 32-bit processing blocks. - FastBinaryPacking32Codec => fastbinarypacking32_codec, + CppFastBinaryPacking32 => fastbinarypacking32_codec, - /// Fast [`PForCodec`] with 128-value processing blocks. - FastPFor128Codec => fastpfor128_codec, + /// Fast [`CppPFor`] with 128-value processing blocks. + CppFastPFor128 => fastpfor128_codec, - /// Fast [`PForCodec`] with 256-value processing blocks. - FastPFor256Codec => fastpfor256_codec, + /// Fast [`CppPFor`] with 256-value processing blocks. + CppFastPFor256 => fastpfor256_codec, - /// Masked [`VByteCodec`] with SIMD optimizations. - MaskedVByteCodec => maskedvbyte_codec, + /// Masked [`CppVByte`] with SIMD optimizations. + CppMaskedVByte => maskedvbyte_codec, - /// New [`PForCodec`]. - NewPForCodec => newpfor_codec, + /// New [`CppPFor`]. + CppNewPFor => newpfor_codec, - /// Optimized [`PForCodec`]. - OptPForCodec => optpfor_codec, + /// Optimized [`CppPFor`]. + CppOptPFor => optpfor_codec, - /// [`PForCodec`] based on the 2008 research paper. - PFor2008Codec => pfor2008_codec, + /// [`CppPFor`] based on the 2008 research paper. + CppPFor2008 => pfor2008_codec, /// Standard Patched Frame of Reference codec. - PForCodec => pfor_codec, + CppPFor => pfor_codec, /// SIMD-accelerated binary packing codec. - SimdBinaryPackingCodec => simdbinarypacking_codec, + CppSimdBinaryPacking => simdbinarypacking_codec, - /// SIMD-optimized [`FastPFor128Codec`] with 128-value blocks. - SimdFastPFor128Codec => simdfastpfor128_codec, + /// SIMD-optimized [`CppFastPFor128`] with 128-value blocks. + CppSimdFastPFor128 => simdfastpfor128_codec, - /// SIMD-optimized [`FastPFor256Codec`] with 256-value blocks. - SimdFastPFor256Codec => simdfastpfor256_codec, + /// SIMD-optimized [`CppFastPFor256`] with 256-value blocks. + CppSimdFastPFor256 => simdfastpfor256_codec, /// SIMD group simple codec. - SimdGroupSimpleCodec => simdgroupsimple_codec, + CppSimdGroupSimple => simdgroupsimple_codec, /// SIMD group simple codec with ring buffer optimization. - SimdGroupSimpleRingBufCodec => simdgroupsimple_ringbuf_codec, + CppSimdGroupSimpleRingBuf => simdgroupsimple_ringbuf_codec, - /// SIMD-accelerated [`NewPForCodec`]. - SimdNewPForCodec => simdnewpfor_codec, + /// SIMD-accelerated [`CppNewPFor`]. + CppSimdNewPFor => simdnewpfor_codec, - /// SIMD-accelerated [`OptPForCodec`]. - SimdOptPForCodec => simdoptpfor_codec, + /// SIMD-accelerated [`CppOptPFor`]. + CppSimdOptPFor => simdoptpfor_codec, - /// SIMD-accelerated [`PForCodec`]. - SimdPForCodec => simdpfor_codec, + /// SIMD-accelerated [`CppPFor`]. + CppSimdPFor => simdpfor_codec, - /// SIMD-accelerated [`SimplePForCodec`]. - SimdSimplePForCodec => simdsimplepfor_codec, + /// SIMD-accelerated [`CppSimplePFor`]. + CppSimdSimplePFor => simdsimplepfor_codec, /// Simple-16 encoding scheme. - Simple16Codec => simple16_codec, + CppSimple16 => simple16_codec, /// Simple-8b encoding scheme. - Simple8bCodec => simple8b_codec, + CppSimple8b => simple8b_codec, /// Simple-8b encoding with run-length encoding. - Simple8bRleCodec => simple8b_rle_codec, + CppSimple8bRle => simple8b_rle_codec, /// Simple-9 encoding scheme. - Simple9Codec => simple9_codec, + CppSimple9 => simple9_codec, /// Simple-9 encoding with run-length encoding. - Simple9RleCodec => simple9_rle_codec, + CppSimple9Rle => simple9_rle_codec, - /// Simple Patched Frame of Reference ([`PForCodec`]) codec. - SimplePForCodec => simplepfor_codec, + /// Simple Patched Frame of Reference ([`CppPFor`]) codec. + CppSimplePFor => simplepfor_codec, - // SnappyCodec => snappy_codec, // Conditional with #ifdef + // CppSnappy => snappy_codec, // Conditional with #ifdef - /// [`StreamVByteCodec`](https://github.com/lemire/streamvbyte) encoding for fast variable-byte compression. - StreamVByteCodec => streamvbyte_codec, + /// [`CppStreamVByte`](https://github.com/lemire/streamvbyte) encoding for fast variable-byte compression. + CppStreamVByte => streamvbyte_codec, /// Standard variable-byte encoding. - VByteCodec => vbyte_codec, + CppVByte => vbyte_codec, /// Variable-length integer encoding. - VarIntCodec => varint_codec, + CppVarInt => varint_codec, - // VarIntG8iuCodec => varintg8iu_codec, // Conditional with #ifdef + // CppVarIntG8iu => varintg8iu_codec, // Conditional with #ifdef /// Group Variable-length integer encoding with optimizations. - VarIntGbCodec => varintgb_codec, + CppVarIntGb => varintgb_codec, - // VsEncodingCodec => vsencoding_codec, // This is leaking memory + // CppVsEncoding => vsencoding_codec, // This is leaking memory } /// Adds `BlockCodec64` impl for codecs that support 64-bit integers. @@ -173,15 +173,15 @@ macro_rules! implement_cpp_codecs_64 { } implement_cpp_codecs_64! { - FastPFor128Codec => fastpfor128_codec, - FastPFor256Codec => fastpfor256_codec, - VarIntCodec => varint_codec, + CppFastPFor128 => fastpfor128_codec, + CppFastPFor256 => fastpfor256_codec, + CppVarInt => varint_codec, } #[cfg(test)] pub(crate) mod tests { use crate::codec::{AnyLenCodec, BlockCodec64}; - use crate::cpp::codecs::{FastPFor128Codec, FastPFor256Codec, VByteCodec, VarIntCodec}; + use crate::cpp::codecs::{CppFastPFor128, CppFastPFor256, CppVByte, CppVarInt}; pub fn roundtrip_32(codec: &mut (impl AnyLenCodec + ?Sized), input: &[u32]) { let mut compressed = Vec::new(); @@ -192,10 +192,10 @@ pub(crate) mod tests { } /// C++ `fastpfor256_codec` returns `CompositeCodec, VariableByte>` — already - /// any-length. Use it directly; do not wrap in Rust `CompositeCodec`. + /// any-length. Use it directly; do not wrap in Rust `CppComposite`. #[test] fn test_cpp_fastpfor256_composite_anylen() { - let mut codec = FastPFor256Codec::new(); + let mut codec = CppFastPFor256::new(); roundtrip_32(&mut codec, &[1, 2, 3, 4, 5]); let data: Vec = (0..600).collect(); roundtrip_32(&mut codec, &data); @@ -204,19 +204,19 @@ pub(crate) mod tests { #[test] fn test_fastpfor128_anylen() { let data: Vec = (0..128).collect(); - roundtrip_32(&mut FastPFor128Codec::new(), &data); + roundtrip_32(&mut CppFastPFor128::new(), &data); } #[test] fn test_fastpfor256_anylen() { let data: Vec = (0..256).collect(); - roundtrip_32(&mut FastPFor256Codec::new(), &data); + roundtrip_32(&mut CppFastPFor256::new(), &data); } #[test] fn test_fastpfor256_u64() { let input: Vec = (0..256).collect(); - let mut codec = FastPFor256Codec::new(); + let mut codec = CppFastPFor256::new(); let mut compressed = Vec::new(); codec.encode64(&input, &mut compressed).unwrap(); let mut decoded = Vec::new(); @@ -227,7 +227,7 @@ pub(crate) mod tests { #[test] fn test_varint_u64() { let input = vec![1u64, 2, 3, 4, 5]; - let mut codec = VarIntCodec::new(); + let mut codec = CppVarInt::new(); let mut compressed = Vec::new(); codec.encode64(&input, &mut compressed).unwrap(); let mut decoded = Vec::new(); @@ -237,7 +237,7 @@ pub(crate) mod tests { #[test] fn test_decode32_empty_input() { - let mut codec = VByteCodec::new(); + let mut codec = CppVByte::new(); let mut out = Vec::new(); codec.decode(&[], &mut out, None).unwrap(); assert!(out.is_empty()); @@ -245,7 +245,7 @@ pub(crate) mod tests { #[test] fn test_decode32_cpp_empty_format() { - let mut codec = FastPFor128Codec::new(); + let mut codec = CppFastPFor128::new(); let mut out = Vec::new(); codec.decode(&[0u32], &mut out, Some(0)).unwrap(); assert!(out.is_empty()); @@ -253,7 +253,7 @@ pub(crate) mod tests { #[test] fn test_decode64_empty_input() { - let mut codec = FastPFor256Codec::new(); + let mut codec = CppFastPFor256::new(); let mut out: Vec = Vec::new(); codec.decode64(&[], &mut out).unwrap(); assert!(out.is_empty()); @@ -261,7 +261,7 @@ pub(crate) mod tests { #[test] fn test_decode64_empty_format() { - let mut codec = VarIntCodec::new(); + let mut codec = CppVarInt::new(); let mut out: Vec = Vec::new(); codec.decode64(&[], &mut out).unwrap(); assert!(out.is_empty()); @@ -269,7 +269,7 @@ pub(crate) mod tests { #[test] fn test_decode_empty_input() { - let mut codec = FastPFor128Codec::new(); + let mut codec = CppFastPFor128::new(); let mut out = Vec::new(); codec.decode(&[], &mut out, None).unwrap(); assert!(out.is_empty()); diff --git a/src/cpp/tests.rs b/src/cpp/tests.rs index 3147391..4845c0a 100644 --- a/src/cpp/tests.rs +++ b/src/cpp/tests.rs @@ -1,51 +1,51 @@ use crate::cpp::codecs::tests::roundtrip_32; -// Test all codecs compile and do a basic 32-bit roundtrip +/// Test all codecs compile and do a basic 32-bit roundtrip macro_rules! test_anylen { - ($($name:ident),*) => { - $( - #[test] - #[allow(non_snake_case)] - fn $name() { - roundtrip_32(&mut $crate::cpp::$name::new(), &[1u32, 2, 3, 4, 5]); - } - )* - }; - } + ($($name:ident),* $(,)?) => { + $( + #[test] + #[allow(non_snake_case)] + fn $name() { + roundtrip_32(&mut $crate::cpp::$name::new(), &[1u32, 2, 3, 4, 5]); + } + )* + }; +} test_anylen!( - BP32Codec, - CopyCodec, - FastBinaryPacking8Codec, - FastBinaryPacking16Codec, - FastBinaryPacking32Codec, - FastPFor128Codec, - FastPFor256Codec, - MaskedVByteCodec, - NewPForCodec, - OptPForCodec, - PFor2008Codec, - PForCodec, - SimdBinaryPackingCodec, - SimdFastPFor128Codec, - SimdFastPFor256Codec, - SimdGroupSimpleCodec, - SimdGroupSimpleRingBufCodec, - SimdNewPForCodec, - SimdOptPForCodec, - SimdPForCodec, - SimdSimplePForCodec, - SimplePForCodec, - StreamVByteCodec, - VByteCodec, - VarIntCodec, - VarIntGbCodec + CppBP32, + CppCopy, + CppFastBinaryPacking16, + CppFastBinaryPacking32, + CppFastBinaryPacking8, + CppFastPFor128, + CppFastPFor256, + CppMaskedVByte, + CppNewPFor, + CppOptPFor, + CppPFor, + CppPFor2008, + CppSimdBinaryPacking, + CppSimdFastPFor128, + CppSimdFastPFor256, + CppSimdGroupSimple, + CppSimdGroupSimpleRingBuf, + CppSimdNewPFor, + CppSimdOptPFor, + CppSimdPFor, + CppSimdSimplePFor, + CppSimplePFor, + CppStreamVByte, + CppVByte, + CppVarInt, + CppVarIntGb, ); -// Simple-9/16/8b codecs require values that fit in small bit widths and a -// block-aligned count; test them separately with 128 small values. +/// Simple-9/16/8b codecs require values that fit in small bit widths and a +/// block-aligned count; test them separately with 128 small values. macro_rules! test_anylen_128 { - ($($name:ident),*) => { + ($($name:ident),* $(,)?) => { $( #[test] #[allow(non_snake_case)] @@ -58,66 +58,54 @@ macro_rules! test_anylen_128 { } // Note: Simple9Rle crashes with heap corruption on various inputs; skip everywhere. -test_anylen_128!(Simple16Codec, Simple8bCodec, Simple9Codec); - -// Simple8bRle reinterpret-casts uint32_t* → uint64_t* inside the C++ header, -// which is UB on strict-alignment architectures (ARM64 requires 8-byte alignment -// for 64-bit loads/stores and will SIGSEGV on unaligned access). The codec is -// otherwise correct on x86/x86_64 where unaligned access is handled in hardware. -// Tracked upstream; skip on aarch64 until fixed in the submodule. -// #[cfg(not(target_arch = "aarch64"))] -test_anylen_128!(Simple8bRleCodec); +test_anylen_128!(CppSimple16, CppSimple8b, CppSimple9, CppSimple8bRle); // Verify Default impl routes through new() for all generated codec types. macro_rules! test_default { - ($($name:ident),*) => { - $( - #[test] - #[allow(non_snake_case)] - fn $name() { - let _codec = $crate::cpp::$name::default(); - } - )* - }; - } + ($($name:ident),* $(,)?) => { + $( + #[test] + #[allow(non_snake_case)] + fn $name() { + let _codec = $crate::cpp::$name::default(); + } + )* + }; +} -// Use a distinct prefix to avoid name collisions with test_anylen tests. +/// Use a distinct prefix to avoid name collisions with `test_anylen` tests. mod default_impls { test_default!( - BP32Codec, - CopyCodec, - FastBinaryPacking8Codec, - FastBinaryPacking16Codec, - FastBinaryPacking32Codec, - FastPFor128Codec, - FastPFor256Codec, - MaskedVByteCodec, - NewPForCodec, - OptPForCodec, - PFor2008Codec, - PForCodec, - SimdBinaryPackingCodec, - SimdFastPFor128Codec, - SimdFastPFor256Codec, - SimdGroupSimpleCodec, - SimdGroupSimpleRingBufCodec, - SimdNewPForCodec, - SimdOptPForCodec, - SimdPForCodec, - SimdSimplePForCodec, - Simple16Codec, - Simple8bCodec, - Simple8bRleCodec, - Simple9Codec, - SimplePForCodec, - StreamVByteCodec, - VByteCodec, - VarIntCodec, - VarIntGbCodec + CppBP32, + CppCopy, + CppFastBinaryPacking16, + CppFastBinaryPacking32, + CppFastBinaryPacking8, + CppFastPFor128, + CppFastPFor256, + CppMaskedVByte, + CppNewPFor, + CppOptPFor, + CppPFor, + CppPFor2008, + CppSimdBinaryPacking, + CppSimdFastPFor128, + CppSimdFastPFor256, + CppSimdGroupSimple, + CppSimdGroupSimpleRingBuf, + CppSimdNewPFor, + CppSimdOptPFor, + CppSimdPFor, + CppSimdSimplePFor, + CppSimple16, + CppSimple8b, + CppSimple8bRle, + CppSimple9, + CppSimple9Rle, + CppSimplePFor, + CppStreamVByte, + CppVByte, + CppVarInt, + CppVarIntGb, ); } - -mod default_impls2 { - // #[cfg(not(target_arch = "aarch64"))] - test_default!(Simple9RleCodec); -} diff --git a/tests/benchmark_smoke.rs b/tests/benchmark_smoke.rs index 68932d7..fbc1e8c 100644 --- a/tests/benchmark_smoke.rs +++ b/tests/benchmark_smoke.rs @@ -15,7 +15,7 @@ use bench_utils::{ #[cfg(feature = "cpp")] use bench_utils::{cpp_decode, cpp_decode_fixtures}; #[cfg(feature = "cpp")] -use fastpfor::cpp; +use fastpfor::cpp::CppFastPFor128; const SMOKE_SIZE: usize = 256; @@ -112,7 +112,7 @@ fn smoke_compression_ratio() { fn smoke_cpp_vs_rust() { for (_, fix) in cpp_decode_fixtures(&[SMOKE_SIZE]) { // C++ decode - let mut codec = cpp::FastPFor128Codec::new(); + let mut codec = CppFastPFor128::new(); let mut cpp_out = vec![0u32; fix.original_len]; let n = cpp_decode(&mut codec, &fix.cpp_compressed, &mut cpp_out); assert_eq!( diff --git a/tests/cpp_compat_tests.rs b/tests/cpp_compat_tests.rs index a01b894..8d2c618 100644 --- a/tests/cpp_compat_tests.rs +++ b/tests/cpp_compat_tests.rs @@ -5,14 +5,15 @@ use std::io::Cursor; use fastpfor::rust::Integer as _; -use fastpfor::{AnyLenCodec as _, cpp, rust}; +use fastpfor::{AnyLenCodec as _, rust}; mod common; use common::{get_test_cases, test_input_sizes}; +use fastpfor::cpp::CppFastPFor128; #[test] fn test_rust_decompresses_cpp_encoded_data() { - let mut codec_cpp = cpp::FastPFor128Codec::new(); + let mut codec_cpp = CppFastPFor128::new(); let mut codec_rs = rust::FastPFOR::new(rust::DEFAULT_PAGE_SIZE, rust::BLOCK_SIZE_128); for n in test_input_sizes() { @@ -56,7 +57,7 @@ fn test_rust_decompresses_cpp_encoded_data() { #[test] fn test_rust_and_cpp_fastpfor32_compression_matches() { - let mut codec_cpp = cpp::FastPFor128Codec::new(); + let mut codec_cpp = CppFastPFor128::new(); let mut codec_rs = rust::FastPFOR::new(rust::DEFAULT_PAGE_SIZE, rust::BLOCK_SIZE_128); for n in test_input_sizes() {