Sort by Peano curve.

@param objs Objects
@param start Start index
@param end End
@param mms Minmax values
@param dims Dimensions index
@param depth Dimension
@param bits Bit set for inversions
@param desc Current ordering
481149
protected void peanoSort(List<? extends SpatialComparable> objs, int start, int end, double[] mms, int[] dims, int depth, long[] bits, boolean desc) {
    final int numdim = (dims != null) ? dims.length : (mms.length >> 1);
    final int edim = (dims != null) ? dims[depth] : depth;
    // Find the splitting points.
    final double min = mms[2 * edim], max = mms[2 * edim + 1];
    final double tfirst = (min + min + max) / 3.;
    final double tsecond = (min + max + max) / 3.;
    // Safeguard against duplicate points:
    if(max - tsecond < 1E-10 || tsecond - tfirst < 1E-10 || tfirst - min < 1E-10) {
      boolean ok = false;
      for(int d = 0; d < numdim; d++) {
        int d2 = ((dims != null) ? dims[d] : d) << 1;
        if(mms[d2 + 1] - mms[d2] >= 1E-10) {
          ok = true;
          break;
        }
      }
      if(!ok) {
        return;
      }
    }
    final boolean inv = BitsUtil.get(bits, edim) ^ desc;
    // Split the data set into three parts
    int fsplit, ssplit;
    if(!inv) {
      fsplit = pivotizeList1D(objs, start, end, edim, tfirst, false);
      ssplit = (fsplit < end - 1) ? pivotizeList1D(objs, fsplit, end, edim, tsecond, false) : fsplit;
    }
    else {
      fsplit = pivotizeList1D(objs, start, end, edim, tsecond, true);
      ssplit = (fsplit < end - 1) ? pivotizeList1D(objs, fsplit, end, edim, tfirst, true) : fsplit;
    }
    int nextdim = (depth + 1) % numdim;
    // Do we need to update the min/max values?
    if(start < fsplit - 1) {
      mms[2 * edim] = !inv ? min : tsecond;
      mms[2 * edim + 1] = !inv ? tfirst : max;
      peanoSort(objs, start, fsplit, mms, dims, nextdim, bits, desc);
    }
    if(fsplit < ssplit - 1) {
      BitsUtil.flipI(bits, edim); // set (all but dim: we also flip "desc")
      mms[2 * edim] = tfirst;
      mms[2 * edim + 1] = tsecond;
      peanoSort(objs, fsplit, ssplit, mms, dims, nextdim, bits, !desc);
      BitsUtil.flipI(bits, edim);
    }
    if(ssplit < end - 1) {
      mms[2 * edim] = !inv ? tsecond : min;
      mms[2 * edim + 1] = !inv ? max : tfirst;
      peanoSort(objs, ssplit, end, mms, dims, nextdim, bits, desc);
    }
    // Restore ranges
    mms[2 * edim] = min;
    mms[2 * edim + 1] = max;
  }
562585
public static void sortReverse(double[] keys, int[] values, int start, int end) {
    quickSortReverse(keys, values, start, end);
  }
32941
private static void parseDockers(JSONObject modelJSON,
                                     Shape current) throws JSONException {
        if (modelJSON.has("dockers")) {
            ArrayList<Point> dockers = new ArrayList<Point>();

            JSONArray dockersObject = modelJSON.getJSONArray("dockers");
            for (int i = 0; i < dockersObject.length(); i++) {
                Double x = dockersObject.getJSONObject(i).getDouble("x");
                Double y = dockersObject.getJSONObject(i).getDouble("y");
                dockers.add(new Point(x,
                                      y));
            }
            if (dockers.size() > 0) {
                current.setDockers(dockers);
            }
        }
    }
404345
public static <E extends Comparable<E>> void recursiveQuickSort(List<E> array, int startIdx,
      int endIdx) {

    int idx = partition(array, startIdx, endIdx);

    // Recursively call quicksort with left part of the partitioned array
    if (startIdx < idx - 1) {
      recursiveQuickSort(array, startIdx, idx - 1);
    }

    // Recursively call quick sort with right part of the partitioned array
    if (endIdx > idx) {
      recursiveQuickSort(array, idx, endIdx);
    }
  }
