Patent attributes
Techniques for improving encoding and decoding data are described herein. According to one embodiment, buffering an initial chunk of an input stream. A number of escape tokens that would be emitted at each stage of encoding at least buffered initial chunk is determined. For each stage, a base value and a step value for the escape token are determined using a heuristic modeling function in view of the determined number of escape tokens such that a number of bits required to encode the input stream is minimized. The input stream are encoded using an adaptive context model having a context for each stage to generate an output stream, wherein each context is initialized with the corresponding base value and step value generated from the heuristic modeling function, where the output stream includes the base value and step value for each stage.