New Fixes

- Fixed: ObjectLists Crashed when a null was provided as a Comparator.
(Unless the List was Initialized with the ClassType)
- Fixed: LinkedLists didn't implement add(Object)
- Fixed: Object Collections did have the JavaCollections deprecated as
the Constructor. This should only be deprecated for Primitives
- Added: Tests with 5k Random names for Object sorting.
- Changed: Object Arrays no longer require a Comparable[] it just
assumes now that the elements in the Array are Comparable
This commit is contained in:
Speiger 2021-09-02 13:38:25 +02:00
parent aa1e7da38c
commit 117d0f36e6
16 changed files with 5204 additions and 57 deletions

View File

@ -4,6 +4,11 @@
### Version 0.3.5
- Fixed: Simple Code Generator dependency was declared wrong. Its only needed for runtime. Not for Compilation.
- Fixed: ObjectLists Crashed when a null was provided as a Comparator. (Unless the List was Initialized with the ClassType)
- Fixed: LinkedLists didn't implement add(Object)
- Fixed: Object Collections did have the JavaCollections deprecated as the Constructor. This should only be deprecated for Primitives
- Added: Tests with 5k Random names for Object sorting.
- Changed: Object Arrays no longer require a Comparable[] it just assumes now that the elements in the Array are Comparable
### Version 0.3.4
- Fixed: ArrayLists didn't resize properly if they were empty.

View File

