From 3bfff500ab0625ce55aef3345984d766b0e4d5b6 Mon Sep 17 00:00:00 2001 From: Andrew Duffy Date: Wed, 14 Aug 2024 21:48:27 -0400 Subject: [PATCH] fix table insert --- benches/compress.rs | 23 ----------------------- src/builder.rs | 1 - src/lib.rs | 1 - src/lossy_pht.rs | 2 +- 4 files changed, 1 insertion(+), 26 deletions(-) diff --git a/benches/compress.rs b/benches/compress.rs index 9581c9c..603eca1 100644 --- a/benches/compress.rs +++ b/benches/compress.rs @@ -51,29 +51,6 @@ fn bench_fsst(c: &mut Criterion) { fn bench_lz4(c: &mut Criterion) { let mut group = c.benchmark_group("lz4"); - // { - // let compressed = Vec::with_capacity(10_000); - // let mut encoder = lz4::EncoderBuilder::new() - // .block_size(BlockSize::Max64KB) - // .build(compressed) - // .unwrap(); - // - // encoder.write_all(TEST.as_bytes()).unwrap(); - // let (compressed, result) = encoder.finish(); - // result.unwrap(); - // - // let ratio = (TEST.as_bytes().len() as f64) / (compressed.len() as f64); - // println!("LZ4 compress_ratio = {ratio}"); - // - // // ensure decodes cleanly - // let cursor = Cursor::new(compressed); - // let mut decoder = lz4::Decoder::new(cursor).unwrap(); - // let mut output = String::new(); - // - // decoder.read_to_string(&mut output).unwrap(); - // assert_eq!(output.as_str(), TEST); - // } - group.bench_function("compress-single", |b| { let mut compressed = Vec::with_capacity(100_000_000); let mut encoder = lz4::EncoderBuilder::new() diff --git a/src/builder.rs b/src/builder.rs index 3c28b8b..558a3b4 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -88,7 +88,6 @@ impl SymbolTable { let mut pos = self.symbols[prev_code as usize].len(); while pos < len { - println!("loop pos = {pos} len = {len}"); let code = self.find_longest_symbol(&sample[pos..len]); counter.record_count1(code); counter.record_count2(prev_code, code); diff --git a/src/lib.rs b/src/lib.rs index ba21fea..5350fb3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -278,7 +278,6 @@ impl SymbolTable { } else if symbol_len >= 3 { // Attempt to insert larger symbols into the 3-byte cache if !self.lossy_pht.insert(symbol, self.n_symbols) { - println!("table insert rejected"); return false; } } diff --git a/src/lossy_pht.rs b/src/lossy_pht.rs index f7ca6c0..ada8980 100644 --- a/src/lossy_pht.rs +++ b/src/lossy_pht.rs @@ -85,7 +85,7 @@ impl LossyPHT { let slot = self.hash(prefix_3bytes) as usize & (HASH_TABLE_SIZE - 1); let entry = &mut self.slots[slot]; - if entry.is_unused() { + if !entry.is_unused() { false } else { entry.symbol = symbol;