Github user SolidWallOfCode commented on a diff in the pull request:

    https://github.com/apache/trafficserver/pull/286#discussion_r38668014
  
    --- Diff: lib/ts/Vec.h ---
    @@ -964,41 +965,71 @@ qsort_Vec(C *left, C *right, bool (*lt)(C, C))
           }
         }
       } else {
    -    C *i = left + 1, *j = right - 1;
    -    C x = *left;
    -    for (;;) {
    -      while (lt(x, *j))
    -        j--;
    -      while (i < j && lt(*i, x))
    -        i++;
    -      if (i >= j)
    -        break;
    -      C t = *i;
    -      *i = *j;
    -      *j = t;
    -      i++;
    -      j--;
    +    C *center = left + ((right - left) / 2);
    +    C median;
    +
    +    // find the median
    +    if (lt(*center, *left)){  // order left and center
    +      swap(center, left);
    +    }
    +    if (lt(*(right-1), *left)){       // order left and right
    +      swap(right-1, left);
    +    }
    +    if (lt(*(right-1), *center)){  // order right and center
    +      swap((right-1), center);
    +    }
    +    swap(center, right-2);      // stash the median one from the right for 
now
    +    median = *(right-2);        // and that's the median of the 3
    +
    +    // now partition, pivoting on the median value
    +    // l ptr is +1 b/c we already put the lowest in there, ignore it for 
now
    --- End diff --
    
    Not quite right - l (left) is not necessarily the lowest value in the span, 
but we do know !(median < left) which makes it valid for being in its position 
relative to the pivot (median). Same for right-1, !(right < median) so it's 
correctly grouped already. (This is about the comment, the code is correct)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to