Sha256: c5fdaacf98585237e0d9755dc8035764052f84a25c7c4d7234ca85057f2ffa01

Contents?: true

Size: 911 Bytes

Versions: 15

Compression:

Stored size: 911 Bytes

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);
    }
  }


  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);
  }


  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;
  }


  abstract public int size();
  abstract public int compare(int a, int b);
  abstract public void swap(int a, int b);
}

Version data entries

15 entries across 14 versions & 1 rubygems

Version Path
propane-3.11.0-java src/main/java/processing/data/Sort.java
propane-3.10.0-java src/main/java/processing/data/Sort.java
propane-3.10.0-java lib/java/processing/data/Sort.java
propane-3.9.0-java src/main/java/processing/data/Sort.java
propane-3.8.0-java src/main/java/processing/data/Sort.java
propane-3.7.1-java src/main/java/processing/data/Sort.java
propane-3.7.0.pre-java src/main/java/processing/data/Sort.java
propane-3.6.0-java src/main/java/processing/data/Sort.java
propane-3.5.0-java src/main/java/processing/data/Sort.java
propane-3.1.0.pre-java src/main/java/processing/data/Sort.java
propane-2.9.3-java src/main/java/processing/data/Sort.java
propane-3.0.1.pre-java src/main/java/processing/data/Sort.java
propane-2.9.2-java src/main/java/processing/data/Sort.java
propane-3.0.0.pre-java src/main/java/processing/data/Sort.java
propane-2.9.1-java src/main/java/processing/data/Sort.java