Skip to content

Commit

Permalink
Merge pull request #80 from instaclustr/polynomial-compressor
Browse files Browse the repository at this point in the history
Polynomial compressor
  • Loading branch information
cjrolo authored Nov 24, 2023
2 parents 01e02dd + b1f8f18 commit 0326550
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 22 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions brro-compressor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ regex = "1.9.1"
hound = "3.5"
median = "0.3.2"
wavbrro = { path = "../wavbrro" }
splines = "4.3.0"
inverse_distance_weight = "0.1.1"

[dev-dependencies]
criterion = "0.5.1"
Expand Down
6 changes: 3 additions & 3 deletions brro-compressor/src/compressor/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bincode::{Decode, Encode};
use log::{debug, info};
use std::collections::HashMap;

const CONSTANT_COMPRESSOR_ID: u8 = 0;
const CONSTANT_COMPRESSOR_ID: u8 = 30;

/// This is a temporary implementation, other implementations (FFT, Polynomial) might provide the same result
/// as going through the data anyway.
Expand Down Expand Up @@ -127,7 +127,7 @@ mod tests {
#[test]
fn test_constant() {
let vector1 = vec![1.0, 1.0, 1.0, 1.0, 1.0];
assert_eq!(constant(&vector1), [0, 2, 0]);
assert_eq!(constant(&vector1), [30, 2, 0]);
}

#[test]
Expand All @@ -138,7 +138,7 @@ mod tests {
let bin_data = c.to_bytes();
let c2 = Constant::decompress(&bin_data);

assert_eq!(bin_data, [0, 2, 0]);
assert_eq!(bin_data, [30, 2, 0]);
assert_eq!(c.clone(), c2);
}

Expand Down
1 change: 0 additions & 1 deletion brro-compressor/src/compressor/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ impl FFT {
match iterations {
1..=17 => jump += max_freq/2,
18..=22 => jump += max_freq/10,
23 => break,
_ => break
}
}
Expand Down
12 changes: 10 additions & 2 deletions brro-compressor/src/compressor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ use bincode::{Decode, Encode};
use self::constant::{constant, constant_to_data};
use self::fft::{fft, fft_to_data, fft_allowed_error};
use self::noop::{noop, noop_to_data};
use self::polynomial::{polynomial, to_data, PolynomialType};

pub mod noop;
pub mod constant;
pub mod fft;
pub mod polynomial;

#[derive(Encode, Decode, Default, Debug, Clone)]
pub enum Compressor {
#[default]
Noop,
FFT,
Wavelet,
Idw,
Constant,
Polynomial,
TopBottom,
Auto
}

impl Compressor {
Expand All @@ -26,6 +28,8 @@ impl Compressor {
Compressor::Noop => noop(data),
Compressor::FFT => fft(data),
Compressor::Constant => constant(data),
Compressor::Polynomial => polynomial(data, PolynomialType::Polynomial),
Compressor::Idw => polynomial(data, PolynomialType::Idw),
_ => todo!(),
}
}
Expand All @@ -35,6 +39,8 @@ impl Compressor {
Compressor::Noop => noop(data),
Compressor::FFT => fft_allowed_error(data, max_error),
Compressor::Constant => constant(data),
Compressor::Polynomial => polynomial(data, PolynomialType::Polynomial),
Compressor::Idw => polynomial(data, PolynomialType::Idw),
_ => todo!(),
}
}
Expand All @@ -44,6 +50,8 @@ impl Compressor {
Compressor::Noop => noop_to_data(samples, data),
Compressor::FFT => fft_to_data(samples, data),
Compressor::Constant => constant_to_data(samples, data),
Compressor::Polynomial => to_data(samples, data),
Compressor::Idw => to_data(samples, data),
_ => todo!()
}
}
Expand Down
Loading

0 comments on commit 0326550

Please sign in to comment.