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

jps.hh: redundant perculateUp call? #12

Open
emily785 opened this issue Apr 27, 2023 · 2 comments
Open

jps.hh: redundant perculateUp call? #12

emily785 opened this issue Apr 27, 2023 · 2 comments

Comments

@emily785
Copy link

inline void _fixIdx(SizeT i) { _percolateDown(i); _percolateUp(i); }

_percolateDown already calls _percolateUp, so the standalone call seems redundant.

@fgenesis
Copy link
Owner

fgenesis commented Apr 27, 2023

Yes, but the index i may change in _percolateDown() when traversing children. Depending on the new value a node goes either up or down the heap, and since that isn't tracked we need to try both directions.

EDIT: Better explained than i can right now: https://en.wikipedia.org/wiki/Binary_heap#Decrease_or_increase_key

@emily785
Copy link
Author

emily785 commented Apr 27, 2023

EDIT: Got it. Thank you for taking the time to answer.

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

No branches or pull requests

2 participants