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

pos.IndexAtDepth() always equals pos.TraceIndex(pos.Depth()) #13980

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

zhiqiangxu
Copy link
Contributor

Simplify the code a bit by the invariant that pos.IndexAtDepth() == pos.TraceIndex(pos.Depth()) always holds.

@zhiqiangxu zhiqiangxu requested review from a team as code owners January 25, 2025 07:12
@zhiqiangxu zhiqiangxu requested a review from mbaxter January 25, 2025 07:12
@mbaxter
Copy link
Contributor

mbaxter commented Jan 30, 2025

/ci authorize e02af61

Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

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

That invariant does not hold. pos.PositionAtIndex returns the index at the current depth of the position which may be above the split depth. ie gindex 2 has PositionAtIndex=0 but a much larger TraceIndex(30) since it follows the right child at each depth to reach depth 30.

@ajsutton
Copy link
Contributor

Sorry, misread - at pos.Depth() yes that should hold, but now I'm suspicious why it's using pos.Depth instead of the split depth.

@ajsutton
Copy link
Contributor

Ah I see - we're determining if we're to the left or right of a position from higher up. Given we explicitly want to compare the trace index of the two positions at the same depth, I'd argue the original code is clearer since it's then comparing the same thing (both position's TraceIndex at a specific depth) vs comparing differently named things that happen to be equivalent in this case.

@zhiqiangxu
Copy link
Contributor Author

I'm OK with close this PR if @ajsutton thinks the original code is clearer. IMO the new code is more explicit in what it's comparing: the IndexAtDepth, but anyway it may be just a personal preference:)

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