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 Int indexes to make them sortable. #114

Merged
merged 1 commit into from
Dec 15, 2021

Conversation

jakedt
Copy link
Contributor

@jakedt jakedt commented Nov 29, 2021

Fixes #113

Copy link
Contributor

@kisunji kisunji left a comment

Choose a reason for hiding this comment

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

Minor comments but looks good!

Our team had some non-blocking comments about the readability of TestIntFieldIndexSortability - do you think it might be clearer to represent the numbers in 0b_ binary form to better see the bit comparisons between the inputs?

Not all the test cases but some of the edge cases (comparing -0b_10000000 and 0b_1 for instance) that would have failed before this PR would be nice to see.

index.go Outdated
Comment on lines 343 to 358
switch size {
case 1:
buf[0] = uint8(scaled)
case 2:
binary.BigEndian.PutUint16(buf, uint16(scaled))
case 4:
binary.BigEndian.PutUint32(buf, uint32(scaled))
case 8:
binary.BigEndian.PutUint64(buf, uint64(scaled))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add a default: panic case in case there's a programmer error in passing an unsupported size

func encodeInt(val int64, size int) []byte {
buf := make([]byte, size)

scaled := val ^ int64(-1<<(size*8-1))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a comment explaining what this line does?

@jakedt
Copy link
Contributor Author

jakedt commented Dec 15, 2021

I made the two changes with inline comments, but I can't figure out how to make the sortability tests more readable with the binary formatting. Some of the numbers would literally be 64 characters long!

If you want to send over something more readable I would be happy to include it in this PR, or I won't have any hard feelings if someone wants to fix this up after it's in.

Copy link
Contributor

@kisunji kisunji left a comment

Choose a reason for hiding this comment

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

Yeah not a blocker at all! Thanks for this valuable bugfix 👍

@kisunji kisunji merged commit fcf5d84 into hashicorp:master Dec 15, 2021
@jakedt
Copy link
Contributor Author

jakedt commented May 2, 2022

@kisunji do you know when this might make it into a release? I think i'm actually being bitten by this bug now.

@kisunji
Copy link
Contributor

kisunji commented May 2, 2022

@kisunji do you know when this might make it into a release? I think i'm actually being bitten by this bug now.

Just tagged a new version now!

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.

Index out of order for IntFieldIndex
2 participants