Skip to content

Commit 566b50a

Browse files
committed
chore: cleanup results
1 parent bf5c165 commit 566b50a

8 files changed

Lines changed: 48 additions & 55 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ Unless otherwise specified, all codecs support `&[u32]` only.
1818
```text
1919
* BP32
2020
* Copy
21+
* FastBinaryPacking16
22+
* FastBinaryPacking32
2123
* FastBinaryPacking8
2224
* FastPFor128 (both `&[u32]` and `&[u64]`)
2325
* FastPFor256 (both `&[u32]` and `&[u64]`)
24-
* FastBinaryPacking16
25-
* FastBinaryPacking32
2626
* MaskedVByte
2727
* NewPFor
2828
* OptPFor
29-
* PFor2008
3029
* PFor
30+
* PFor2008
3131
* SimdBinaryPacking
3232
* SimdFastPFor128
3333
* SimdFastPFor256

src/codec.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bytemuck::{Pod, cast_slice};
22

3-
use crate::FastPForError;
3+
use crate::FastPForResult;
44

55
/// Internal default for max decompressed length. Used by trait defaults and C++ FFI.
66
#[inline]
@@ -27,9 +27,9 @@ pub(crate) fn default_max_decoded_len(compressed_words: usize) -> usize {
2727
/// impl BlockCodec for MyCodec {
2828
/// type Block = [u32; 256];
2929
/// fn encode_blocks(&self, blocks: &[[u32; 256]], out: &mut Vec<u32>)
30-
/// -> Result<(), FastPForError> { ... }
30+
/// -> FastPForResult<()> { ... }
3131
/// fn decode_blocks(&self, input: &[u32], expected_len: Option<u32>,
32-
/// out: &mut Vec<u32>) -> Result<usize, FastPForError> { ... }
32+
/// out: &mut Vec<u32>) -> FastPForResult<usize> { ... }
3333
/// }
3434
/// ```
3535
pub trait BlockCodec {
@@ -54,11 +54,7 @@ pub trait BlockCodec {
5454
///
5555
/// No remainder is possible — the caller must split the input first using
5656
/// [`slice_to_blocks`] and handle any remainder separately.
57-
fn encode_blocks(
58-
&mut self,
59-
blocks: &[Self::Block],
60-
out: &mut Vec<u32>,
61-
) -> Result<(), FastPForError>;
57+
fn encode_blocks(&mut self, blocks: &[Self::Block], out: &mut Vec<u32>) -> FastPForResult<()>;
6258

6359
/// Decompress blocks from `input`, using the length stored in the header.
6460
///
@@ -75,7 +71,7 @@ pub trait BlockCodec {
7571
input: &[u32],
7672
expected_len: Option<u32>,
7773
out: &mut Vec<u32>,
78-
) -> Result<usize, FastPForError>;
74+
) -> FastPForResult<usize>;
7975

8076
/// Maximum decompressed element count for a given compressed input length.
8177
/// Reject `expected_len` values exceeding this to avoid allocation from bad data.
@@ -100,9 +96,9 @@ pub trait BlockCodec {
10096
#[cfg(feature = "cpp")]
10197
pub trait BlockCodec64 {
10298
/// Compress 64-bit integers into a 32-bit word stream.
103-
fn encode64(&mut self, input: &[u64], out: &mut Vec<u32>) -> Result<(), FastPForError>;
99+
fn encode64(&mut self, input: &[u64], out: &mut Vec<u32>) -> FastPForResult<()>;
104100
/// Decompress 64-bit integers from a 32-bit word stream.
105-
fn decode64(&mut self, input: &[u32], out: &mut Vec<u64>) -> Result<(), FastPForError>;
101+
fn decode64(&mut self, input: &[u32], out: &mut Vec<u64>) -> FastPForResult<()>;
106102
}
107103

108104
/// Compresses and decompresses an arbitrary-length `&[u32]` slice.
@@ -113,7 +109,7 @@ pub trait BlockCodec64 {
113109
/// to produce an `AnyLenCodec`.
114110
pub trait AnyLenCodec {
115111
/// Compress an arbitrary-length slice of `u32` values.
116-
fn encode(&mut self, input: &[u32], out: &mut Vec<u32>) -> Result<(), FastPForError>;
112+
fn encode(&mut self, input: &[u32], out: &mut Vec<u32>) -> FastPForResult<()>;
117113

118114
/// Maximum decompressed element count for a given compressed input length.
119115
/// Reject `expected_len` values exceeding this to avoid allocation from bad data.
@@ -140,7 +136,7 @@ pub trait AnyLenCodec {
140136
input: &[u32],
141137
out: &mut Vec<u32>,
142138
expected_len: Option<u32>,
143-
) -> Result<(), FastPForError>;
139+
) -> FastPForResult<()>;
144140
}
145141

146142
/// Split a flat `&[u32]` into `(&[Blocks::Block], &[u32])` without copying.

src/cpp/codecs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use cxx::UniquePtr;
22

3-
use crate::FastPForError;
3+
use crate::FastPForResult;
44
use crate::codec::{AnyLenCodec, BlockCodec64};
55
use crate::cpp::ffi;
66
use crate::cpp::wrappers::{
@@ -37,7 +37,7 @@ macro_rules! implement_cpp_codecs {
3737
}
3838

3939
impl AnyLenCodec for $name {
40-
fn encode(&mut self, input: &[u32], out: &mut Vec<u32>) -> Result<(), FastPForError> {
40+
fn encode(&mut self, input: &[u32], out: &mut Vec<u32>) -> FastPForResult<()> {
4141
encode32_to_vec_ffi(&self.0, input, out)
4242
}
4343

@@ -46,7 +46,7 @@ macro_rules! implement_cpp_codecs {
4646
input: &[u32],
4747
out: &mut Vec<u32>,
4848
expected_len: Option<u32>,
49-
) -> Result<(), FastPForError> {
49+
) -> FastPForResult<()> {
5050
decode32_anylen_ffi(&self.0, input, out, expected_len)
5151
}
5252
}
@@ -161,10 +161,10 @@ macro_rules! implement_cpp_codecs_64 {
161161
($($name:ident => $ffi:ident ,)*) => {
162162
$(
163163
impl BlockCodec64 for $name {
164-
fn encode64(&mut self, input: &[u64], out: &mut Vec<u32>) -> Result<(), FastPForError> {
164+
fn encode64(&mut self, input: &[u64], out: &mut Vec<u32>) -> FastPForResult<()> {
165165
encode64_to_vec_ffi(&self.0, input, out)
166166
}
167-
fn decode64(&mut self, input: &[u32], out: &mut Vec<u64>) -> Result<(), FastPForError> {
167+
fn decode64(&mut self, input: &[u32], out: &mut Vec<u64>) -> FastPForResult<()> {
168168
decode64_to_vec_ffi(&self.0, input, out)
169169
}
170170
}
@@ -192,7 +192,7 @@ pub(crate) mod tests {
192192
}
193193

194194
/// C++ `fastpfor256_codec` returns `CompositeCodec<FastPFor<8>, VariableByte>` — already
195-
/// any-length. Use it directly; do not wrap in Rust `CppComposite`.
195+
/// any-length. Use it directly; do not wrap in Rust `CompositeCodec`.
196196
#[test]
197197
fn test_cpp_fastpfor256_composite_anylen() {
198198
let mut codec = CppFastPFor256::new();

src/cpp/wrappers.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use cxx::UniquePtr;
22

3-
use crate::FastPForError;
3+
use crate::FastPForResult;
44
use crate::codec::default_max_decoded_len;
55
use crate::cpp::ffi;
66
use crate::helpers::AsUsize;
@@ -14,7 +14,7 @@ pub fn encode32_to_vec_ffi(
1414
codec: &UniquePtr<ffi::IntegerCODEC>,
1515
input: &[u32],
1616
out: &mut Vec<u32>,
17-
) -> Result<(), FastPForError> {
17+
) -> FastPForResult<()> {
1818
let capacity = input.len() * 2 + 1024;
1919
let start = out.len();
2020
out.resize(start + capacity, 0);
@@ -28,7 +28,7 @@ fn decode32_to_vec_ffi(
2828
input: &[u32],
2929
out: &mut Vec<u32>,
3030
capacity: usize,
31-
) -> Result<(), FastPForError> {
31+
) -> FastPForResult<()> {
3232
if !input.is_empty() {
3333
let start = out.len();
3434
out.resize(start + capacity, 0);
@@ -43,7 +43,7 @@ pub fn decode32_anylen_ffi(
4343
input: &[u32],
4444
out: &mut Vec<u32>,
4545
expected_len: Option<u32>,
46-
) -> Result<(), FastPForError> {
46+
) -> FastPForResult<()> {
4747
let max = default_max_decoded_len(input.len());
4848
let capacity = if let Some(n) = expected_len {
4949
n.is_valid_expected(max)?
@@ -64,7 +64,7 @@ pub fn encode64_to_vec_ffi(
6464
codec: &UniquePtr<ffi::IntegerCODEC>,
6565
input: &[u64],
6666
out: &mut Vec<u32>,
67-
) -> Result<(), FastPForError> {
67+
) -> FastPForResult<()> {
6868
let capacity = input.len() * 3 + 1024;
6969
let start = out.len();
7070
out.resize(start + capacity, 0);
@@ -77,7 +77,7 @@ pub fn decode64_to_vec_ffi(
7777
codec: &UniquePtr<ffi::IntegerCODEC>,
7878
input: &[u32],
7979
out: &mut Vec<u64>,
80-
) -> Result<(), FastPForError> {
80+
) -> FastPForResult<()> {
8181
if !input.is_empty() {
8282
// C++ decodeArray needs output buffer. Variable-byte can pack multiple values per word.
8383
let capacity = input.len().saturating_mul(4);

src/helpers.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::FastPForError;
1+
use crate::{FastPForError, FastPForResult};
22

33
/// Finds the greatest multiple of `factor` that is less than or equal to `value`.
44
#[cfg_attr(feature = "cpp", allow(dead_code))]
@@ -18,7 +18,7 @@ pub trait AsUsize: Eq + Copy {
1818

1919
#[inline]
2020
#[cfg(feature = "cpp")]
21-
fn is_decoded_mismatch(self, expected: impl AsUsize) -> Result<(), FastPForError> {
21+
fn is_decoded_mismatch(self, expected: impl AsUsize) -> FastPForResult<()> {
2222
let actual = self.as_usize();
2323
let expected = expected.as_usize();
2424
if self.as_usize() == expected {
@@ -31,7 +31,7 @@ pub trait AsUsize: Eq + Copy {
3131
/// Returns an error if `expected` exceeds `max`.
3232
#[inline]
3333
#[cfg(feature = "cpp")]
34-
fn is_valid_expected(self, max: impl AsUsize) -> Result<usize, FastPForError> {
34+
fn is_valid_expected(self, max: impl AsUsize) -> FastPForResult<usize> {
3535
let expected = self.as_usize();
3636
let max = max.as_usize();
3737
if expected > max {
@@ -69,12 +69,12 @@ impl AsUsize for u32 {
6969

7070
#[cfg_attr(feature = "cpp", allow(dead_code))]
7171
pub trait GetWithErr<T> {
72-
fn get_val(&self, pos: impl AsUsize) -> Result<T, FastPForError>;
72+
fn get_val(&self, pos: impl AsUsize) -> FastPForResult<T>;
7373
}
7474

7575
impl<T: Copy> GetWithErr<T> for &[T] {
7676
#[inline]
77-
fn get_val(&self, pos: impl AsUsize) -> Result<T, FastPForError> {
77+
fn get_val(&self, pos: impl AsUsize) -> FastPForResult<T> {
7878
self.get(pos.as_usize())
7979
.copied()
8080
.ok_or(FastPForError::NotEnoughData)
@@ -83,7 +83,7 @@ impl<T: Copy> GetWithErr<T> for &[T] {
8383

8484
impl<T: Copy> GetWithErr<T> for Vec<T> {
8585
#[inline]
86-
fn get_val(&self, pos: impl AsUsize) -> Result<T, FastPForError> {
86+
fn get_val(&self, pos: impl AsUsize) -> FastPForResult<T> {
8787
self.as_slice().get_val(pos)
8888
}
8989
}

src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22
#![cfg_attr(docsrs, feature(doc_cfg))]
33
#![doc = include_str!("../README.md")]
44

5-
#[cfg(not(any(feature = "cpp", feature = "rust",)))]
5+
#[cfg(not(any(feature = "cpp", feature = "rust")))]
66
compile_error!("At least one of the features 'cpp' or 'rust' must be enabled");
77

88
// Error types are always available regardless of which codec features are enabled.
99
mod error;
1010
pub use error::{FastPForError, FastPForResult};
1111

12-
// FIXME: need decide on the external API. Some ideas:
13-
// - offer two sets of similar APIs - rust and cpp ffi
14-
// - it will be possible to enable/disable each with a feature flag
15-
// - introduce a new feature-agnostic API that will forward to either
16-
// - if both are enabled, forward to the more stable (ffi probably)
1712
#[cfg(feature = "cpp")]
1813
/// Rust wrapper for the [`FastPFOR` C++ library](https://github.com/fast-pack/FastPFor)
1914
pub mod cpp;

src/rust/integer_compression/fastpfor.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::array;
22
use std::io::Cursor;
33
use std::num::NonZeroU32;
44

5+
use bytemuck::cast_slice;
56
use bytes::{Buf as _, BufMut as _, BytesMut};
67

78
use crate::helpers::{GetWithErr, bits, greatest_multiple};
@@ -176,13 +177,13 @@ impl FastPFOR {
176177
/// - Writes header, packed data, metadata bytes, and exception values.
177178
///
178179
/// # Arguments
179-
/// * `thissize` - Must be multiple of `block_size`
180-
/// * `input_offset` - Advanced by `thissize`
180+
/// * `this_size` - Must be multiple of `block_size`
181+
/// * `input_offset` - Advanced by `this_size`
181182
/// * `output_offset` - Advanced by compressed size
182183
fn encode_page(
183184
&mut self,
184185
input: &[u32],
185-
thissize: u32,
186+
this_size: u32,
186187
input_offset: &mut Cursor<u32>,
187188
output: &mut [u32],
188189
output_offset: &mut Cursor<u32>,
@@ -196,7 +197,7 @@ impl FastPFOR {
196197
self.bytes_container.clear();
197198

198199
let mut tmp_input_offset = input_offset.position() as u32;
199-
let final_input_offset = tmp_input_offset + thissize - self.block_size;
200+
let final_input_offset = tmp_input_offset + this_size - self.block_size;
200201
while tmp_input_offset <= final_input_offset {
201202
self.best_bit_from_data(input, tmp_input_offset);
202203
self.bytes_container.put_u8(self.optimal_bits);
@@ -331,17 +332,17 @@ impl FastPFOR {
331332
/// unpacks regular values per block, patches in exceptions by position.
332333
///
333334
/// # Arguments
334-
/// * `thissize` - Expected decompressed integer count
335+
/// * `this_size` - Expected decompressed integer count
335336
/// * `input_offset` - Advanced by bytes read
336-
/// * `output_offset` - Advanced by `thissize`
337+
/// * `output_offset` - Advanced by `this_size`
337338
#[expect(clippy::too_many_lines)]
338339
fn decode_page(
339340
&mut self,
340341
input: &[u32],
341342
input_offset: &mut Cursor<u32>,
342343
output: &mut [u32],
343344
output_offset: &mut Cursor<u32>,
344-
thissize: u32,
345+
this_size: u32,
345346
) -> FastPForResult<()> {
346347
let n = u32::try_from(input.len())
347348
.map_err(|_| FastPForError::InvalidInputLength(input.len()))?;
@@ -362,7 +363,7 @@ impl FastPFOR {
362363
// The C++ encoder uses a raw `memcpy` of bytes into the u32 output (no endian
363364
// conversion), and the decoder does a raw reinterpret_cast back -- both native byte
364365
// order. `cast_slice` is the exact Rust equivalent: a safe, zero-copy native view.
365-
let input_bytes: &[u8] = bytemuck::cast_slice(input);
366+
let input_bytes: &[u8] = cast_slice(input);
366367
let mut byte_pos = (inexcept as usize)
367368
.checked_mul(4)
368369
.filter(|&bp| bp <= input_bytes.len())
@@ -448,7 +449,7 @@ impl FastPFOR {
448449
let mut tmp_output_offset = output_offset.position() as u32;
449450
let mut tmp_input_offset = input_offset.position() as u32;
450451

451-
let run_end = thissize / self.block_size;
452+
let run_end = this_size / self.block_size;
452453
for _ in 0..run_end {
453454
let bits = input_bytes.get_val(byte_pos)?;
454455
if bits > 32 {

tests/decode_error_paths.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use std::io::Cursor;
1313

14+
use bytemuck::cast_slice_mut;
1415
use fastpfor::rust::{BLOCK_SIZE_128, DEFAULT_PAGE_SIZE, FastPFOR, Integer, Skippable};
1516

1617
// ── helpers ──────────────────────────────────────────────────────────────────
@@ -229,7 +230,7 @@ fn decode_exception_partial_group_not_enough_data() {
229230
fn decode_block_b_too_large() {
230231
let (mut compressed, _) = compressed_with_exceptions();
231232
let start = meta_byte_start(&compressed);
232-
let bytes: &mut [u8] = bytemuck::cast_slice_mut(&mut compressed);
233+
let bytes: &mut [u8] = cast_slice_mut(&mut compressed);
233234
bytes[start] = 33; // overwrite best_b of block 0
234235
assert!(try_decode(&compressed).is_err());
235236
}
@@ -289,7 +290,7 @@ fn find_exception_block(bytes: &[u8], meta_start: usize) -> Option<(usize, usize
289290
fn decode_exception_maxbits_too_large() {
290291
let (mut compressed, _) = compressed_with_exceptions();
291292
let start = meta_byte_start(&compressed);
292-
let bytes: &mut [u8] = bytemuck::cast_slice_mut(&mut compressed);
293+
let bytes: &mut [u8] = cast_slice_mut(&mut compressed);
293294
if let Some((_, _, mb_off)) = find_exception_block(bytes, start) {
294295
bytes[mb_off] = 33;
295296
}
@@ -301,7 +302,7 @@ fn decode_exception_maxbits_too_large() {
301302
fn decode_exception_index_underflow() {
302303
let (mut compressed, _) = compressed_with_exceptions();
303304
let start = meta_byte_start(&compressed);
304-
let bytes: &mut [u8] = bytemuck::cast_slice_mut(&mut compressed);
305+
let bytes: &mut [u8] = cast_slice_mut(&mut compressed);
305306
if let Some((bb_off, _, mb_off)) = find_exception_block(bytes, start) {
306307
bytes[mb_off] = bytes[bb_off].saturating_sub(1); // maxbits < best_b
307308
}
@@ -313,7 +314,7 @@ fn decode_exception_index_underflow() {
313314
fn decode_exception_index_zero() {
314315
let (mut compressed, _) = compressed_with_exceptions();
315316
let start = meta_byte_start(&compressed);
316-
let bytes: &mut [u8] = bytemuck::cast_slice_mut(&mut compressed);
317+
let bytes: &mut [u8] = cast_slice_mut(&mut compressed);
317318
if let Some((bb_off, _, mb_off)) = find_exception_block(bytes, start) {
318319
bytes[mb_off] = bytes[bb_off]; // maxbits == best_b → index 0
319320
}
@@ -368,7 +369,7 @@ fn decode_index1_pos_out_of_block() {
368369
buf.truncate(out_off.position() as usize);
369370

370371
let start = meta_byte_start(&buf);
371-
let bytes: &mut [u8] = bytemuck::cast_slice_mut(&mut buf);
372+
let bytes: &mut [u8] = cast_slice_mut(&mut buf);
372373
if let Some((bb_off, _, mb_off)) = find_exception_block(bytes, start) {
373374
if bytes[mb_off].wrapping_sub(bytes[bb_off]) == 1 && mb_off + 1 < bytes.len() {
374375
bytes[mb_off + 1] = 200; // position 200 >= block_size 128
@@ -432,7 +433,7 @@ fn decode_exception_pos_out_of_block() {
432433
buf.truncate(out_off.position() as usize);
433434

434435
let start = meta_byte_start(&buf);
435-
let bytes: &mut [u8] = bytemuck::cast_slice_mut(&mut buf);
436+
let bytes: &mut [u8] = cast_slice_mut(&mut buf);
436437
if let Some((bb_off, _, mb_off)) = find_exception_block(bytes, start) {
437438
if bytes[mb_off].wrapping_sub(bytes[bb_off]) > 1 && mb_off + 1 < bytes.len() {
438439
bytes[mb_off + 1] = 200; // position 200 >= block_size 128

0 commit comments

Comments
 (0)