Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use random access indexing in huffman::table::find #101

Merged
merged 1 commit into from
Jan 6, 2024

Commits on Jan 6, 2024

  1. 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
    oliverlee committed Jan 6, 2024
    Configuration menu
    Copy the full SHA
    e343fbf View commit details
    Browse the repository at this point in the history