Skip to content

Commit 115d91a

Browse files
doc: document the missing few items (#57)
This PR is the last in the row of PRs to improve the documentation (since now every item has docs)
1 parent 4985ffa commit 115d91a

17 files changed

Lines changed: 96 additions & 41 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ rand = "0.10.0"
4545
dead_code = "allow"
4646
unused_assignments = "allow"
4747
unused_qualifications = "warn"
48+
missing_docs = "warn"
4849

4950
[lints.clippy]
5051
cargo = { level = "warn", priority = -1 }

benches/fastpfor_benchmark.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Benchmark suite for `FastPFOR` compression codecs.
2+
13
use core::ops::Range;
24
use std::hint::black_box;
35
use std::io::Cursor;

build.rs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
1-
fn main() {
2-
#[cfg(feature = "cpp")]
3-
{
4-
use std::path::Path;
1+
//! Build script for `FastPFOR-rs`.
52
6-
assert!(
7-
Path::new("cpp/CMakeLists.txt").exists(),
8-
"FastPFOR submodule not initialized. Run `git submodule update --init`."
9-
);
3+
/// Builds the C++ `FastPFOR` library and bridge when the `cpp` feature is enabled.
4+
#[cfg(feature = "cpp")]
5+
fn build_fastpfor() {
6+
use std::path::Path;
107

11-
// Compile FastPFOR using CMake
12-
println!("cargo:rerun-if-changed=cpp");
13-
let lib_path = cmake::Config::new("cpp")
14-
.define("WITH_TEST", "OFF")
15-
.build()
16-
.join("lib");
17-
let lib_path = lib_path.to_str().unwrap();
8+
assert!(
9+
Path::new("cpp/CMakeLists.txt").exists(),
10+
"FastPFOR submodule not initialized. Run `git submodule update --init`."
11+
);
1812

19-
// Compile the bridge
20-
println!("cargo:rerun-if-changed=src/cpp/fastpfor_bridge.h");
21-
println!("cargo:rerun-if-changed=src/cpp/mod.rs");
22-
cxx_build::bridge("src/cpp/mod.rs")
23-
.include("cpp/headers")
24-
.include("src/cpp")
25-
.std("c++14")
26-
.compile("fastpfor_bridge");
13+
// Compile FastPFOR using CMake
14+
println!("cargo:rerun-if-changed=cpp");
15+
let lib_path = cmake::Config::new("cpp")
16+
.define("WITH_TEST", "OFF")
17+
.build()
18+
.join("lib");
19+
let lib_path = lib_path.to_str().unwrap();
2720

28-
// Link the FastPFOR library - must be done after the bridge is compiled
29-
println!("cargo:rustc-link-search=native={lib_path}");
30-
println!("cargo:rustc-link-lib=static=FastPFOR");
31-
}
21+
// Compile the bridge
22+
println!("cargo:rerun-if-changed=src/cpp/fastpfor_bridge.h");
23+
println!("cargo:rerun-if-changed=src/cpp/mod.rs");
24+
cxx_build::bridge("src/cpp/mod.rs")
25+
.include("cpp/headers")
26+
.include("src/cpp")
27+
.std("c++14")
28+
.compile("fastpfor_bridge");
29+
30+
// Link the FastPFOR library - must be done after the bridge is compiled
31+
println!("cargo:rustc-link-search=native={lib_path}");
32+
println!("cargo:rustc-link-lib=static=FastPFOR");
33+
}
34+
35+
/// Build script entry point.
36+
fn main() {
37+
#[cfg(feature = "cpp")]
38+
build_fastpfor();
3239
}

fuzz/fuzz_targets/fastpfor_rust.rs

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

33
use std::io::Cursor;
4+
use std::num::NonZeroU32;
45

5-
use fastpfor::rust::{FastPFOR, Integer, BLOCK_SIZE_128, BLOCK_SIZE_256, DEFAULT_PAGE_SIZE};
6+
use fastpfor::rust::{BLOCK_SIZE_128, BLOCK_SIZE_256, DEFAULT_PAGE_SIZE, FastPFOR, Integer};
67
use libfuzzer_sys::fuzz_target;
7-
use std::num::NonZeroU32;
88

99
fuzz_target!(|data: FuzzInput| {
1010
let input = data.data;

src/rust/cursor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::io::Cursor;
22

3+
/// Extension trait for `Cursor<u32>` providing position increment operations.
34
pub trait IncrementCursor {
5+
/// Increments the cursor position by 1.
46
fn increment(&mut self);
7+
/// Adds `n` to the cursor position.
58
fn add(&mut self, n: u32);
69
}
710

src/rust/integer_compression/bitpacking.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![expect(clippy::identity_op)]
22

3+
/// Packs 32 integers from `input` into `output` using `bit` bits per integer.
34
pub fn fast_pack(input: &[u32], inpos: usize, output: &mut [u32], outpos: usize, bit: u8) {
45
match bit {
56
0 => (),
@@ -1299,6 +1300,7 @@ fn fast_pack32(input: &[u32], inpos: usize, output: &mut [u32], outpos: usize) {
12991300
output[outpos..outpos + 32].copy_from_slice(&input[inpos..inpos + 32]);
13001301
}
13011302

1303+
/// Unpacks 32 integers from `input` into `output` using `bit` bits per integer.
13021304
pub fn fast_unpack(input: &[u32], inpos: usize, output: &mut [u32], outpos: usize, bit: u8) {
13031305
match bit {
13041306
0 => fast_unpack0(output, outpos),

src/rust/integer_compression/codec.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
use crate::rust::{FastPFOR, JustCopy, VariableByte};
22

3+
/// Type-erased wrapper for compression codecs.
4+
///
5+
/// Allows different codec types to be used interchangeably through a unified interface.
36
pub enum Codec {
7+
/// [`FastPFOR`] compression codec
48
FastPFor(Box<FastPFOR>),
9+
/// [`VariableByte`] compression codec
510
VariableByte(VariableByte),
11+
/// Pass-through codec (no compression)
612
JustCopy(JustCopy),
713
}
814

src/rust/integer_compression/composition.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ use std::io::Cursor;
33
use crate::rust::cursor::IncrementCursor;
44
use crate::rust::{Codec, FastPForResult, Integer};
55

6+
/// Chains two codecs together, applying them sequentially.
7+
///
8+
/// Compresses data first with `c1`, then with `c2` on the remaining data.
69
pub struct Composition {
710
c1: Codec,
811
c2: Codec,
912
}
1013

1114
impl Composition {
15+
/// Creates a new instance of the composition codec.
1216
pub fn new<C1, C2>(c1: C1, c2: C2) -> Self
1317
where
1418
C1: Into<Codec>,

src/rust/integer_compression/differential/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
use std::ops::{Add, AddAssign};
22

3+
/// Delta encoding/decoding utility for integer compression.
34
pub struct Delta;
45

56
impl Delta {
7+
/// Creates a new instance
68
pub fn new() -> Delta {
79
Delta
810
}
911

1012
// C++ port as it supports any type of numeric data
1113
// source: https://github.com/fast-pack/FastPFor/blob/49d44d94773518ef26486f7a58f8da08e8a498bb/headers/deltautil.h#L274
14+
/// Applies inverse delta encoding to decompress delta-encoded data in place.
1215
pub fn fast_inverse_delta<T>(data: &mut [T])
1316
where
1417
T: Copy + Add<Output = T> + AddAssign,

src/rust/integer_compression/fastpfor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ pub struct FastPFOR {
4040
/// Frequency count for each bit width:
4141
/// `freqs[i]` = count of values needing exactly i bits
4242
pub freqs: [u32; 33],
43+
/// Optimal number of bits chosen for the current block
4344
pub optimal_bits: u32,
45+
/// Number of exceptions that don't fit in the optimal bit width
4446
pub exception_count: u32,
47+
/// Maximum bit width required for any value in the block
4548
pub max_bits: u32,
4649
/// Integers per block (128 or 256)
4750
pub block_size: u32,

0 commit comments

Comments
 (0)