forked from fast-pack/FastPFOR-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastpfor_rust.rs
More file actions
66 lines (57 loc) · 1.96 KB
/
Copy pathfastpfor_rust.rs
File metadata and controls
66 lines (57 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#![no_main]
use std::io::Cursor;
use fastpfor::rust::{BLOCK_SIZE_256, DEFAULT_PAGE_SIZE, FastPFOR, Integer};
use libfuzzer_sys::fuzz_target;
fuzz_target!(|input_data: Vec<u32>| {
let mut codec = FastPFOR::new(DEFAULT_PAGE_SIZE, BLOCK_SIZE_256);
// Limit input size to avoid timeouts
let input_data: Vec<u32> = input_data.into_iter().take(10_000).collect();
// Allocate output buffer with generous size
let mut compressed = vec![0u32; input_data.len() * 2 + 1024];
// Compress the data
let mut output_offset = Cursor::new(0);
codec
.compress(
&input_data,
input_data.len() as u32,
&mut Cursor::new(0),
&mut compressed,
&mut output_offset,
)
.unwrap();
let compressed_size = output_offset.position() as u32;
if !input_data.is_empty() {
assert!(compressed_size != 0, "compression should not be empty");
}
// Now decompress
let mut decompressed = vec![0u32; input_data.len()];
let mut output_offset = Cursor::new(0);
codec
.uncompress(
&compressed,
compressed_size,
&mut Cursor::new(0),
&mut decompressed,
&mut output_offset,
)
.unwrap();
let decompressed_length = output_offset.position() as usize;
// Verify roundtrip
if decompressed_length + input_data.len() < 200 {
assert_eq!(
input_data,
decompressed[..decompressed_length],
"Decompressed length mismatch: expected {}, got {decompressed_length}",
input_data.len()
);
} else {
for (i, (&original, &decoded)) in input_data.iter().zip(decompressed.iter()).enumerate() {
assert_eq!(
original, decoded,
"Mismatch at position {}: expected {}, got {}",
i, original, decoded
);
}
}
assert_eq!(decompressed_length, input_data.len());
});