-
Notifications
You must be signed in to change notification settings - Fork 215
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
only move the queue items if the new item index is less than size #498
base: main
Are you sure you want to change the base?
Conversation
The code as is currenly correct; there is no rush to merge this change. However, it does allocate extra memory in the vector to support the current insertion strategy, and it keeps track of its own size and capacity. We have a larger improvment to this whole class that simplifies the logic, reduces the memory requried, and removes the need for and explicit memmove, allowing std:vector to manage the insertion optimally. @SMovaghati we should bring in all of our changes to this class instead of this small change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SMovaghati I think we should bring our entire changes to this class for this PR; it simplifies the logic, it removes the extra size and capacity state, the need to allocate an extra item, and uses the built-in vector element moving when required.
@@ -78,7 +78,7 @@ class NeighborPriorityQueue | |||
} | |||
} | |||
|
|||
if (lo < _capacity) | |||
if (lo < _size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a check to make sure that _size + 1 <= _capacity? Otherwise we might run off the end of the vector.
What does this implement/fix? Briefly explain your changes.
Before, it used to always move the queue items, but that is not necessary if the item to add is at the end of the queue (and queue still has capacity).