Partition the points based on their distance to origin around the selected pivot.
@param left range start
@param right range end (exclusive)
@param pivot pivot for the partition
@param origin origin to compute the distance to
@return index of the pivot
331857
private int partitionItems(int left, int right, int pivot, double[] origin) {
		double pivotDistance = distance(origin, items[pivot]);
		listSwap(items, pivot, right - 1);
		listSwap(indexes, pivot, right - 1);
		int storeIndex = left;
		for (int i = left; i < right - 1; i++) {
			if (distance(origin, items[i]) <= pivotDistance) {
				listSwap(items, i, storeIndex);
				listSwap(indexes, i, storeIndex);
				storeIndex++;
			}
		}
		listSwap(items, storeIndex, right - 1);
		listSwap(indexes, storeIndex, right - 1);
		return storeIndex;
	}
616870
private int selectRightToLeft( int col , int[] scores ) {
		// see how far it can search
		int localMax = Math.min(imageWidth-regionWidth,col+maxDisparity)-col-minDisparity;

		int indexBest = 0;
		int indexScore = col;
		int scoreBest = scores[col];
		indexScore += imageWidth+1;

		for( int i = 1; i < localMax; i++ ,indexScore += imageWidth+1) {
			int s = scores[indexScore];

			if( s < scoreBest ) {
				scoreBest = s;
				indexBest = i;
			}
		}

		return indexBest;
	}
970185
public static Point nearestSegmentPoint(double startX, double startY, double endX, double endY, double pointX, double pointY) {
        double xDiff = endX - startX;
        double yDiff = endY - startY;
        double length2 = xDiff * xDiff + yDiff * yDiff;
        if (length2 == 0) return new Point(startX, startY);
        double t = ((pointX - startX) * (endX - startX) + (pointY - startY) * (endY - startY)) / length2;
        if (t < 0) return new Point(startX, startY);
        if (t > 1) return new Point(endX, endY);
        return new Point(startX + t * (endX - startX), startY + t * (endY - startY));
    }
18583
@Override
  final protected void addRangeEmpty(int left, int right) {
    String key = left + "_" + right;
    if (index.containsKey(key)) {
      // do nothing (empty...)
    } else {
      root = addRange(root, left, right, null);
      root.color = IntervalRBTreeNode.BLACK;
    }
  }
48368
def pivot(self, speed, durationS=-1.0):
        
        if speed < 0:
            self.left_fwd(min(abs(speed), 255))
            self.right_rev(min(abs(speed), 255))
        else:
            self.left_rev(min(abs(speed), 255))
            self.right_fwd(min(abs(speed), 255))
        if durationS > 0:
            self.board.sleep(durationS)
            self.left_stop()
            self.right_stop()
749349
public static IntSupplier leftAlignedTo(IPositioned other, int offset)
	{
		checkNotNull(other);
		return () -> {
			return other.position().x() + offset;
		};
	}
1233939
private static void quickSortReverse(double[] keys, int[] vals, final int start, final int end) {
    final int len = end - start;
    if(len < INSERTION_THRESHOLD) {
      insertionSortReverse(keys, vals, start, end);
      return;
    }
    final int last = end - 1;

    // Choose pivots by looking at five candidates.
    final int seventh = (len >> 3) + (len >> 6) + 1;
    final int m3 = (start + end) >> 1; // middle
    final int m2 = m3 - seventh;
    final int m1 = m2 - seventh;
    final int m4 = m3 + seventh;
    final int m5 = m4 + seventh;

    // Mixture of insertion and merge sort:
    sortReverse5(keys, vals, m1, m2, m3, m4, m5);

    // Move pivot to the front.
    double pivotkey = keys[m3];
    int pivotval = vals[m3];
    keys[m3] = keys[start];
    vals[m3] = vals[start];

    // The interval to pivotize
    int left = start + 1; // Without pivot
    int right = last; // inclusive

    // This is the classic QuickSort loop:
    while(true) {
      // Move duplicates to right partition, i.e. < here, <= below.
      while(left <= right && keys[left] > pivotkey) {
        left++;
      }
      while(left <= right && pivotkey >= keys[right]) {
        right--;
      }
      if(right <= left) {
        break;
      }
      swap(keys, vals, left, right);
      left++;
      right--;
    }
    // right now points to the last element smaller than the pivot.
    // Move pivot back into the appropriate place
    keys[start] = keys[right];
    vals[start] = vals[right];
    keys[right] = pivotkey;
    vals[right] = pivotval;

    // Recursion when more than one element only:
    if(start + 1 < right) {
      quickSortReverse(keys, vals, start, right);
    }
    int rstart = right + 1;
    // Avoid recursing on duplicates of the pivot:
    while(rstart < last && keys[rstart] >= keys[right]) {
      rstart++;
    }
    // Recurse when _more_ than 1 element only
    if(rstart < last) {
      quickSortReverse(keys, vals, rstart, end);
    }
  }
