Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
a10y committed Aug 20, 2024
1 parent df630f7 commit 81662e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
15 changes: 1 addition & 14 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ impl Compressor {
gain *= 8;
}
if gain > 0 {
// println!("pushing single: symbol = {symbol1:?} gain = {gain}");
pqueue.push(Candidate {
symbol: symbol1,
gain,
Expand All @@ -186,13 +185,6 @@ impl Compressor {
let new_symbol = symbol1.concat(symbol2);
let gain = counters.count2(code1, code2) * new_symbol.len();
if gain > 0 {
// println!("pushing double: symbol = {new_symbol:?} gain = {gain}");
// println!(
// "\tfirst-half gain = {} second-half gain = {}",
// counters.count1(code1),
// counters.count1(code2)
// );

pqueue.push(Candidate {
symbol: new_symbol,
gain,
Expand Down Expand Up @@ -272,13 +264,8 @@ impl Ord for Candidate {

#[cfg(test)]
mod test {
use crate::{Compressor, ESCAPE_CODE};

#[test]
fn test_sadness() {
let compressor = Compressor::train_n("hello world", 1);
let _ = compressor.compress(&[1]);
}
use crate::{Compressor, ESCAPE_CODE};

#[test]
fn test_builder() {
Expand Down
23 changes: 9 additions & 14 deletions tests/correctness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,17 @@ fn test_zeros() {

#[test]
fn test_large() {
let mut corpus = String::new();
// TODO(aduffy): make this larger once table build performance is better.
while corpus.len() < 10 * 1_024 {
corpus.push_str(DECLARATION);
}
let corpus: Vec<u8> = DECLARATION.bytes().cycle().take(10_240).collect();

let trained = Compressor::train(&corpus);
let mut massive = String::new();
while massive.len() < 16 * 1_024 * 1_024 {
massive.push_str(DECLARATION);
}
let compressed = trained.compress(massive.as_bytes());
assert_eq!(
trained.decompressor().decompress(&compressed),
massive.as_bytes()
);
let massive: Vec<u8> = DECLARATION
.bytes()
.cycle()
.take(16 * 1_024 * 1_024)
.collect();

let compressed = trained.compress(&massive);
assert_eq!(trained.decompressor().decompress(&compressed), massive);
}

#[test]
Expand Down

0 comments on commit 81662e1

Please sign in to comment.