1152566
function indexCurve(start, minX, minY, size) {
        var p = start;
        do {
            if (p.z === null)
                p.z = zOrder(p.x, p.y, minX, minY, size);
            p.prevZ = p.prev;
            p.nextZ = p.next;
            p = p.next;
        } while (p !== start);
        p.prevZ.nextZ = null;
        p.prevZ = null;
        sortLinked(p);
    }
154043
public void solveVandermondeSystem(int[] x, byte[][] y, 
                                     int len, int dataStart, int dataLen) {
    assert(x.length <= len && y.length <= len);
    int dataEnd = dataStart + dataLen;
    for (int i = 0; i < len - 1; i++) {
      for (int j = len - 1; j > i; j--) {
        for (int k = dataStart; k < dataEnd; k++) {
          y[j][k] = (byte)(y[j][k] ^ mulTable[x[i]][y[j - 1][k] & 0x000000FF]);
        }
      }
    }
    for (int i = len - 1; i >= 0; i--) {
      for (int j = i + 1; j < len; j++) {
        for (int k = dataStart; k < dataEnd; k++) {
          y[j][k] = (byte)(divTable[y[j][k] & 0x000000FF][x[j] ^ x[j - i - 1]]);
        }
      }
      for (int j = i; j < len - 1; j++) {
        for (int k = dataStart; k < dataEnd; k++) {
          y[j][k] = (byte)(y[j][k] ^ y[j + 1][k]);
        }
      }
    }
  }
464598
private void sortPoints() {
		final ControlPoint firstPt = (ControlPoint)list.get(0);
		final ControlPoint lastPt  = (ControlPoint)list.get(list.size()-1);
		Comparator compare = new Comparator() {
			public int compare(Object first, Object second) {
				if (first == firstPt) {
					return -1;
				}
				if (second == lastPt) {
					return -1;
				}
				
				float a = ((ControlPoint) first).pos;
				float b = ((ControlPoint) second).pos;
				return (int) ((a-b) * 10000);
			}
		};
		Collections.sort(list, compare);
	}
804655
protected void sortTables(int[] offsets, final ByteBuffer bb) {
    Integer[] off = new Integer[offsets.length];
    for (int i = 0; i < offsets.length; i++) off[i] = offsets[i];
    java.util.Arrays.sort(off, new java.util.Comparator<Integer>() {
      public int compare(Integer o1, Integer o2) {
        return keysCompare(o1, o2, bb);
      }
    });
    for (int i = 0; i < offsets.length; i++) offsets[i] = off[i];
  }
394675
public static void sort(int[] data, int start, int end, Comparator<? super DBIDRef> comp) {
    quickSort(data, start, end - 1, comp, new IntegerDBIDVar(), new IntegerDBIDVar(), new IntegerDBIDVar());
  }
1108144
function () {
                var _this = this;
                /** @type {?} */
                var _points = Array.from(this._points);
                /** @type {?} */
                var sortedPoints = [];
                /** @type {?} */
                var sortOrder = {
                    vertical: ['top', 'top', 'bottom', 'bottom'],
                    horizontal: ['left', 'right', 'right', 'left']
                };
                var _loop_1 = function (i) {
                    /** @type {?} */
                    var roles = Array.from([sortOrder.vertical[i], sortOrder.horizontal[i]]);
                    sortedPoints.push(_points.filter(function (point) {
                        return _this.limitsService.compareArray(point.roles, roles);
                    })[0]);
                };
                for (var i = 0; i < 4; i++) {
                    _loop_1(i);
                }
                this._sortedPoints = sortedPoints;
            }
824266
private void querySortedEndPointIndices_(AttributeStreamOfInt32 end_indices) {
		int size = (!m_b_envelopes_ref ? m_intervals.size() : m_envelopes_ref.size());

		for (int i = 0; i < 2 * size; i++)
			end_indices.add(i);

		sortEndIndices_(end_indices, 0, 2 * size);
	}
61261
public void sort() {
        if (initial)
            Arrays.sort(data, 0, size, comparator);
        else if (size > limit)
            sortTail();
    }
