public static double fraction( GrowQueue_F64 list , double fraction ) { int k = (int)((list.size-1)*fraction+0.5); return QuickSelect.select(list.data,k,list.size); } }
/** * If this function is called the exact sort routine will not be used and instead an approximate routine will * be used. * @param numBins Number of bins. Try 2000. More bins the more accurate it will be */ public void configureApproximateSort( int numBins ) { sorterApprox = new ApproximateSort_F32(numBins); }
public ApproximateSort_F32(int minValue, int maxValue, int numBins) { this.numBins = numBins; setRange(minValue,maxValue); }
@Test public void sortObject() { int numBins = 150; double tolerance = 15.0/numBins; double[] data = random(-5,10,4,200); SortableParameter_F64[] objs = convert(data); ApproximateSort_F64 alg = new ApproximateSort_F64(-5,10,numBins); alg.sortObject(objs, 4, 200); // see if the sort was to within the expected tolerance for( int i = 5; i < objs.length; i++ ) { assertTrue( objs[i].sortValue > objs[i-1].sortValue -tolerance ); } }
public ApproximateSort_F64(double minValue, double maxValue, int numBins) { this.numBins = numBins; setRange(minValue,maxValue); }
public CountingSort(int minValue, int maxValue) { setRange(minValue,maxValue); }
public EllipseClustersIntoAsymmetricGrid() { sorter = new QuickSortComparator<>(new Comparator<Edge>() { @Override public int compare(Edge o1, Edge o2) { if (o1.angle < o2.angle) return -1; else if (o1.angle > o2.angle) return 1; else return 0; } }); }
public static void main( String args[] ) throws FileNotFoundException { GenerateQuickSelect app = new GenerateQuickSelect(); app.generate(); } }
@Test public void test_F32() { float[] ret = BenchMarkSort.createRandom_F32(rand,200); ShellSort.sort(ret); float prev = ret[0]; for( int i = 1; i < ret.length; i++ ) { if( ret[i] < prev ) fail("Not ascending"); prev = ret[i]; } }
@Test public void test_F64() { double[] ret = BenchMarkSort.createRandom_F64(rand,200); ShellSort.sort(ret); double prev = ret[0]; for( int i = 1; i < ret.length; i++ ) { if( ret[i] < prev ) fail("Not ascending"); prev = ret[i]; } }
@Test public void testSortDouble() { double[] ret = BenchMarkSort.createRandom_F64(rand,200); StraightInsertionSort.sort(ret); double prev = ret[0]; for( int i = 1; i < ret.length; i++ ) { if( ret[i] < prev ) fail("Not ascending"); } } }
@Test public void test_S32() { int[] ret = BenchMarkSort.createRandom_S32(rand,200); ShellSort.sort(ret); double prev = ret[0]; for( int i = 1; i < ret.length; i++ ) { if( ret[i] < prev ) fail("Not ascending"); prev = ret[i]; } }
public static SortableParameter_F32[] copy( SortableParameter_F32[] list ) { SortableParameter_F32[] ret = new SortableParameter_F32[ list.length ]; for( int i = 0; i < list.length; i++ ) { ret[i] = new SortableParameter_F32(); ret[i].sortValue = list[i].sortValue; } return ret; }
public static SortableParameter_F64[] copy( SortableParameter_F64[] list ) { SortableParameter_F64[] ret = new SortableParameter_F64[ list.length ]; for( int i = 0; i < list.length; i++ ) { ret[i] = new SortableParameter_F64(); ret[i].sortValue = list[i].sortValue; } return ret; }
public static double fraction( GrowQueue_F64 list , double fraction ) { int k = (int)((list.size-1)*fraction+0.5); return QuickSelect.select(list.data,k,list.size); } }
public ApproximateSort_F32(int minValue, int maxValue, int numBins) { this.numBins = numBins; setRange(minValue,maxValue); }
public ApproximateSort_F64(double minValue, double maxValue, int numBins) { this.numBins = numBins; setRange(minValue,maxValue); }
public CountingSort(int minValue, int maxValue) { setRange(minValue,maxValue); }
public SortableParameter_F32[] convert(float[] data ) { SortableParameter_F32[] ret = new SortableParameter_F32[data.length]; for( int i = 0; i < data.length; i++ ) { ret[i] = new SortableParameter_F32(data[i]); } return ret; } }
public SortableParameter_F64[] convert(double[] data ) { SortableParameter_F64[] ret = new SortableParameter_F64[data.length]; for( int i = 0; i < data.length; i++ ) { ret[i] = new SortableParameter_F64(data[i]); } return ret; } }