882336
public static <C extends Comparable> Ordering<Range<C>> orderingByUpperEndpoint() {
        return new Ordering<Range<C>>() {
            @Override
            public int compare(final Range<C> left, final Range<C> right) {
                return ComparisonChain.start()
                    .compare(left.hasUpperBound(), right.hasUpperBound())
                    .compare(left.upperEndpoint(), right.upperEndpoint())
                    .result();
            }
        };
    }
692215
def geo_distance(left, right, use_spheroid=None):
    
    op = ops.GeoDistance(left, right, use_spheroid)
    return op.to_expr()
695587
public static void getDefaultPivot(Settings settings, Point out) {
        getMovementAreaPosition(settings, tmpRect2);
        Gravity.apply(settings.getGravity(), 0, 0, tmpRect2, tmpRect1);
        out.set(tmpRect1.left, tmpRect1.top);
    }
504185
function locationOf(element, array, start, end) {
  start = start || 0;
  end = end || array.length;
  var pivot = parseInt(start + (end - start) / 2, 10);
  if (end-start <= 1 || array[pivot] === element) return pivot;
  if (array[pivot] < element) {
    return locationOf(element, array, pivot, end);
  } else {
    return locationOf(element, array, start, pivot);
  }
}
1076750
private static <T extends Comparable<? super T>> 
    void quicksort( T[] arr, int left, int right )
    {
        if ( left + CUTOFF <= right  ) {
            //find the pivot
            T pivot = median( arr, left, right );
            
            //start partitioning
            int i = left, j = right - 1;
            for ( ; ; ) {
                while ( arr[++i].compareTo( pivot ) < 0 ) ;
                while ( arr[--j].compareTo( pivot ) > 0 ) ;
                if ( i < j ) {
                    swapReferences( arr, i, j );
                } else {
                    break;
                }
            }
            
            //swap the pivot reference back to the small collection.
            swapReferences( arr, i, right - 1 );
            
            quicksort( arr, left, i - 1 );        //sort the small collection.
            quicksort( arr, i + 1, right );        //sort the large collection.
            
        } else {
            //if the total number is less than CUTOFF we use insertion sort instead.
            insertionSort( arr, left, right );
        }
    }
1117270
public static <C extends Comparable> Ordering<Range<C>> orderingByLowerEndpoint() {
        return new Ordering<Range<C>>() {
            @Override
            public int compare(final Range<C> left, final Range<C> right) {
                return ComparisonChain.start()
                    .compare(left.hasLowerBound(), right.hasLowerBound())
                    .compare(left.lowerEndpoint(), right.lowerEndpoint())
                    .result();
            }
        };
    }
333802
private Type.Field[] determinePivotFields(Tuple<Type.Field> lhsFields, Tuple<Type.Field> rhsFields,
			LifetimeRelation lifetimes, LinkageStack stack) {
		Type.Field[] pivots = new Type.Field[lhsFields.size()];
		//
		for (int i = 0; i != lhsFields.size(); ++i) {
			Type.Field lhsField = lhsFields.get(i);
			Identifier lhsFieldName = lhsField.getName();
			for (int j = 0; j != rhsFields.size(); ++j) {
				Type.Field rhsField = rhsFields.get(j);
				Identifier rhsFieldName = rhsField.getName();
				if (lhsFieldName.equals(rhsFieldName)) {
					// Matched field, now compute its type.
					Type type = apply(lhsField.getType(), rhsField.getType(), lifetimes, stack);
					// Check whether is a pivot or not
					if (!(type instanceof Type.Void)) {
						// Yes, is a pivot
						pivots[i] = new Type.Field(lhsFieldName, type);
					}
					break;
				}
			}
		}
		return pivots;
	}
151772
public static CellRangeAddress getMergedRegion(final Sheet sheet, final int rowIdx, final int colIdx) {
        ArgUtils.notNull(sheet, "sheet");

        final int num = sheet.getNumMergedRegions();
        for(int i=0; i < num; i ++) {
            final CellRangeAddress range = sheet.getMergedRegion(i);
            if(range.isInRange(rowIdx, colIdx)) {
                return range;
            }
        }

        return null;
    }
832345
private void quicksort(short[] a, int[] indexes, int left, int right) {
        if (right <= left)
            return;
        int i = partition(a, indexes, left, right);
        quicksort(a, indexes, left, i - 1);
        quicksort(a, indexes, i + 1, right);
    }
699025
private void computeFirstRow(GrayS16 left, GrayS16 right ) {
		// compute horizontal scores for first row block
		for( int row = 0; row < regionHeight; row++ ) {

			int scores[] = horizontalScore[row];

			UtilDisparityScore.computeScoreRow(left, right, row, scores,
					minDisparity,maxDisparity,regionWidth,elementScore);
		}

		// compute score for the top possible row
		for( int i = 0; i < lengthHorizontal; i++ ) {
			int sum = 0;
			for( int row = 0; row < regionHeight; row++ ) {
				sum += horizontalScore[row][i];
			}
			verticalScore[i] = sum;
		}

		// compute disparity
		computeDisparity.process(radiusY, verticalScore);
	}