Skip to content

Commit

Permalink
eliminate condition where _head - 1 == _tail + 1
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperlarson committed Aug 5, 2024
1 parent 6179033 commit 6a04e7c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/BoundedPriorityDeque.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ class BoundedPriorityDequeBase {
}

auto index = binarySearch(element);
if (index == nextIndex(_tail)) _tail = nextIndex(_tail);
if (index == nextIndex(_tail)) {
if (index == prevIndex(_head) && compare(element.key, topK())) _head = prevIndex(_head);
else _tail = nextIndex(_tail);
}
else if (index == prevIndex(_head)) _head = prevIndex(_head);
else if (_head <= _tail && _head > 0) {
std::move(_buffer.begin() + _head, _buffer.begin() + index + 1, _buffer.begin() + _head - 1);
Expand Down

0 comments on commit 6a04e7c

Please sign in to comment.