Sha256: 0a604d48bbd8cf8032b49565d5ceb6ae0601454e214eed32e87b7e0a15ce87d5

Contents?: true

Size: 1.24 KB

Versions: 25

Compression:

Stored size: 1.24 KB

Contents

package processing.data;


/**
 * Internal sorter used by several data classes.
 * Advanced users only, not official API.
 */
public abstract class Sort implements Runnable {

    /**
     *
     */
    public Sort() { }

    /**
     *
     */
    public void run() {
    int c = size();
    if (c > 1) {
      sort(0, c - 1);
    }
  }

    /**
     *
     * @param i
     * @param j
     */
    protected void sort(int i, int j) {
    int pivotIndex = (i+j)/2;
    swap(pivotIndex, j);
    int k = partition(i-1, j);
    swap(k, j);
    if ((k-i) > 1) sort(i, k-1);
    if ((j-k) > 1) sort(k+1, j);
  }

    /**
     *
     * @param left
     * @param right
     * @return
     */
    protected int partition(int left, int right) {
    int pivot = right;
    do {
      while (compare(++left, pivot) < 0) { }
      while ((right != 0) && (compare(--right, pivot) > 0)) { }
      swap(left, right);
    } while (left < right);
    swap(left, right);
    return left;
  }

    /**
     *
     * @return
     */
    abstract public int size();

    /**
     *
     * @param a
     * @param b
     * @return
     */
    abstract public float compare(int a, int b);

    /**
     *
     * @param a
     * @param b
     */
    abstract public void swap(int a, int b);
}

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
picrate-2.5.2-java src/main/java/processing/data/Sort.java
picrate-2.5.1-java src/main/java/processing/data/Sort.java
picrate-2.5.0-java src/main/java/processing/data/Sort.java
picrate-2.4.2-java src/main/java/processing/data/Sort.java
picrate-2.4.1-java src/main/java/processing/data/Sort.java
picrate-2.4.0-java src/main/java/processing/data/Sort.java
picrate-2.3.0-java src/main/java/processing/data/Sort.java
picrate-2.2.0-java src/main/java/processing/data/Sort.java
picrate-2.1.2-java src/main/java/processing/data/Sort.java
picrate-2.1.1-java src/main/java/processing/data/Sort.java
picrate-2.1.0-java src/main/java/processing/data/Sort.java
picrate-2.0.1-java src/main/java/processing/data/Sort.java
picrate-1.3.0-java src/main/java/processing/data/Sort.java
picrate-2.0.0.pre-java src/main/java/processing/data/Sort.java
picrate-1.2.4-java src/main/java/processing/data/Sort.java
picrate-1.2.3-java src/main/java/processing/data/Sort.java
picrate-1.2.2-java src/main/java/processing/data/Sort.java
picrate-1.2.1-java src/main/java/processing/data/Sort.java
picrate-1.2.0-java src/main/java/processing/data/Sort.java
picrate-1.1.0-java src/main/java/processing/data/Sort.java