Skip to content

Commit 1087d58

Browse files
authored
feat: just-copy (#16)
1 parent 9813ae0 commit 1087d58

16 files changed

Lines changed: 491 additions & 194 deletions

src/compressor.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ pub enum FastPForError {
1010
CompressError(String),
1111
#[error("Invalid block size: {0}")]
1212
InvalidBlockSizeError(String),
13+
#[error("Unsupported operation: {0}")]
14+
UnsupportedOperationError(String),
15+
#[error("Out of bounds access")]
16+
OutOfBoundsAccess,
1317
}

src/integer_codec.rs

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/integer_compression/codec.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::{FastPFOR, JustCopy, VariableByte};
2+
3+
pub enum Codec {
4+
FastPFor(FastPFOR),
5+
VariableByte(VariableByte),
6+
JustCopy(JustCopy),
7+
}
8+
9+
impl From<FastPFOR> for Codec {
10+
fn from(fastpfor: FastPFOR) -> Self {
11+
Codec::FastPFor(fastpfor)
12+
}
13+
}
14+
15+
impl From<VariableByte> for Codec {
16+
fn from(vb: VariableByte) -> Self {
17+
Codec::VariableByte(vb)
18+
}
19+
}
20+
21+
impl From<JustCopy> for Codec {
22+
fn from(jc: JustCopy) -> Self {
23+
Codec::JustCopy(jc)
24+
}
25+
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
use std::io::Cursor;
22

33
use crate::cursor::IncrementCursor;
4-
use crate::integer_codec::IntegerCodec;
5-
use crate::{Compressor, FastPForResult};
4+
use crate::{Codec, FastPForResult, Integer};
65

76
pub struct Composition {
8-
c1: IntegerCodec,
9-
c2: IntegerCodec,
7+
c1: Codec,
8+
c2: Codec,
109
}
1110

1211
impl Composition {
1312
pub fn new<C1, C2>(c1: C1, c2: C2) -> Self
1413
where
15-
C1: Into<IntegerCodec>,
16-
C2: Into<IntegerCodec>,
14+
C1: Into<Codec>,
15+
C2: Into<Codec>,
1716
{
1817
Composition {
1918
c1: c1.into(),
@@ -70,8 +69,8 @@ impl Composition {
7069
#[cfg(test)]
7170
mod tests {
7271
use super::*;
73-
use crate::fastpfor::FastPFOR;
74-
use crate::variable_byte::VariableByte;
72+
use crate::integer_compression::fastpfor::FastPFOR;
73+
use crate::integer_compression::variable_byte::VariableByte;
7574

7675
#[test]
7776
fn test_composition() {
Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::io::Cursor;
22

3-
use crate::compressor::Compressor;
43
use crate::cursor::IncrementCursor;
5-
use crate::error::FastPForResult;
6-
use crate::{bitpacking, bytebuffer, helpers};
4+
use crate::integer_compression::{bitpacking, helpers};
5+
use crate::{bytebuffer, FastPForError, FastPForResult, Integer, Skippable};
76

87
pub const BLOCK_SIZE_256: i32 = 256;
98
pub const BLOCK_SIZE_128: i32 = 128;
@@ -21,7 +20,42 @@ pub struct FastPFOR {
2120
pub block_size: i32,
2221
}
2322

24-
impl Compressor<i32> for FastPFOR {
23+
impl Skippable for FastPFOR {
24+
fn headless_compress(
25+
&mut self,
26+
input: &[i32],
27+
input_length: i32,
28+
input_offset: &mut Cursor<i32>,
29+
output: &mut [i32],
30+
output_offset: &mut Cursor<i32>,
31+
) -> FastPForResult<()> {
32+
let inlength = helpers::greatest_multiple(input_length, self.block_size as i32);
33+
let pos = input_offset.position() as i32;
34+
let final_inpos = pos + inlength;
35+
while input_offset.position() as i32 != final_inpos {
36+
let this_size = std::cmp::min(self.page_size, final_inpos - pos);
37+
self.encode_page(input, input_offset, this_size, output, output_offset);
38+
}
39+
FastPForResult::Ok(())
40+
}
41+
42+
#[expect(unused_variables)]
43+
fn headless_uncompress(
44+
&mut self,
45+
input: &[i32],
46+
inlength: i32,
47+
input_offset: &mut Cursor<i32>,
48+
output: &mut [i32],
49+
output_offset: &mut Cursor<i32>,
50+
num: i32,
51+
) -> FastPForResult<()> {
52+
FastPForResult::Err(FastPForError::UnsupportedOperationError(
53+
"Unimplemented".to_string(),
54+
))
55+
}
56+
}
57+
58+
impl Integer<i32> for FastPFOR {
2559
fn compress(
2660
&mut self,
2761
input: &[i32],
@@ -37,14 +71,7 @@ impl Compressor<i32> for FastPFOR {
3771
}
3872
output[output_offset.position() as usize] = inlength;
3973
output_offset.increment();
40-
let _inlength = helpers::greatest_multiple(inlength, self.block_size as i32);
41-
let pos = input_offset.position() as i32;
42-
let final_inpos = pos + _inlength;
43-
while input_offset.position() as i32 != final_inpos {
44-
let this_size = std::cmp::min(self.page_size, final_inpos - pos);
45-
self.encode_page(input, input_offset, this_size, output, output_offset);
46-
}
47-
FastPForResult::Ok(())
74+
self.headless_compress(input, inlength, input_offset, output, output_offset)
4875
}
4976

5077
fn uncompress(
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use std::io::Cursor;
2+
3+
use crate::{Codec, FastPForResult};
4+
5+
pub trait Integer<T> {
6+
fn compress(
7+
&mut self,
8+
input: &[i32],
9+
input_length: i32,
10+
input_offset: &mut Cursor<i32>,
11+
output: &mut [T],
12+
output_offset: &mut Cursor<i32>,
13+
) -> FastPForResult<()>;
14+
15+
fn uncompress(
16+
&mut self,
17+
input: &[T],
18+
input_length: i32,
19+
input_offset: &mut Cursor<i32>,
20+
output: &mut [i32],
21+
output_offset: &mut Cursor<i32>,
22+
) -> FastPForResult<()>;
23+
}
24+
25+
impl Integer<i32> for Codec {
26+
fn compress(
27+
&mut self,
28+
input: &[i32],
29+
input_length: i32,
30+
input_offset: &mut Cursor<i32>,
31+
output: &mut [i32],
32+
output_offset: &mut Cursor<i32>,
33+
) -> FastPForResult<()> {
34+
match self {
35+
Codec::FastPFor(fastpfor) => {
36+
fastpfor.compress(input, input_length, input_offset, output, output_offset)
37+
}
38+
Codec::VariableByte(vb) => {
39+
vb.compress(input, input_length, input_offset, output, output_offset)
40+
}
41+
Codec::JustCopy(jc) => {
42+
jc.compress(input, input_length, input_offset, output, output_offset)
43+
}
44+
}
45+
}
46+
47+
fn uncompress(
48+
&mut self,
49+
input: &[i32],
50+
input_length: i32,
51+
input_offset: &mut Cursor<i32>,
52+
output: &mut [i32],
53+
output_offset: &mut Cursor<i32>,
54+
) -> FastPForResult<()> {
55+
match self {
56+
Codec::FastPFor(fastpfor) => {
57+
fastpfor.uncompress(input, input_length, input_offset, output, output_offset)
58+
}
59+
Codec::VariableByte(vb) => {
60+
vb.uncompress(input, input_length, input_offset, output, output_offset)
61+
}
62+
Codec::JustCopy(jc) => {
63+
jc.uncompress(input, input_length, input_offset, output, output_offset)
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)