Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use random access indexing in huffman::table::find
All DEFLATE canonical codes of a given bitsize are lexicographically consecutive values in the same order as the symbols they represent. As a result, the skip field for the first code of a given bitsize can be used to determine if an input code exists in the table in constant time. This commit replaces the linear time search of all codes of a given bitsize in huffman::table::find. Instead, the find method does the following: * if the input code bitsize is greater than the iterator code bitsize, advance the iterator by the iterator skip field * if the input code bitsize is less than the iterator code bitsize, return the iterator as an error * if the input code bitsize is equal to the iterator code bitsize: - determine the distance from the iterator code value to the input code value. If it is less than the iterator skip field, advance the iterator by the calculated distance and return the iterator as a success; otherwise - advance the iterator by the iterator skip field and continue resolves #90 Change-Id: Ic736c4d2e0150e53bd7bf1870104462294368a5c
- Loading branch information