forked from Hithomelabs/Princeton1
Reviewed-on: Hithomelabs/Princeton1#17 Reviewed-by: kruti <krutis0201@gmail.com> Co-authored-by: hitanshu310 <hitanshu98@gmail.com> Co-committed-by: hitanshu310 <hitanshu98@gmail.com>
39 lines
1.2 KiB
Java
39 lines
1.2 KiB
Java
package com.hithomelabs.clients.Benchmarks;
|
|
|
|
|
|
import com.hithomelabs.princeton1.common.Apple;
|
|
import com.hithomelabs.princeton1.module5.MeasurableSort;
|
|
import com.hithomelabs.princeton1.module5.SortingMetaData;
|
|
|
|
import java.util.Comparator;
|
|
import java.util.List;
|
|
|
|
/*
|
|
* * A sorting bundle, that bundles one array and passes a copy of that array for all algorithms to sort
|
|
*/
|
|
public class Bundle<E> {
|
|
|
|
private Sortable<E> array;
|
|
private List<MeasurableSort<E>> algorithms;
|
|
private Comparator<E> cmp;
|
|
|
|
Bundle(Sortable<E> array, List<MeasurableSort<E>> algorithms){
|
|
this.array = array;
|
|
this.algorithms = algorithms;
|
|
}
|
|
|
|
Bundle (Sortable<E> array, List<MeasurableSort<E>> algorithms, Comparator<E> cmp){
|
|
this(array, algorithms);
|
|
if (cmp != null) this.cmp = cmp;
|
|
}
|
|
|
|
public void run(Comparator<E> cmp){
|
|
for (MeasurableSort<E> sortingAlgorithm: algorithms){
|
|
SortingMetaData metaData = new SortingMetaData();
|
|
sortingAlgorithm.sort(array.getArray(), cmp, metaData);
|
|
System.out.println("| " + array.getOrdering() + " | " + sortingAlgorithm + " | " + metaData.timeElapsed() + " | " + metaData.getCompares() + " | " + metaData.getExchanges() + " |" );
|
|
}
|
|
}
|
|
|
|
}
|