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:
+2
@@ -11,6 +11,7 @@ import java.util.function.Consumer;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
|
||||
/**
|
||||
* Abstract Type Specific Collection that reduces boxing/unboxing
|
||||
@@ -245,6 +246,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
*/
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY() {
|
||||
if(isEmpty()) return ARRAYS.EMPTY_ARRAY;
|
||||
return TO_ARRAY(new KEY_TYPE[size()]);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,11 +42,10 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.utils.Stack;
|
||||
#else
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#endif
|
||||
#if PRIMITIVES && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
@@ -1043,6 +1042,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
@Primitive
|
||||
public Object[] toArray() {
|
||||
if(size == 0) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size];
|
||||
for(int i = 0;i<size;i++)
|
||||
obj[i] = KEY_TO_OBJ(data[i]);
|
||||
|
||||
+2
-2
@@ -42,11 +42,10 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.utils.Stack;
|
||||
#else
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#endif
|
||||
#if PRIMITIVES && STREAM_FEATURE && SPLIT_ITERATOR_FEATURE
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
@@ -1291,6 +1290,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
public Object[] toArray() {
|
||||
KEY_TYPE[] data = this.data;
|
||||
int size = data.length;
|
||||
if(size == 0) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size];
|
||||
for(int i = 0;i<size;i++)
|
||||
obj[i] = KEY_TO_OBJ(data[i]);
|
||||
|
||||
+1
@@ -446,6 +446,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
@Override
|
||||
@Primitive
|
||||
public Object[] toArray() {
|
||||
if(data.length == 0) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[data.length];
|
||||
for(int i = 0,m=data.length;i<m;i++)
|
||||
obj[i] = KEY_TO_OBJ(data[i]);
|
||||
|
||||
+2
-2
@@ -54,10 +54,9 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.utils.Stack;
|
||||
#else
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
@@ -967,6 +966,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
#endif
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
if(size == 0) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size];
|
||||
int i = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
|
||||
@@ -551,6 +551,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object[] toArray() {
|
||||
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size()];
|
||||
for(int i = 0;i<size();i++)
|
||||
obj[i] = KEY_TO_OBJ(data[i]);
|
||||
|
||||
@@ -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