Skip to content

Commit 502073c

Browse files
authored
feat: differential delta fast inverse delta (#18)
1 parent d54ebb2 commit 502073c

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use std::ops::{Add, AddAssign};
2+
3+
pub struct Delta;
4+
5+
impl Delta {
6+
pub fn new() -> Delta {
7+
Delta
8+
}
9+
10+
// C++ port as it supports any type of numeric data
11+
// source: https://github.com/fast-pack/FastPFor/blob/49d44d94773518ef26486f7a58f8da08e8a498bb/headers/deltautil.h#L274
12+
pub fn fast_inverse_delta<T>(data: &mut [T])
13+
where
14+
T: Copy + Add<Output = T> + AddAssign,
15+
{
16+
if data.is_empty() {
17+
return;
18+
}
19+
20+
let sz0 = (data.len() / 4) * 4;
21+
let mut i = 1;
22+
23+
if sz0 >= 4 {
24+
let mut a = data[0];
25+
while i < sz0 - 4 {
26+
a = {
27+
data[i] += a;
28+
data[i]
29+
};
30+
a = {
31+
data[i + 1] += a;
32+
data[i + 1]
33+
};
34+
a = {
35+
data[i + 2] += a;
36+
data[i + 2]
37+
};
38+
a = {
39+
data[i + 3] += a;
40+
data[i + 3]
41+
};
42+
i += 4;
43+
}
44+
}
45+
46+
while i < data.len() {
47+
data[i] += data[i - 1];
48+
i += 1;
49+
}
50+
}
51+
}
52+
53+
impl Default for Delta {
54+
fn default() -> Self {
55+
Delta::new()
56+
}
57+
}

src/integer_compression/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod bitpacking;
22
pub mod codec;
33
pub mod composition;
4+
pub mod differential;
45
pub mod fastpfor;
56
pub mod helpers;
67
pub mod integer_codec;

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use error::{FastPForError, FastPForResult};
77
pub use integer_compression::bitpacking::{fast_pack, fast_unpack};
88
pub use integer_compression::codec::Codec;
99
pub use integer_compression::composition::Composition;
10+
pub use integer_compression::differential::Delta;
1011
pub use integer_compression::fastpfor::{
1112
FastPFOR, BLOCK_SIZE_128, BLOCK_SIZE_256, DEFAULT_PAGE_SIZE,
1213
};

0 commit comments

Comments
 (0)