1351585
function slice(start, end) {
    var index = -1,
        object = Object(this),
        length = object.length >>> 0,
        result = [];

    start = toInteger(start);
    start = start < 0 ? max(length + start, 0) : min(start, length);
    start--;
    end = end == null ? length : toInteger(end);
    end = end < 0 ? max(length + end, 0) : min(end, length);

    while ((++index, ++start) < end) {
      if (start in object) {
        result[index] = object[start];
      }
    }
    return result;
  }
5361
function depthFirstSearch(obj, handler) {
  var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
  var reverse = arguments[3];

  var rootChildren = hp.isArray(obj) ? obj : [obj];
  //
  var StopException = function StopException() {};
  var func = function func(children, parent) {
    if (reverse) {
      children = children.slice();
      children.reverse();
    }
    var len = children.length;
    for (var i = 0; i < len; i++) {
      var item = children[i];
      var r = handler(item, i, parent);
      if (r === false) {
        // stop
        throw new StopException();
      } else if (r === 'skip children') {
        continue;
      } else if (r === 'skip siblings') {
        break;
      }
      if (item[childrenKey] != null) {
        func(item[childrenKey], item);
      }
    }
  };
  try {
    func(rootChildren);
  } catch (e) {
    if (e instanceof StopException) {
      // stop
    } else {
      throw e;
    }
  }
}
419594
int QueryCoordinates(Point3D[] dst, int dstSize, int beginIndex,
			int endIndex) {
		int endIndexC = endIndex < 0 ? m_pointCount : endIndex;
		endIndexC = Math.min(endIndexC, beginIndex + dstSize);

		if (beginIndex < 0 || beginIndex >= m_pointCount
				|| endIndexC < beginIndex)
			// TODO replace geometry exc
			throw new IllegalArgumentException();

		AttributeStreamOfDbl xy = (AttributeStreamOfDbl) getAttributeStreamRef(VertexDescription.Semantics.POSITION);
		AttributeStreamOfDbl z = null;
		double v = VertexDescription
				.getDefaultValue(VertexDescription.Semantics.Z);
		boolean bHasZ = hasAttribute(VertexDescription.Semantics.Z);
		if (bHasZ)
			z = (AttributeStreamOfDbl) getAttributeStreamRef(VertexDescription.Semantics.Z);
		int j = 0;
		for (int i = beginIndex; i < endIndexC; i++, j++) {
			dst[j].x = xy.read(2 * i);
			dst[j].y = xy.read(2 * i + 1);
			dst[j].z = bHasZ ? z.read(i) : v;

			dst[j] = getXYZ(i);
		}

		return endIndexC;
	}
1041305
public static Graph sortDFS(Graph g, Graph sortedGraph) {
        int nodes = g.getNodes();
        final GHIntArrayList list = new GHIntArrayList(nodes);
        list.fill(nodes, -1);
        final GHBitSetImpl bitset = new GHBitSetImpl(nodes);
        final AtomicInteger ref = new AtomicInteger(-1);
        EdgeExplorer explorer = g.createEdgeExplorer();
        for (int startNode = 0; startNode >= 0 && startNode < nodes;
             startNode = bitset.nextClear(startNode + 1)) {
            new DepthFirstSearch() {
                @Override
                protected GHBitSet createBitSet() {
                    return bitset;
                }

                @Override
                protected boolean goFurther(int nodeId) {
                    list.set(nodeId, ref.incrementAndGet());
                    return super.goFurther(nodeId);
                }
            }.start(explorer, startNode);
        }
        return createSortedGraph(g, sortedGraph, list);
    }
693203
function sortIndexes(indexes, sort) {
	function compare(a, b) {
		return a > b ? -1 : (b > a ? 1 : 0);
	}

	// format: [{ name: 'colName', direction: 'asc' }, { name: 'colName2', direction: 'desc' }]
	// direction is 'asc' by default

	indexes.sort(function (a, b) {
		var result = 0;

		for (var i = 0; i < sort.length && result === 0; i++) {
			var prop = sort[i].name;
			var factor = sort[i].direction === 'desc' ? -1 : 1;

			result = factor * compare(a[prop], b[prop]);
		}

		return result;
	});
}