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

store huffman table elements in forward order #94

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

oliverlee
Copy link
Collaborator

Remove use of std::reverse_iterator when iterating over table elements.
Instead, invoke reverse on the underlying table storage after
construction.

Change-Id: I45916a591f51298fff8b4012b9507b781021100e

@codecov-commenter
Copy link

codecov-commenter commented Sep 27, 2023

Codecov Report

Merging #94 (5bac1df) into master (8dd46b1) will decrease coverage by 3.12%.
The diff coverage is 97.87%.

@@            Coverage Diff             @@
##           master      #94      +/-   ##
==========================================
- Coverage   98.91%   95.80%   -3.12%     
==========================================
  Files          11       11              
  Lines         277      286       +9     
==========================================
  Hits          274      274              
- Misses          3       12       +9     
Files Coverage Δ
huffman/src/detail/static_vector.hpp 59.09% <100.00%> (-36.15%) ⬇️
huffman/src/detail/table_node.hpp 100.00% <100.00%> (ø)
huffman/src/detail/table_storage.hpp 100.00% <ø> (ø)
huffman/src/table.hpp 96.84% <97.36%> (-0.78%) ⬇️

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@oliverlee oliverlee force-pushed the I45916a591f51298fff8b4012b9507b781021100e branch from b4e4d80 to bc94c5c Compare September 28, 2023 05:05
@oliverlee oliverlee force-pushed the Ic0e5224850d8478aa92806a8f21248e979acce04 branch from 9db71f1 to d1c8b2e Compare October 5, 2023 00:28
Base automatically changed from Ic0e5224850d8478aa92806a8f21248e979acce04 to master October 5, 2023 00:45
@oliverlee oliverlee force-pushed the I45916a591f51298fff8b4012b9507b781021100e branch from bc94c5c to 6912c7f Compare October 5, 2023 00:54
@oliverlee oliverlee changed the base branch from master to If703d0b0a6307ebcf9e64722431069247ba51800 October 5, 2023 00:54
Base automatically changed from If703d0b0a6307ebcf9e64722431069247ba51800 to master October 5, 2023 00:57
@oliverlee oliverlee changed the base branch from master to If703d0b0a6307ebcf9e64722431069247ba51800 October 5, 2023 01:08
@oliverlee oliverlee changed the base branch from If703d0b0a6307ebcf9e64722431069247ba51800 to master October 5, 2023 01:09
@oliverlee oliverlee force-pushed the I45916a591f51298fff8b4012b9507b781021100e branch from 6912c7f to debbdb9 Compare October 5, 2023 01:09
using C [[maybe_unused]] = std::common_type_t<std::make_unsigned_t<S>, U>;

assert(
static_cast<C>(uint) < static_cast<C>(std::numeric_limits<S>::max()));
Copy link
Collaborator Author

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 I45916a591f51298fff8b4012b9507b781021100e branch from debbdb9 to 72620db Compare October 7, 2023 03:38
for (; first != last; first = first->next()) {
using S = std::ranges::range_difference_t<decltype(table_)>;

assert(std::cmp_less_equal(uint, std::numeric_limits<S>::max()));
Copy link
Owner

Choose a reason for hiding this comment

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

Why std::cmp_less_equal instead of <=?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There's a comparison of signed with unsigned integral types and I don't know the integral promotion and conversion rules. With cmp_less_equal, it "will do the right thing". If both operands were signed or both were unsigned integrals, I would use <=. I also partially rely on the compiler to catch these issues with -Wconversion

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wconversion

There's some decent motivation in the original proposal to add these functions:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0586r2.html

}
// postcondition
assert(total_freq == table_.front().frequency());
std::ranges::reverse(table_);
Copy link
Owner

Choose a reason for hiding this comment

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

add a comment about why

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll add this later:

If front().frequency() does not equal total_freq, we have skipped over nodes during construction of the implicit Huffman tree.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or you feel free to :)

Copy link
Owner

Choose a reason for hiding this comment

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

I meant comment about why the reverse, not about the assertion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@garymm
Copy link
Owner

garymm commented Oct 11, 2023

Hmm test coverage is down! Did you add functions we don't need to static_vector or table?

@oliverlee
Copy link
Collaborator Author

add

I only added empty() and used it immediately. Not sure how coverage is being calculated but we also don't explicitly test anything from static_vector.

@garymm
Copy link
Owner

garymm commented Oct 11, 2023

Hmm yeah probably an artifact of how we're calculating things.
Anyways, LGTM, just add a comment about why reversing in table.hpp.

@oliverlee oliverlee force-pushed the I45916a591f51298fff8b4012b9507b781021100e branch from 72620db to 1f290ae Compare October 11, 2023 23:59
@oliverlee oliverlee requested a review from garymm October 11, 2023 23:59
@oliverlee
Copy link
Collaborator Author

Failing code coverage is due to lack of tests for tables with zero symbols and one symbol

@oliverlee oliverlee force-pushed the I45916a591f51298fff8b4012b9507b781021100e branch from 1f290ae to 44ba57c Compare October 12, 2023 00:37
Remove use of std::reverse_iterator when iterating over table elements.
Instead, invoke reverse on the underlying table storage after
construction.

Change-Id: I45916a591f51298fff8b4012b9507b781021100e
@oliverlee oliverlee force-pushed the I45916a591f51298fff8b4012b9507b781021100e branch from 44ba57c to 5bac1df Compare October 12, 2023 02:46
@oliverlee oliverlee merged commit 9098e1c into master Oct 12, 2023
26 of 28 checks passed
@oliverlee oliverlee deleted the I45916a591f51298fff8b4012b9507b781021100e branch October 12, 2023 05:31
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.

3 participants