Changes:
- Added: RandomGenerator support (Java17), though requires self compilation - Added: Optimizations for HashUtils next power of function. - Added: toArray() now returns a cached empty array if the collection is empty. - Added: toArray function for AsyncBuilder - Updated: SCG to version 1.2.2
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
#if JAVA_VERSION>=17
|
||||
import java.util.random.RANDOM;
|
||||
#else
|
||||
import java.util.RANDOM;
|
||||
#endif
|
||||
import java.util.concurrent.RecursiveAction;
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
@@ -292,7 +296,7 @@ public class ARRAYS
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, Random random) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, RANDOM random) {
|
||||
for(int i = array.length-1; i>=0;i--) {
|
||||
int p = random.nextInt(i + 1);
|
||||
KEY_TYPE t = array[i];
|
||||
@@ -310,7 +314,7 @@ public class ARRAYS
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int length, Random random) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int length, RANDOM random) {
|
||||
return shuffle(array, 0, length, random);
|
||||
}
|
||||
|
||||
@@ -323,7 +327,7 @@ public class ARRAYS
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int offset, int length, Random random) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, int offset, int length, RANDOM random) {
|
||||
for(int i = length-1; i>=0;i--) {
|
||||
int p = offset + random.nextInt(i + 1);
|
||||
KEY_TYPE t = array[offset+i];
|
||||
|
||||
+67
@@ -12,6 +12,7 @@ import java.util.function.Consumer;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#else
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Comparator;
|
||||
|
||||
@@ -69,6 +70,7 @@ import speiger.src.collections.objects.utils.ObjectAsyncBuilder.BaseObjectTask;
|
||||
import speiger.src.collections.ints.utils.IntAsyncBuilder;
|
||||
import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
|
||||
#endif
|
||||
import speiger.src.collections.utils.ISizeProvider;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
@@ -292,6 +294,26 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
|
||||
#endif
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Pours all elements of the Iterable down into a Array.
|
||||
* @param action creates the final array that should be copied into.
|
||||
* @return a new Builder with the ToArray function applied
|
||||
*/
|
||||
public ObjectAsyncBuilder<KEY_TYPE[]> TO_ARRAY(IntFunction<KEY_TYPE[]> action) {
|
||||
return new ObjectAsyncBuilder<>(new ArrayTaskBRACES(iterable, action));
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Pours all elements of the Iterable down into a Array.
|
||||
* @return a new Builder with the ToArray function applied
|
||||
*/
|
||||
public ObjectAsyncBuilder<KEY_TYPE[]> TO_ARRAY() {
|
||||
return new ObjectAsyncBuilder<>(new ArrayTaskBRACES(iterable));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
/**
|
||||
* Pours all elements into a List that can be later
|
||||
@@ -729,6 +751,51 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
private static class ArrayTask KEY_GENERIC_TYPE extends BaseObjectTask<KEY_TYPE[]>
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE wrapper;
|
||||
#if TYPE_OBJECT
|
||||
IntFunction<KEY_TYPE[]> builder;
|
||||
|
||||
public ArrayTask(ITERABLE KEY_GENERIC_TYPE iterable, IntFunction<KEY_TYPE[]> builder) {
|
||||
this.builder = builder;
|
||||
#else
|
||||
|
||||
public ArrayTask(ITERABLE KEY_GENERIC_TYPE iterable) {
|
||||
#endif
|
||||
iter = iterable.iterator();
|
||||
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||
int size = prov == null ? -1 : prov.size();
|
||||
wrapper = size < 0 ? COLLECTIONS.wrapper() : COLLECTIONS.wrapper(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute() throws Exception {
|
||||
while(shouldRun() && iter.hasNext()) {
|
||||
wrapper.add(iter.NEXT());
|
||||
}
|
||||
if(!iter.hasNext()) {
|
||||
#if TYPE_OBJECT
|
||||
setResult(wrapper.TO_ARRAY(builder));
|
||||
#else
|
||||
setResult(wrapper.TO_ARRAY());
|
||||
#endif
|
||||
wrapper = null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCompletion() {
|
||||
super.onCompletion();
|
||||
iter = null;
|
||||
#if TYPE_OBJECT
|
||||
builder = null;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private static class ForEachTask<T> extends BaseObjectTask<Void>
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
|
||||
@@ -5,7 +5,11 @@ import java.util.List;
|
||||
#if IARRAY_FEATURE
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
import java.util.Random;
|
||||
#if JAVA_VERSION>=17
|
||||
import java.util.random.RANDOM;
|
||||
#else
|
||||
import java.util.RANDOM;
|
||||
#endif
|
||||
import java.util.RandomAccess;
|
||||
#if IARRAY_FEATURE || TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
@@ -157,7 +161,7 @@ public class LISTS
|
||||
* @Type(T)
|
||||
* @return the input list
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE shuffle(LIST KEY_GENERIC_TYPE list, Random random) {
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE shuffle(LIST KEY_GENERIC_TYPE list, RANDOM random) {
|
||||
int size = list.size();
|
||||
#if IARRAY_FEATURE
|
||||
if(list instanceof IARRAY) {
|
||||
|
||||
Reference in New Issue
Block a user