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

fix: comment for NextHighestPowerOf2 #644

Merged
merged 2 commits into from
Aug 22, 2022

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented Aug 20, 2022

@rootulp rootulp self-assigned this Aug 20, 2022
@codecov-commenter
Copy link

codecov-commenter commented Aug 20, 2022

Codecov Report

Merging #644 (127f990) into main (24bbf82) will increase coverage by 8.67%.
The diff coverage is 75.25%.

@@            Coverage Diff             @@
##             main     #644      +/-   ##
==========================================
+ Coverage   29.78%   38.45%   +8.67%     
==========================================
  Files          16       19       +3     
  Lines        2055     2538     +483     
==========================================
+ Hits          612      976     +364     
- Misses       1382     1476      +94     
- Partials       61       86      +25     
Impacted Files Coverage Δ
pkg/shares/shares.go 50.00% <50.00%> (ø)
pkg/shares/share_splitting.go 75.00% <75.00%> (ø)
pkg/shares/share_merging.go 77.11% <77.11%> (ø)
x/payment/types/payfordata.go 77.20% <100.00%> (+1.85%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -188,8 +188,7 @@ func powerOf2MountainRange(l, k uint64) []uint64 {
return output
}

// NextHighestPowerOf2 returns the next lowest power of 2 unless the input is a power
// of two, in which case it returns the input
// NextHighestPowerOf2 returns the next highest power of 2
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this is the correct resolution. If anything, the function should be renamed to NextLowestPowerOf2? Additionally, the linked issue should be resolved by properly documenting behavior when the input is a power of 2.

These are two orthogonal things.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. This function finds the next highest power of two. Confirmed by checking these tests
  2. I think it is more confusing to explicitly document the behavior when the input is a power of 2 because the behavior is the same as when the input is not a power of 2. In both cases, this function returns the next highest power of 2. I think examples may be the easiest way to convey the behavior
// NextHighestPowerOf2 returns the next highest power of 2. Examples:
// NextHighestPowerOf2(1) = 2
// NextHighestPowerOf2(2) = 4
// NextHighestPowerOf2(11) = 16
func NextHighestPowerOf2(v uint64) uint64 {

thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

UPDATE: now I see why highest is misleading here 🤦‍♂️ this function returns the next lowest power of 2 that is higher than the input. Hmm will re-think comments / function naming here

Copy link
Member

Choose a reason for hiding this comment

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

NextHigherPowerOf2 would also work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will avoid renaming because there exists a nextLowestPowerOf2 already:

func nextLowestPowerOf2(v uint64) uint64 {

@rootulp rootulp requested a review from adlerjohn August 22, 2022 15:09
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

this is my bad, pls feel free to rename any of the functions as we see fit.

@rootulp
Copy link
Collaborator Author

rootulp commented Aug 22, 2022

Will merge this but happy to create a follow-up PR if @adlerjohn has any other feedback

@adlerjohn
Copy link
Member

It's fine as-is, but could you file a follow-up issue @rootulp so we don't forget?

@rootulp
Copy link
Collaborator Author

rootulp commented Aug 22, 2022

Sure #648

@rootulp rootulp deleted the rp/fix-comment branch August 22, 2022 23:58
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.

Comment of NextHighestPowerOf2 is inaccurate
4 participants