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

SorterTemplate.quicksort incorrect

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 3.6.1, 4.0, 4.1
    • Fix Version/s: 3.6.1, 4.0, 4.1
    • Component/s: core/other
    • Labels:
    • Lucene Fields:
      New, Patch Available

      Description

      On trying to use the very useful o.a.l.utils.SorterTemplate, I stumbled upon inconsistent sorting behaviour, of course, only a randomized test caught this

      Because SorterTemplate.quicksort is used in several places in the code (directly BytesRefList, ArrayUtil, BytesRefHash, CollectionUtil and transitively index and search), I'm a bit puzzled that this either hasn't been caught by another higher-level test or that neither my test nor my understanding of an insufficiency in the code is valid
      If the former holds and given that the same code is released in 3.6 and 4.0, this might even be a more critical issue requiring a higher priority than 'major'.
      So, can a second pair of eyes please have a timely look at the attached test and patch?

      Basically the current quicksort implementation seems to assume that luckily always the median is chosen as pivot element by grabbing the mid element, not handling the case where the initially chosen pivot ends up not in the middle. Hope this and the test helps to understand the issue.

      Reproducible, currently failing test and a patch attached.

        Attachments

        1. SorterTemplate.java.patch
          1 kB
          Stefan Pohl
        2. TestSorterTemplate.java
          2 kB
          Uwe Schindler
        3. TestSorterTemplate.java
          2 kB
          Stefan Pohl

          Activity

            People

            • Assignee:
              uschindler Uwe Schindler
              Reporter:
              spo Stefan Pohl
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: