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

Conversation

oliverlee
Copy link
Collaborator

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 oliverlee requested a review from garymm October 5, 2023 05:05
@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (4b1d0c0) 82.08% compared to head (e343fbf) 82.21%.

Files Patch % Lines
huffman/src/table.hpp 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #101      +/-   ##
==========================================
+ Coverage   82.08%   82.21%   +0.13%     
==========================================
  Files          17       17              
  Lines         625      624       -1     
  Branches       37       37              
==========================================
  Hits          513      513              
  Misses         94       94              
+ Partials       18       17       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oliverlee oliverlee force-pushed the Ic736c4d2e0150e53bd7bf1870104462294368a5c branch 2 times, most recently from a4795ec to 2fb547f Compare October 7, 2023 03:43
@oliverlee oliverlee force-pushed the I5597dc51ea5e9f086c71e2f9396fccd5ace923b2 branch from 4ed4fa6 to cbb5d82 Compare October 7, 2023 03:43
@garymm garymm force-pushed the I5597dc51ea5e9f086c71e2f9396fccd5ace923b2 branch from cbb5d82 to c6c647a Compare October 13, 2023 02:48
@garymm garymm force-pushed the Ic736c4d2e0150e53bd7bf1870104462294368a5c branch from 2fb547f to f041213 Compare October 13, 2023 02:52
Copy link
Owner

@garymm garymm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@oliverlee oliverlee force-pushed the I5597dc51ea5e9f086c71e2f9396fccd5ace923b2 branch 4 times, most recently from 200b3ef to c72bc7d Compare November 21, 2023 20:08
Base automatically changed from I5597dc51ea5e9f086c71e2f9396fccd5ace923b2 to master November 21, 2023 20:17
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 oliverlee force-pushed the Ic736c4d2e0150e53bd7bf1870104462294368a5c branch from f041213 to e343fbf Compare January 6, 2024 17:58
@oliverlee oliverlee requested a review from garymm January 6, 2024 17:58
@oliverlee oliverlee merged commit b4f1ad9 into master Jan 6, 2024
15 checks passed
@oliverlee oliverlee deleted the Ic736c4d2e0150e53bd7bf1870104462294368a5c branch January 6, 2024 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

change huffman::table to always be canonical
3 participants