[Haskell-cafe] Abstraction leak

Bulat Ziganshin bulat.ziganshin at gmail.com
Sun Jul 1 10:18:59 EDT 2007


Hello Andrew,

Sunday, July 1, 2007, 1:18:16 PM, you wrote:

>> encoding is simple - make this traversal one time and store bit
>> sequence for each symbol. for decoding, you can find length of longest
>> symbol MaxBits and build table of 2^MaxBits elements which allows to
>> find next symbol by direct lookup with next input MaxBits. faster
>> algorithms use two-level lookup, first lookup with 9-10 bits is best
>> when your encoded symbols are bytes
>>   

> I see. So build a table of codes and bitmasks and test against that...

decodeSymbol = do
  n <- returnNextNBits MaxBits  -- this operation doesn't forward input pointer!
  symbol <- table1 ! n
  bits   <- table2 ! symbol
  skipNBits bits
  return symbol


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list