Skip to content

Commit

Permalink
each generation of table building should only consider up to self.n_s…
Browse files Browse the repository at this point in the history
…ymbols
  • Loading branch information
a10y committed Aug 15, 2024
1 parent 121e8cf commit 27c4a0f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ impl SymbolTable {
fn optimize(&self, counters: Counter) -> Self {
let mut res = SymbolTable::default();
let mut pqueue = BinaryHeap::new();
for code1 in 0..511 {
for code1 in 0u16..(256u16 + self.n_symbols as u16) {
let symbol1 = self.symbols[code1 as usize];
let gain = counters.count1(code1) * symbol1.len();
pqueue.push(Candidate {
symbol: symbol1,
gain,
});

for code2 in 0..511 {
for code2 in 0u16..(256u16 + self.n_symbols as u16) {
let symbol2 = &self.symbols[code2 as usize];
// If either symbol is zero-length, or if merging would yield a symbol of
// length greater than 8, skip.
Expand Down
2 changes: 1 addition & 1 deletion src/find_longest/naive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl FindLongestSymbol for SymbolTable {
// Start with the code corresponding to the escape of the first character in the text
let mut best_code = text[0] as u16;
let mut best_overlap = 1;
for code in 256..511 {
for code in 256..(256 + self.n_symbols as u16) {
let symbol = &self.symbols[code as usize];
if symbol.is_prefix(text) && symbol.len() > best_overlap {
best_code = code;
Expand Down

0 comments on commit 27c4a0f

Please sign in to comment.