Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-9960

Avoid unnecessary top element replacement for equal elements in PriorityQueue

Details

    • Improvement
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • None
    • 9.0
    • None
    • None
    • New

    Description

      Currently the priority queue implementation always replaces the top (minimum) element, even if it is equal to the provided argument. This seems redundant. I've modified the condition and polished a few other minor things (unnecessary cast, size modification even if add throws AIOOB).

      Separately from the above, it is quite weird that a pq of size zero is allowed (and actually used!). The code is incorrect in this case, allowing add() to proceed and top() to return the added value. I understand it's a heavily used data structure but perhaps we should at least add an assertion to add() checking for zero-size?

      Attachments

        Issue Links

          Activity

            People

              dweiss Dawid Weiss
              dweiss Dawid Weiss
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h