Skip to content

Commit 915d1fe

Browse files
Weixing-ZhangWeixing Zhang
andauthored
fix: data-to-be-packed resize remove existing values (#30)
Context: - When the number of exception values `bestbbestcexceptmaxb[1]` + `data_pointers[index as usize]` exceeded the pre-allocated size of `data_to_be_packed`, the resize logic replaced the entire buffer, discarding existing values. Implemented: - Fixed the resizing logic to preserve existing exception values by extending the vector with zeros instead of overwriting. - Added `test_exception_value_vector_resizes` unit test. Co-authored-by: Weixing Zhang <[email protected]>
1 parent ae30939 commit 915d1fe

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/rust/integer_compression/fastpfor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ impl FastPFOR {
168168
+ self.bestbbestcexceptmaxb[1] as usize)
169169
as u32;
170170
new_size = helpers::greatest_multiple(new_size + 31, 32);
171-
self.data_to_be_packed[index as usize].resize(new_size as usize, 1);
172-
self.data_to_be_packed[index as usize]
173-
.clone_from_slice(&vec![1; new_size as usize]);
171+
self.data_to_be_packed[index as usize].resize(new_size as usize, 0);
174172
}
175173
for k in 0..self.block_size {
176174
if (input[(k + tmp_input_offset) as usize] >> self.bestbbestcexceptmaxb[0]) != 0

tests/basic_tests.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,45 @@ fn test_fastpfor_headless_compress_unfit_pagesize() {
415415

416416
assert_eq!(input, decoded, "Input and decompressed data do not match");
417417
}
418+
419+
#[test]
420+
fn test_exception_value_vector_resizes() {
421+
let page_size = 512;
422+
let test_input_size = page_size * 2;
423+
424+
// every even index value is large which will trigger exception buffer to be resize
425+
let input: Vec<u32> = (0..test_input_size)
426+
.map(|i| if i % 2 == 0 { 1 << 30 } else { 3 })
427+
.collect();
428+
429+
let mut output: Vec<u32> = vec![0; input.len() * 4];
430+
let mut decoded: Vec<u32> = vec![0; input.len()];
431+
let mut input_offset = Cursor::new(0u32);
432+
let mut output_offset = Cursor::new(0u32);
433+
434+
let mut codec = FastPFOR::new(page_size, BLOCK_SIZE_128);
435+
codec
436+
.compress(
437+
&input,
438+
input.len() as u32,
439+
&mut input_offset,
440+
&mut output,
441+
&mut output_offset,
442+
)
443+
.expect("compression failed");
444+
445+
let compressed_len = output_offset.position() as usize;
446+
input_offset.set_position(0);
447+
448+
codec
449+
.uncompress(
450+
&output,
451+
compressed_len as u32,
452+
&mut input_offset,
453+
&mut decoded,
454+
&mut Cursor::new(0u32),
455+
)
456+
.expect("decompression failed");
457+
458+
assert_eq!(input, decoded, "Input and decompressed data do not match");
459+
}

0 commit comments

Comments
 (0)