1. A method for encoding an input sequence, wherein the bits of the input sequence are grouped into bit sequences according to probability state, and wherein the bits of each bit sequence are associated with a respective probability state, the method comprising: for each of the bit sequences, selecting a primary encoding table and a secondary encoding table based on the probability state for that bit sequence, the primary encoding table having rows each containing a parsed sequence and its corresponding primary codeword, the secondary encoding table having rows each containing a prefix of one of the parsed sequences and a corresponding secondary codeword; and encoding at least a portion of that bit sequence using the primary encoding table, and, if a flush event occurs, encoding a remainder of that bit sequence using the secondary encoding table, wherein at least two of the parsed sequences are of different lengths.