diff --git a/src/builder.rs b/src/builder.rs index 7e865a8..43a6fd4 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -103,7 +103,7 @@ 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 { @@ -111,7 +111,7 @@ impl SymbolTable { 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. diff --git a/src/find_longest/naive.rs b/src/find_longest/naive.rs index c75ecad..c9add2d 100644 --- a/src/find_longest/naive.rs +++ b/src/find_longest/naive.rs @@ -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;