8. A computer readable medium including instructions that, when executed by a processing system, cause the processing system to perform a method for encoding data, the method comprising: in response to an input stream having a plurality of symbols in sequence, buffering an initial chunk of symbols; determining a number of escape tokens that would be emitted at each stage of encoding at least buffered initial chunk; for each stage, determining a base value and a step value for the escape token 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; and encoding the input stream 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, and wherein the output stream includes the base value and step value for each stage.
13. The computer readable medium of claim 8 , wherein encoding the input stream comprises: initializing a current context to have an initial count of an escape token equals to the base value corresponding to the current context; in response to a symbol retrieved from an input stream, emitting an escape token if the current context cannot encode the symbol; and incrementing by a step value corresponding to the current context a count of the escape token in the current context based on the base value.