@ -88,6 +88,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
* Creates a new ArrayList a copy with the contents of the Collection.
* @param c the elements that should be added into the list
*/
@Primitive
public ARRAY_LIST(Collection<? extends CLASS_TYPE> c) {
this(c.size());
size = ITERATORS.unwrap(data, c.iterator());
@ -444,7 +445,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
@Override
public void sort(Comparator<? super CLASS_TYPE> c) {
if(c != null) ARRAYS.stableSort(data, size, c);
else ARRAYS.stableSort((Comparable[])data, size);
else ARRAYS.stableSort(data, size);
}
/**
@ -455,7 +456,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
@Override
public void unstableSort(Comparator<? super CLASS_TYPE> c) {
if(c != null) ARRAYS.unstableSort(data, size, c);
else ARRAYS.unstableSort((Comparable[])data, size);
else ARRAYS.unstableSort(data, size);
}
#else

View File

@ -53,6 +53,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
* Creates a new Immutable copy of the contents of the Collection.
* @param c the elements that should be added into the list
*/
@Primitive
public IMMUTABLE_LIST(Collection<? extends CLASS_TYPE> c) {
data = ARRAYS.pour(ITERATORS.wrap(c.iterator()));
}

View File

@ -125,6 +125,12 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
for(int i = offset,m=offset+length;i<m;add(a[i++]));
}
@Override
public boolean add(KEY_TYPE e) {
add(size(), e);
return true;
}
@Override
public void add(int index, KEY_TYPE e) {
checkAddRange(index);

View File

@ -223,7 +223,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
public default void sort(Comparator<? super CLASS_TYPE> c) {
KEY_TYPE[] array = (KEY_TYPE[])TO_ARRAY();
if(c != null) ARRAYS.stableSort(array, c);
else ARRAYS.stableSort((Comparable[])array);
else ARRAYS.stableSort(array);
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator();
for (int i = 0,m=size();i<m && iter.hasNext();i++) {
iter.NEXT();
@ -239,7 +239,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
public default void unstableSort(Comparator<? super CLASS_TYPE> c) {
KEY_TYPE[] array = (KEY_TYPE[])TO_ARRAY();
if(c != null) ARRAYS.unstableSort(array, c);
else ARRAYS.unstableSort((Comparable[])array);
else ARRAYS.unstableSort(array);
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator();
for (int i = 0,m=size();i<m && iter.hasNext();i++) {
iter.NEXT();

View File

@ -115,7 +115,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
* @param collection the set the elements should be added to the TreeSet
*/
@Deprecated
@Primitive
public AVL_TREE_SET(Collection<? extends CLASS_TYPE> collection) {
addAll(collection);
}
@ -125,7 +125,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
* @param collection the set the elements should be added to the TreeSet
* @param comp the sorter of the tree, can be null
*/
@Deprecated
@Primitive
public AVL_TREE_SET(Collection<? extends CLASS_TYPE> collection, COMPARATOR KEY_GENERIC_TYPE comp) {
comparator = comp;
addAll(collection);

View File

@ -79,7 +79,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
* @param c the elements that should be added to the set.
* @note this slowly checks every element to remove duplicates
*/
@Deprecated
@Primitive
public ARRAY_SET(Collection<? extends CLASS_TYPE> c) {
this(c.size());
addAll(c);
@ -100,7 +100,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
* Since it is assumed that there is no duplication in the first place
* @param s the set the element should be taken from
*/
@Deprecated
@Primitive
public ARRAY_SET(Set<? extends CLASS_TYPE> s) {
this(s.size());
for(CLASS_TYPE e : s)

View File

@ -94,7 +94,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
* @param collection the set the elements should be added to the Set
*/
@Deprecated
@Primitive
public IMMUTABLE_HASH_SET(Collection<? extends CLASS_TYPE> collection) {
this(collection, HashUtil.DEFAULT_LOAD_FACTOR);
}
@ -105,7 +105,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
* @param loadFactor the percentage of how full the backing array can be before they resize
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
*/
@Deprecated
@Primitive
public IMMUTABLE_HASH_SET(Collection<? extends CLASS_TYPE> collection, float loadFactor) {
#if !TYPE_OBJECT
init(ARRAYS.unwrap(collection.toArray(NEW_CLASS_ARRAY(collection.size()))), 0, collection.size(), loadFactor);

View File

@ -132,7 +132,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
* @param strategy the strategy that allows hash control.
* @throws NullPointerException if Strategy is null
*/
@Deprecated
@Primitive
public LINKED_CUSTOM_HASH_SET(Collection<? extends CLASS_TYPE> collection, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
this(collection, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
}
@ -145,7 +145,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
* @throws NullPointerException if Strategy is null
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
*/
@Deprecated
@Primitive
public LINKED_CUSTOM_HASH_SET(Collection<? extends CLASS_TYPE> collection, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
this(collection.size(), loadFactor, strategy);
addAll(collection);

View File

@ -118,7 +118,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
* @param collection the set the elements should be added to the Set
*/
@Deprecated
@Primitive
public LINKED_HASH_SET(Collection<? extends CLASS_TYPE> collection) {
this(collection, HashUtil.DEFAULT_LOAD_FACTOR);
}
@ -129,7 +129,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
* @param loadFactor the percentage of how full the backing array can be before they resize
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
*/
@Deprecated
@Primitive
public LINKED_HASH_SET(Collection<? extends CLASS_TYPE> collection, float loadFactor) {
this(collection.size(), loadFactor);
addAll(collection);

View File

@ -147,7 +147,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
* @param strategy the strategy that allows hash control.
* @throws NullPointerException if Strategy is null
*/
@Deprecated
@Primitive
public CUSTOM_HASH_SET(Collection<? extends CLASS_TYPE> collection, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
this(collection, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
}
@ -160,7 +160,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
* @throws NullPointerException if Strategy is null
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
*/
@Deprecated
@Primitive
public CUSTOM_HASH_SET(Collection<? extends CLASS_TYPE> collection, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
this(collection.size(), loadFactor, strategy);
addAll(collection);
@ -272,7 +272,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
}
@Override
@Deprecated
@Primitive
public boolean addAll(Collection<? extends CLASS_TYPE> c) {
if(loadFactor <= 0.5F) ensureCapacity(c.size());
else ensureCapacity(c.size() + size());

View File

@ -128,7 +128,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
* @param collection the set the elements should be added to the Set
*/
@Deprecated
@Primitive
public HASH_SET(Collection<? extends CLASS_TYPE> collection) {
this(collection, HashUtil.DEFAULT_LOAD_FACTOR);
}
@ -139,7 +139,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
* @param loadFactor the percentage of how full the backing array can be before they resize
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
*/
@Deprecated
@Primitive
public HASH_SET(Collection<? extends CLASS_TYPE> collection, float loadFactor) {
this(collection.size(), loadFactor);
addAll(collection);
@ -231,7 +231,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
}
@Override
@Deprecated
@Primitive
public boolean addAll(Collection<? extends CLASS_TYPE> c) {
if(loadFactor <= 0.5F) ensureCapacity(c.size());
else ensureCapacity(c.size() + size());

View File

@ -115,7 +115,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
* @param collection the set the elements should be added to the TreeSet
*/
@Deprecated
@Primitive
public RB_TREE_SET(Collection<? extends CLASS_TYPE> collection) {
addAll(collection);
}
@ -125,7 +125,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
* @param collection the set the elements should be added to the TreeSet
* @param comp the sorter of the tree, can be null
*/
@Deprecated
@Primitive
public RB_TREE_SET(Collection<? extends CLASS_TYPE> collection, COMPARATOR KEY_GENERIC_TYPE comp) {
comparator = comp;
addAll(collection);

View File

@ -387,7 +387,7 @@ public class ARRAYS
* @param array the array that needs to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void stableSort(KEY_TYPE[] array) {
public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array) {
stableSort(array, 0, array.length);
}
@ -399,7 +399,7 @@ public class ARRAYS
* @param length the maxmium size of the array to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void stableSort(KEY_TYPE[] array, int length) {
public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array, int length) {
stableSort(array, 0, length);
}
@ -412,7 +412,7 @@ public class ARRAYS
* @param to where the array should be sorted to
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void stableSort(KEY_TYPE[] array, int from, int to) {
public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array, int from, int to) {
mergeSort(array, null, from, to);
}
@ -462,7 +462,7 @@ public class ARRAYS
* @param array the array that needs to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void unstableSort(KEY_TYPE[] array) {
public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array) {
unstableSort(array, 0, array.length);
}
@ -474,7 +474,7 @@ public class ARRAYS
* @param length the maxmium size of the array to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void unstableSort(KEY_TYPE[] array, int length) {
public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array, int length) {
unstableSort(array, 0, length);
}
@ -487,7 +487,7 @@ public class ARRAYS
* @param to where the array should be sorted to
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void unstableSort(KEY_TYPE[] array, int from, int to) {
public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array, int from, int to) {
quickSort(array, from, to);
}
@ -536,7 +536,7 @@ public class ARRAYS
* @param array the array that needs to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void insertionSort(KEY_TYPE[] array) {
public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array) {
insertionSort(array, 0, array.length);
}
@ -546,7 +546,7 @@ public class ARRAYS
* @param length the maxmium size of the array to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void insertionSort(KEY_TYPE[] array, int length) {
public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array, int length) {
insertionSort(array, 0, length);
}
@ -557,7 +557,7 @@ public class ARRAYS
* @param to where the array should be sorted to
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void insertionSort(KEY_TYPE[] array, int from, int to) {
public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array, int from, int to) {
for (int i = from+1;i<to; i++) {
KEY_TYPE current = array[i];
int j = i - 1;
@ -618,7 +618,7 @@ public class ARRAYS
* @param array the array that needs to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void selectionSort(KEY_TYPE[] array) {
public static GENERIC_KEY_BRACES void selectionSort(KEY_TYPE[] array) {
selectionSort(array, 0, array.length);
}
@ -628,7 +628,7 @@ public class ARRAYS
* @param length the maxmium size of the array to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void selectionSort(KEY_TYPE[] array, int length) {
public static GENERIC_KEY_BRACES void selectionSort(KEY_TYPE[] array, int length) {
selectionSort(array, 0, length);
}
@ -639,7 +639,7 @@ public class ARRAYS
* @param to where the array should be sorted to
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void selectionSort(KEY_TYPE[] array, int from, int to) {
public static GENERIC_KEY_BRACES void selectionSort(KEY_TYPE[] array, int from, int to) {
for (int i = from; i < to; i++) {
KEY_TYPE min = array[i];
int minId = i;
@ -714,7 +714,7 @@ public class ARRAYS
* @param array the array that needs to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void mergeSort(KEY_TYPE[] array) {
public static GENERIC_KEY_BRACES void mergeSort(KEY_TYPE[] array) {
mergeSort(array, null, 0, array.length);
}
@ -725,7 +725,7 @@ public class ARRAYS
* @param length the maxmium size of the array to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void mergeSort(KEY_TYPE[] array, int length) {
public static GENERIC_KEY_BRACES void mergeSort(KEY_TYPE[] array, int length) {
mergeSort(array, null, 0, length);
}
@ -738,7 +738,7 @@ public class ARRAYS
* @param to where the array should be sorted to
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void mergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) {
public static GENERIC_KEY_BRACES void mergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) {
if(to - from < BASE_THRESHOLD) {
insertionSort(array, from, to);
return;
@ -809,7 +809,7 @@ public class ARRAYS
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array) {
public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array) {
parallelMergeSort(array, null, 0, array.length);
}
@ -821,7 +821,7 @@ public class ARRAYS
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, int length) {
public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, int length) {
parallelMergeSort(array, null, 0, length);
}
@ -835,7 +835,7 @@ public class ARRAYS
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) {
public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) {
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
SanityChecks.invokeTask(new MergeSortActionBRACES(array, supp, from, to));
return;
@ -923,7 +923,7 @@ public class ARRAYS
* @param array the array that needs to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array) {
public static GENERIC_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array) {
memFreeMergeSort(array, 0, array.length);
}
@ -937,7 +937,7 @@ public class ARRAYS
* @param length the maxmium size of the array to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int length) {
public static GENERIC_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int length) {
memFreeMergeSort(array, 0, length);
}
@ -952,7 +952,7 @@ public class ARRAYS
* @param to where the array should be sorted to
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int from, int to) {
public static GENERIC_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int from, int to) {
if(to - from < BASE_THRESHOLD) {
insertionSort(array, from, to);
return;
@ -1053,7 +1053,7 @@ public class ARRAYS
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array) {
public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array) {
parallelMemFreeMergeSort(array, 0, array.length);
}
@ -1068,7 +1068,7 @@ public class ARRAYS
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length) {
public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length) {
parallelMemFreeMergeSort(array, 0, length);
}
@ -1084,7 +1084,7 @@ public class ARRAYS
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to) {
public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to) {
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
SanityChecks.invokeTask(new MemFreeMergeSortActionBRACES(array, from, to));
return;
@ -1158,7 +1158,7 @@ public class ARRAYS
* @param array the array that needs to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void quickSort(KEY_TYPE[] array) {
public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array) {
quickSort(array, 0, array.length);
}
@ -1170,7 +1170,7 @@ public class ARRAYS
* @param length the maxmium size of the array to be sorted
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void quickSort(KEY_TYPE[] array, int length) {
public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array, int length) {
quickSort(array, 0, length);
}
@ -1183,7 +1183,7 @@ public class ARRAYS
* @param to where the array should be sorted to
* @ArrayType(T)
*/
public static COMPAREABLE_KEY_BRACES void quickSort(KEY_TYPE[] array, int from, int to) {
public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array, int from, int to) {
int length = to - from;
if(length <= 0) return;
if(length < BASE_THRESHOLD) {
@ -1261,7 +1261,7 @@ public class ARRAYS
* @ArrayType(T)
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
*/
public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array) {
public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array) {
parallelQuickSort(array, 0, array.length);
}
@ -1274,7 +1274,7 @@ public class ARRAYS
* @ArrayType(T)
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
*/
public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int length) {
public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int length) {
parallelQuickSort(array, 0, length);
}
@ -1288,7 +1288,7 @@ public class ARRAYS
* @ArrayType(T)
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
*/
public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to) {
public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to) {
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
SanityChecks.invokeTask(new QuickSortActionBRACES(array, from, to));
return;
@ -1315,15 +1315,15 @@ public class ARRAYS
return comp.compare(data[a], data[b]) < 0 ? (comp.compare(data[b], data[c]) < 0 ? b : comp.compare(data[a], data[c]) < 0 ? c : a) : (comp.compare(data[b], data[c]) > 0 ? b : comp.compare(data[a], data[c]) > 0 ? c : a);
}
static COMPAREABLE_KEY_BRACES int subMedium(KEY_TYPE[] data, int a, int b, int c, int length) {
static GENERIC_KEY_BRACES int subMedium(KEY_TYPE[] data, int a, int b, int c, int length) {
return medium(data, medium(data, a, a + length, a + (length * 2)), medium(data, b - length, b, b + length), medium(data, c - (length * 2), c - length, c));
}
static COMPAREABLE_KEY_BRACES int medium(KEY_TYPE[] data, int a, int b, int c) {
static GENERIC_KEY_BRACES int medium(KEY_TYPE[] data, int a, int b, int c) {
return COMPAREABLE_TO_KEY(data[a], data[b]) < 0 ? (COMPAREABLE_TO_KEY(data[b], data[c]) < 0 ? b : COMPAREABLE_TO_KEY(data[a], data[c]) < 0 ? c : a) : (COMPAREABLE_TO_KEY(data[b], data[c]) > 0 ? b : COMPAREABLE_TO_KEY(data[a], data[c]) > 0 ? c : a);
}
static class QuickSortAction KEY_COMPAREABLE_TYPE extends RecursiveAction {
static class QuickSortAction KEY_GENERIC_TYPE extends RecursiveAction {
private static final long serialVersionUID = 0L;
KEY_TYPE[] array;
int from;
@ -1407,7 +1407,7 @@ public class ARRAYS
}
}
static class MergeSortAction KEY_COMPAREABLE_TYPE extends RecursiveAction {
static class MergeSortAction KEY_GENERIC_TYPE extends RecursiveAction {
private static final long serialVersionUID = 0L;
KEY_TYPE[] array;
KEY_TYPE[] supp;
@ -1483,7 +1483,7 @@ public class ARRAYS
}
}
static class MemFreeMergeSortAction KEY_COMPAREABLE_TYPE extends RecursiveAction {
static class MemFreeMergeSortAction KEY_GENERIC_TYPE extends RecursiveAction {
private static final long serialVersionUID = 0L;
KEY_TYPE[] array;
int from;

View File

@ -0,0 +1,134 @@
package speiger.src.collections.objects.utils;
import java.io.BufferedReader;
import java.io.File;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.collections.objects.lists.ObjectLinkedList;
import speiger.src.collections.objects.lists.ObjectList;
@SuppressWarnings("javadoc")
public class StringSortTest
{
public static final String[] NAMES = loadNames();
private static final String[] loadNames()
{
List<String> list = new ArrayList<>();
try(BufferedReader reader = Files.newBufferedReader(new File("src/test/resources/testAssets/strings/names.txt").toPath()))
{
reader.lines().forEach(list::add);
}
catch(Exception e)
{
e.printStackTrace();
}
list.sort(null);
return list.toArray(new String[list.size()]);
}
@Test
public void testArrayListSort() {
ObjectList<String> list = new ObjectArrayList<>(NAMES.clone());
ObjectLists.shuffle(list);
Assert.assertFalse(Arrays.equals(list.toArray(new String[list.size()]), NAMES));
list.sort(String::compareTo);
Assert.assertTrue(Arrays.equals(list.toArray(new String[list.size()]), NAMES));
ObjectLists.shuffle(list);
Assert.assertFalse(Arrays.equals(list.toArray(new String[list.size()]), NAMES));
list.sort(null);
Assert.assertTrue(Arrays.equals(list.toArray(new String[list.size()]), NAMES));
}
@Test
public void testLinkedListSort() {
ObjectList<String> list = new ObjectLinkedList<>(NAMES.clone());
ObjectLists.shuffle(list);
Assert.assertFalse(Arrays.equals(list.toArray(new String[list.size()]), NAMES));
list.sort(String::compareTo);
Assert.assertTrue(Arrays.equals(list.toArray(new String[list.size()]), NAMES));
ObjectLists.shuffle(list);
Assert.assertFalse(Arrays.equals(list.toArray(new String[list.size()]), NAMES));
list.sort(null);
Assert.assertTrue(Arrays.equals(list.toArray(new String[list.size()]), NAMES));
}
@Test
public void testInsertionSort() {
String[] array = ObjectArrays.shuffle(NAMES.clone());
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.insertionSort(array);
Assert.assertArrayEquals(NAMES, array);
ObjectArrays.shuffle(array);
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.insertionSort(array, String::compareTo);
Assert.assertArrayEquals(NAMES, array);
}
@Test
public void testMergeSort() {
String[] array = ObjectArrays.shuffle(NAMES.clone());
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.mergeSort(array);
Assert.assertArrayEquals(NAMES, array);
ObjectArrays.shuffle(array);
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.mergeSort(array, String::compareTo);
Assert.assertArrayEquals(NAMES, array);
}
@Test
public void testSelectionSortSort() {
String[] array = ObjectArrays.shuffle(NAMES.clone());
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.selectionSort(array);
Assert.assertArrayEquals(NAMES, array);
ObjectArrays.shuffle(array);
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.selectionSort(array, String::compareTo);
Assert.assertArrayEquals(NAMES, array);
}
@Test
public void testQuickSortSort() {
String[] array = ObjectArrays.shuffle(NAMES.clone());
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.quickSort(array);
Assert.assertArrayEquals(NAMES, array);
ObjectArrays.shuffle(array);
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.quickSort(array, String::compareTo);
Assert.assertArrayEquals(NAMES, array);
}
@Test
public void testParallelMergeSort() {
String[] array = ObjectArrays.shuffle(NAMES.clone());
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.parallelMergeSort(array);
Assert.assertArrayEquals(NAMES, array);
ObjectArrays.shuffle(array);
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.parallelMergeSort(array, String::compareTo);
Assert.assertArrayEquals(NAMES, array);
}
@Test
public void testParallelQuickSort() {
String[] array = ObjectArrays.shuffle(NAMES.clone());
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.parallelQuickSort(array);
Assert.assertArrayEquals(NAMES, array);
ObjectArrays.shuffle(array);
Assert.assertFalse(Arrays.equals(array, NAMES));
ObjectArrays.parallelQuickSort(array, String::compareTo);
Assert.assertArrayEquals(NAMES, array);
}
}

File diff suppressed because it is too large Load Diff