Added Reduce function to all implementations

This commit is contained in:
Speiger 2021-10-29 16:03:39 +02:00
parent c930bda7a6
commit a25ec85ba2
27 changed files with 1755 additions and 49 deletions

View File

@ -229,6 +229,7 @@ public class GlobalVariables
addClassMapper("STRATEGY", "Strategy");
addClassMapper("STACK", "Stack");
addClassMapper("SUPPLIER", "Supplier");
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
if(type.isObject())
{
@ -254,6 +255,7 @@ public class GlobalVariables
public GlobalVariables createFunctions()
{
addSimpleMapper("APPLY_KEY_VALUE", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
addSimpleMapper("APPLY_CAST", "applyAs"+type.getCustomJDKType().getNonFileType());
addSimpleMapper("APPLY", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());

View File

@ -6,6 +6,9 @@ import java.util.function.Consumer;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.collections.ObjectIterable;
#else
import java.util.function.BiFunction;
#endif
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
@ -172,6 +175,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
return EMPTY_VALUE;
}
#if !TYPE_OBJECT
/**
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
* elements of this Iterable
@ -188,9 +192,28 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
return state;
}
#else
/**
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
* elements of this Iterable
* @param operator the operation that should be applied
* @param identity the start value
* @Type(E)
* @return the reduction result, returns identity if nothing was found
*/
default <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
state = operator.APPLY_VALUE(state, iter.NEXT());
}
return state;
}
#endif
/**
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
* elements of this Iterable
* @param operator the operation that should be applied
* @return the reduction result, returns null value if nothing was found
*/
@ -207,7 +230,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
state = operator.APPLY_VALUE(state, iter.NEXT());
}
return state;
}
}
/**
* Helper function to reduce stream usage that allows to count the valid elements.

View File

@ -9,6 +9,7 @@ import java.util.Iterator;
import java.util.Objects;
#if TYPE_OBJECT
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
@ -651,6 +652,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return EMPTY_VALUE;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -661,6 +663,18 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(int i = 0;i<size;i++) {
state = operator.APPLY_VALUE(state, data[i]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);

View File

@ -7,6 +7,7 @@ import java.util.Comparator;
import java.util.Collection;
import java.util.Objects;
#if TYPE_OBJECT
import java.util.function.BiFunction;
import java.util.function.Consumer;
#endif
import java.util.function.Predicate;
@ -331,6 +332,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
return EMPTY_VALUE;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -341,6 +343,18 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(int i = 0,m=data.length;i<m;i++) {
state = operator.APPLY_VALUE(state, data[i]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);

View File

@ -2,6 +2,7 @@ package speiger.src.collections.PACKAGE.lists;
#if TYPE_OBJECT
import java.util.Comparator;
import java.util.function.BiFunction;
#else if PRIMITIVES
import java.nio.JAVA_BUFFER;
#endif
@ -455,6 +456,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return EMPTY_VALUE;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -465,6 +467,18 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
state = operator.APPLY_VALUE(state, entry.value);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);

View File

@ -49,7 +49,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
@Override
public MAP KEY_VALUE_GENERIC_TYPE copy() {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException();
}
#if !TYPE_OBJECT || !VALUE_OBJECT

View File

@ -5,6 +5,7 @@ import java.util.Comparator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.Objects;
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
@ -17,6 +18,7 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
@ -27,6 +29,9 @@ import speiger.src.collections.PACKAGE.utils.STRATEGY;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
#endif
#if !VALUE_OBJECT && !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
@ -47,6 +52,10 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif
#if !TYPE_OBJECT
#if !VALUE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.lists.ObjectListIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
@ -747,6 +756,37 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
return true;
}
@Override
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
Objects.requireNonNull(operator);
E state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
Objects.requireNonNull(operator);
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
empty = false;
state = new BasicEntryKV_BRACES(keys[index], values[index]);
index = (int)links[index];
continue;
}
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
@ -971,6 +1011,52 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_KEY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.apply(state, keys[index]);
index = (int)links[index];
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_KEY_VALUE;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
empty = false;
state = keys[index];
index = (int)links[index];
continue;
}
state = operator.APPLY_KEY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -1100,6 +1186,52 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
return true;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_VALUE(state, values[index]);
index = (int)links[index];
}
return state;
}
#else
@Override
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
VALUE_SPECIAL_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.apply(state, values[index]);
index = (int)links[index];
}
return state;
}
#endif
@Override
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = EMPTY_VALUE;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
empty = false;
state = values[index];
index = (int)links[index];
continue;
}
state = operator.APPLY_VALUE(state, values[index]);
index = (int)links[index];
}
return state;
}
@Override
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -6,6 +6,7 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.BiFunction;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.collections.ITERATOR;
@ -15,6 +16,9 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
@ -33,10 +37,17 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
#if !VALUE_OBJECT
#if !TYPE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
#endif
#else if !VALUE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
@ -874,6 +885,39 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return true;
}
@Override
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
Objects.requireNonNull(operator);
E state = identity;
if(containsNull) state = operator.apply(state, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
for(int i = nullIndex-1;i>=0;i--) {
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
Objects.requireNonNull(operator);
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
boolean empty = true;
if(containsNull) {
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
empty = false;
}
for(int i = 0;i<size;i++) {
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
if(empty) {
empty = false;
state = new BasicEntryKV_BRACES(keys[i], values[i]);
continue;
}
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
@ -1045,6 +1089,54 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
if(containsNull) state = operator.APPLY_KEY_VALUE(state, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
state = operator.APPLY_KEY_VALUE(state, keys[i]);
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
if(containsNull) state = operator.apply(state, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
state = operator.apply(state, keys[i]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_KEY_VALUE;
boolean empty = true;
if(containsNull) {
state = keys[nullIndex];
empty = false;
}
for(int i = 0;i<size;i++) {
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
if(empty) {
empty = false;
state = keys[i];
continue;
}
state = operator.APPLY_KEY_VALUE(state, keys[i]);
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -1153,6 +1245,54 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return true;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = identity;
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
state = operator.APPLY_VALUE(state, values[i]);
}
return state;
}
#else
@Override
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
VALUE_SPECIAL_TYPE state = identity;
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
state = operator.APPLY_VALUE(state, values[i]);
}
return state;
}
#endif
@Override
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = EMPTY_VALUE;
boolean empty = true;
if(containsNull) {
state = values[nullIndex];
empty = false;
}
for(int i = 0;i<size;i++) {
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
if(empty) {
empty = false;
state = values[i];
continue;
}
state = operator.APPLY_VALUE(state, values[i]);
}
return state;
}
@Override
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -5,6 +5,7 @@ import java.util.Comparator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.Objects;
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
@ -17,6 +18,7 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
@ -26,6 +28,9 @@ import speiger.src.collections.PACKAGE.sets.SET;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
#endif
#if !VALUE_OBJECT && !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
@ -46,6 +51,10 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif
#if !TYPE_OBJECT
#if !VALUE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.lists.ObjectListIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
@ -724,6 +733,37 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
return true;
}
@Override
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
Objects.requireNonNull(operator);
E state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
Objects.requireNonNull(operator);
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
empty = false;
state = new BasicEntryKV_BRACES(keys[index], values[index]);
index = (int)links[index];
continue;
}
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
@ -941,13 +981,59 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
Objects.requireNonNull(filter);
if(size() <= 0) return true;
int index = firstIndex;
while(index != -1){
while(index != -1) {
if(!filter.TEST_VALUE(keys[index])) return false;
index = (int)links[index];
}
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_KEY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.apply(state, keys[index]);
index = (int)links[index];
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_KEY_VALUE;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
empty = false;
state = keys[index];
index = (int)links[index];
continue;
}
state = operator.APPLY_KEY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -1059,7 +1145,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
Objects.requireNonNull(filter);
if(size() <= 0) return true;
int index = firstIndex;
while(index != -1){
while(index != -1) {
if(filter.VALUE_TEST_VALUE(values[index])) return false;
index = (int)links[index];
}
@ -1071,13 +1157,59 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
Objects.requireNonNull(filter);
if(size() <= 0) return true;
int index = firstIndex;
while(index != -1){
while(index != -1) {
if(!filter.VALUE_TEST_VALUE(values[index])) return false;
index = (int)links[index];
}
return true;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_VALUE(state, values[index]);
index = (int)links[index];
}
return state;
}
#else
@Override
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
VALUE_SPECIAL_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.apply(state, values[index]);
index = (int)links[index];
}
return state;
}
#endif
@Override
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = EMPTY_VALUE;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
empty = false;
state = values[index];
index = (int)links[index];
continue;
}
state = operator.APPLY_VALUE(state, values[index]);
index = (int)links[index];
}
return state;
}
@Override
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -6,6 +6,7 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.BiFunction;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.collections.ITERATOR;
@ -15,6 +16,9 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
@ -34,9 +38,15 @@ import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
#if !VALUE_OBJECT
#if !TYPE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
#endif
#else if !VALUE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
@ -50,6 +60,7 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
#if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif
import speiger.src.collections.objects.collections.ObjectIterator;
@ -834,6 +845,39 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return true;
}
@Override
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
Objects.requireNonNull(operator);
E state = identity;
if(containsNull) state = operator.apply(state, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NULL(keys[i])) continue;
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
Objects.requireNonNull(operator);
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
boolean empty = true;
if(containsNull) {
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
empty = false;
}
for(int i = 0;i<size;i++) {
if(KEY_EQUALS_NULL(keys[i])) continue;
if(empty) {
empty = false;
state = new BasicEntryKV_BRACES(keys[i], values[i]);
continue;
}
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
@ -1005,6 +1049,54 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
if(containsNull) state = operator.APPLY_KEY_VALUE(state, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NULL(keys[i])) continue;
state = operator.APPLY_KEY_VALUE(state, keys[i]);
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
if(containsNull) state = operator.apply(state, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NULL(keys[i])) continue;
state = operator.apply(state, keys[i]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_KEY_VALUE;
boolean empty = true;
if(containsNull) {
state = keys[nullIndex];
empty = false;
}
for(int i = 0;i<size;i++) {
if(KEY_EQUALS_NULL(keys[i])) continue;
if(empty) {
empty = false;
state = keys[i];
continue;
}
state = operator.APPLY_KEY_VALUE(state, keys[i]);
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -1113,6 +1205,54 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return true;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = identity;
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NULL(keys[i])) continue;
state = operator.APPLY_VALUE(state, values[i]);
}
return state;
}
#else
@Override
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
VALUE_SPECIAL_TYPE state = identity;
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NULL(keys[i])) continue;
state = operator.APPLY_VALUE(state, values[i]);
}
return state;
}
#endif
@Override
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = EMPTY_VALUE;
boolean empty = true;
if(containsNull) {
state = values[nullIndex];
empty = false;
}
for(int i = 0;i<size;i++) {
if(KEY_EQUALS_NULL(keys[i])) continue;
if(empty) {
empty = false;
state = values[i];
continue;
}
state = operator.APPLY_VALUE(state, values[i]);
}
return state;
}
@Override
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -6,6 +6,7 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.BiFunction;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
@ -19,6 +20,9 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
#endif
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
@ -61,6 +65,10 @@ import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_ARRAYS;
#endif
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
#if !TYPE_OBJECT
#if !VALUE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif
import speiger.src.collections.objects.lists.ObjectListIterator;
import speiger.src.collections.objects.sets.ObjectSortedSet;
#endif
@ -685,6 +693,37 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
return true;
}
@Override
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
Objects.requireNonNull(operator);
E state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
Objects.requireNonNull(operator);
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
empty = false;
state = new BasicEntryKV_BRACES(keys[index], values[index]);
index = (int)links[index];
continue;
}
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
@ -879,6 +918,52 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_KEY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.apply(state, keys[index]);
index = (int)links[index];
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_KEY_VALUE;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
empty = false;
state = keys[index];
index = (int)links[index];
continue;
}
state = operator.APPLY_KEY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -1006,6 +1091,52 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
return true;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_VALUE(state, values[index]);
index = (int)links[index];
}
return state;
}
#else
@Override
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
VALUE_SPECIAL_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.apply(state, values[index]);
index = (int)links[index];
}
return state;
}
#endif
@Override
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = EMPTY_VALUE;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
empty = false;
state = values[index];
index = (int)links[index];
continue;
}
state = operator.APPLY_VALUE(state, values[index]);
index = (int)links[index];
}
return state;
}
@Override
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -6,6 +6,7 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT
@ -19,6 +20,9 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
#endif
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
@ -57,6 +61,10 @@ import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
import speiger.src.collections.objects.collections.ObjectIterator;
#endif
#if !TYPE_OBJECT
#if !VALUE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.lists.ObjectListIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
@ -1210,6 +1218,32 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return true;
}
@Override
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
Objects.requireNonNull(operator);
E state = identity;
for(int i = 0;i<length;i++) {
state = operator.apply(state, new BasicEntryKV_BRACES(keys[offset+i], values[offset+i]));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
Objects.requireNonNull(operator);
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
boolean empty = true;
for(int i = 0;i<length;i++) {
if(empty) {
empty = false;
state = new BasicEntryKV_BRACES(keys[offset+i], values[offset+i]);
continue;
}
state = operator.apply(state, new BasicEntryKV_BRACES(keys[offset+i], values[offset+i]));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
@ -1379,6 +1413,45 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
for(int i = 0;i<length;i++) {
state = operator.APPLY_KEY_VALUE(state, keys[i+offset]);
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(int i = 0;i<length;i++) {
state = operator.apply(state, keys[i+offset]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_KEY_VALUE;
boolean empty = true;
for(int i = 0;i<length;i++) {
if(empty) {
empty = false;
state = keys[i+offset];
continue;
}
state = operator.APPLY_KEY_VALUE(state, keys[i+offset]);
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -1484,6 +1557,45 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return true;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = identity;
for(int i = 0;i<length;i++) {
state = operator.APPLY_VALUE(state, values[offset+i]);
}
return state;
}
#else
@Override
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
VALUE_SPECIAL_TYPE state = identity;
for(int i = 0;i<length;i++) {
state = operator.apply(state, values[offset+i]);
}
return state;
}
#endif
@Override
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = EMPTY_VALUE;
boolean empty = true;
for(int i = 0;i<length;i++) {
if(empty) {
empty = false;
state = values[offset+i];
continue;
}
state = operator.APPLY_VALUE(state, values[offset+i]);
}
return state;
}
@Override
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -1782,6 +1894,32 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return true;
}
@Override
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
Objects.requireNonNull(operator);
E state = identity;
for(int i = 0;i<size;i++) {
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
Objects.requireNonNull(operator);
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
boolean empty = true;
for(int i = 0;i<size;i++) {
if(empty) {
empty = false;
state = new BasicEntryKV_BRACES(keys[i], values[i]);
continue;
}
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
@ -1948,6 +2086,45 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
for(int i = 0;i<size;i++) {
state = operator.APPLY_KEY_VALUE(state, keys[i]);
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(int i = 0;i<size;i++) {
state = operator.apply(state, keys[i]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_KEY_VALUE;
boolean empty = true;
for(int i = 0;i<size;i++) {
if(empty) {
empty = false;
state = keys[i];
continue;
}
state = operator.APPLY_KEY_VALUE(state, keys[i]);
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -2044,6 +2221,45 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return true;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = identity;
for(int i = 0;i<size;i++) {
state = operator.APPLY_VALUE(state, values[i]);
}
return state;
}
#else
@Override
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
VALUE_SPECIAL_TYPE state = identity;
for(int i = 0;i<size;i++) {
state = operator.apply(state, values[i]);
}
return state;
}
#endif
@Override
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = EMPTY_VALUE;
boolean empty = true;
for(int i = 0;i<size;i++) {
if(empty) {
empty = false;
state = values[i];
continue;
}
state = operator.APPLY_VALUE(state, values[i]);
}
return state;
}
@Override
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -5,6 +5,7 @@ import java.util.Map;
import java.util.Comparator;
#endif
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.Objects;
import java.util.NoSuchElementException;
@ -20,6 +21,9 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
#endif
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
@ -65,6 +69,10 @@ import speiger.src.collections.objects.utils.ObjectIterators;
import speiger.src.collections.objects.collections.ObjectIterator;
#endif
#if !TYPE_OBJECT
#if !VALUE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
#endif
@ -1559,6 +1567,32 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return true;
}
@Override
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
Objects.requireNonNull(operator);
E state = identity;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
Objects.requireNonNull(operator);
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
boolean empty = true;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
if(empty) {
empty = false;
state = new BasicEntryKV_BRACES(entry.key, entry.value);
continue;
}
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
@ -1653,6 +1687,43 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return true;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = identity;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
state = operator.APPLY_VALUE(state, entry.value);
return state;
}
#else
@Override
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
VALUE_SPECIAL_TYPE state = identity;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
state = operator.apply(state, entry.value);
return state;
}
#endif
@Override
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = EMPTY_VALUE;
boolean empty = true;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
if(empty) {
empty = false;
state = entry.value;
continue;
}
state = operator.APPLY_VALUE(state, entry.value);
}
return state;
}
@Override
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -1893,6 +1964,32 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return true;
}
@Override
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
Objects.requireNonNull(operator);
E state = identity;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
Objects.requireNonNull(operator);
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
boolean empty = true;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
if(empty) {
empty = false;
state = new BasicEntryKV_BRACES(entry.key, entry.value);
continue;
}
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
@ -2077,6 +2174,43 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
state = operator.APPLY_KEY_VALUE(state, entry.key);
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
state = operator.apply(state, entry.key);
return state;
}
#endif
@Override
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_KEY_VALUE;
boolean empty = true;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry)) {
if(empty) {
empty = false;
state = entry.key;
continue;
}
state = operator.APPLY_KEY_VALUE(state, entry.key);
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -2164,6 +2298,43 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return true;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = identity;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
state = operator.APPLY_VALUE(state, entry.value);
return state;
}
#else
@Override
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
VALUE_SPECIAL_TYPE state = identity;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
state = operator.apply(state, entry.value);
return state;
}
#endif
@Override
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = EMPTY_VALUE;
boolean empty = true;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
if(empty) {
empty = false;
state = entry.value;
continue;
}
state = operator.APPLY_VALUE(state, entry.value);
}
return state;
}
@Override
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -7,6 +7,7 @@ import java.util.Comparator;
import java.util.Objects;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT
@ -20,6 +21,9 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !SAME_TYPE
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
#endif
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
@ -65,6 +69,10 @@ import speiger.src.collections.objects.utils.ObjectIterators;
import speiger.src.collections.objects.collections.ObjectIterator;
#endif
#if !TYPE_OBJECT
#if !VALUE_OBJECT
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
#endif
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
#endif
@ -1613,6 +1621,32 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return true;
}
@Override
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
Objects.requireNonNull(operator);
E state = identity;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
Objects.requireNonNull(operator);
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
boolean empty = true;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
if(empty) {
empty = false;
state = new BasicEntryKV_BRACES(entry.key, entry.value);
continue;
}
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
@ -1707,6 +1741,43 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return true;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = identity;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
state = operator.APPLY_VALUE(state, entry.value);
return state;
}
#else
@Override
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
VALUE_SPECIAL_TYPE state = identity;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
state = operator.apply(state, entry.value);
return state;
}
#endif
@Override
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = EMPTY_VALUE;
boolean empty = true;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
if(empty) {
empty = false;
state = entry.value;
continue;
}
state = operator.APPLY_VALUE(state, entry.value);
}
return state;
}
@Override
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -1947,6 +2018,32 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return true;
}
@Override
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
Objects.requireNonNull(operator);
E state = identity;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
Objects.requireNonNull(operator);
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
boolean empty = true;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
if(empty) {
empty = false;
state = new BasicEntryKV_BRACES(entry.key, entry.value);
continue;
}
state = operator.apply(state, new BasicEntryKV_BRACES(entry.key, entry.value));
}
return state;
}
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
@ -2144,6 +2241,43 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
state = operator.APPLY_KEY_VALUE(state, entry.key);
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
state = operator.apply(state, entry.key);
return state;
}
#endif
@Override
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_KEY_VALUE;
boolean empty = true;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry)) {
if(empty) {
empty = false;
state = entry.key;
continue;
}
state = operator.APPLY_KEY_VALUE(state, entry.key);
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -2231,6 +2365,43 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return true;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = identity;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
state = operator.APPLY_VALUE(state, entry.value);
return state;
}
#else
@Override
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
VALUE_SPECIAL_TYPE state = identity;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
state = operator.apply(state, entry.value);
return state;
}
#endif
@Override
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
VALUE_TYPE state = EMPTY_VALUE;
boolean empty = true;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
if(empty) {
empty = false;
state = entry.value;
continue;
}
state = operator.APPLY_VALUE(state, entry.value);
}
return state;
}
@Override
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
#if TYPE_OBJECT
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import java.util.Objects;
import java.util.NoSuchElementException;
@ -300,6 +301,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
return EMPTY_VALUE;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -310,6 +312,18 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(int i = 0,m=size();i<m;i++) {
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);

View File

@ -5,6 +5,7 @@ import java.util.NoSuchElementException;
#if TYPE_OBJECT
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import java.util.Objects;
@ -295,19 +296,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
return true;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.TEST_VALUE(array[i])) {
KEY_TYPE data = array[i];
removeIndex(i);
return data;
}
}
return EMPTY_VALUE;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -318,6 +307,18 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(int i = 0;i<size;i++) {
state = operator.APPLY_VALUE(state, array[i]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -334,6 +335,19 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.TEST_VALUE(array[i])) {
KEY_TYPE data = array[i];
removeIndex(i);
return data;
}
}
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -5,6 +5,7 @@ import java.util.NoSuchElementException;
#if TYPE_OBJECT
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import java.util.Objects;
@ -282,19 +283,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
return true;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.TEST_VALUE(array[i])) {
KEY_TYPE data = array[i];
removeIndex(i);
return data;
}
}
return EMPTY_VALUE;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -305,6 +294,18 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(int i = 0;i<size;i++) {
state = operator.APPLY_VALUE(state, array[i]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -321,6 +322,19 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.TEST_VALUE(array[i])) {
KEY_TYPE data = array[i];
removeIndex(i);
return data;
}
}
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -4,6 +4,7 @@ import java.util.Collection;
#if TYPE_OBJECT
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import java.util.Iterator;
import java.util.NoSuchElementException;
@ -347,6 +348,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return EMPTY_VALUE;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -357,6 +359,18 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
state = operator.APPLY_VALUE(state, entry.key);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -1096,6 +1110,45 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
state = operator.APPLY_VALUE(state, entry.key);
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
state = operator.APPLY_VALUE(state, entry.key);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_VALUE;
boolean empty = true;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
if(empty) {
empty = false;
state = entry.key;
continue;
}
state = operator.APPLY_VALUE(state, entry.key);
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -5,6 +5,7 @@ import java.util.Collection;
#if TYPE_OBJECT
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import java.util.NoSuchElementException;
import java.util.Objects;
@ -423,6 +424,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
return EMPTY_VALUE;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -433,6 +435,18 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(int i = 0;i<size;i++) {
state = operator.APPLY_VALUE(state, data[i]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);

View File

@ -3,6 +3,7 @@ package speiger.src.collections.PACKAGE.sets;
#if TYPE_OBJECT
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import java.util.Arrays;
import java.util.Collection;
@ -19,6 +20,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.utils.ARRAYS;
import speiger.src.collections.PACKAGE.utils.ITERATORS;
@ -346,6 +348,50 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_VALUE;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
state = keys[index];
empty = false;
}
else state = operator.APPLY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -3,6 +3,7 @@ package speiger.src.collections.PACKAGE.sets;
#if TYPE_OBJECT
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import java.util.Arrays;
import java.util.Objects;
@ -25,6 +26,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.utils.STRATEGY;
import speiger.src.collections.utils.HashUtil;
import speiger.src.collections.utils.SanityChecks;
@ -577,6 +579,50 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_VALUE;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
state = keys[index];
empty = false;
}
else state = operator.APPLY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -10,6 +10,7 @@ import java.util.NoSuchElementException;
import java.util.Objects;
#if TYPE_OBJECT
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION;
@ -23,6 +24,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.utils.ITERATORS;
@ -432,6 +434,50 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
int index = firstIndex;
while(index != -1) {
state = operator.APPLY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_VALUE;
boolean empty = true;
int index = firstIndex;
while(index != -1) {
if(empty) {
state = keys[index];
empty = false;
}
else state = operator.APPLY_VALUE(state, keys[index]);
index = (int)links[index];
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -8,6 +8,7 @@ import java.util.NoSuchElementException;
import java.util.Objects;
#if TYPE_OBJECT
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION;
@ -20,6 +21,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.utils.STRATEGY;
import speiger.src.collections.utils.HashUtil;
@ -527,6 +529,54 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
state = operator.APPLY_VALUE(state, keys[i]);
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
state = operator.APPLY_VALUE(state, keys[i]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_VALUE;
boolean empty = true;
if(containsNull) {
state = keys[nullIndex];
empty = false;
}
for(int i = 0;i<size;i++) {
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
if(empty) {
empty = false;
state = keys[i];
continue;
}
state = operator.APPLY_VALUE(state, keys[i]);
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -8,6 +8,7 @@ import java.util.NoSuchElementException;
import java.util.Objects;
#if TYPE_OBJECT
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION;
@ -20,6 +21,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.utils.HashUtil;
import speiger.src.collections.utils.ITrimmable;
import speiger.src.collections.utils.SanityChecks;
@ -380,6 +382,54 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NULL(keys[i])) continue;
state = operator.APPLY_VALUE(state, keys[i]);
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NULL(keys[i])) continue;
state = operator.APPLY_VALUE(state, keys[i]);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_VALUE;
boolean empty = true;
if(containsNull) {
state = keys[nullIndex];
empty = false;
}
for(int i = 0;i<size;i++) {
if(KEY_EQUALS_NULL(keys[i])) continue;
if(empty) {
empty = false;
state = keys[i];
continue;
}
state = operator.APPLY_VALUE(state, keys[i]);
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -4,6 +4,7 @@ import java.util.Collection;
#if TYPE_OBJECT
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.BiFunction;
#endif
import java.util.Iterator;
import java.util.NoSuchElementException;
@ -338,15 +339,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return true;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
if(filter.TEST_VALUE(entry.key)) return entry.key;
}
return EMPTY_VALUE;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -357,6 +350,18 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
state = operator.APPLY_VALUE(state, entry.key);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
@ -373,6 +378,15 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
if(filter.TEST_VALUE(entry.key)) return entry.key;
}
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
@ -1157,6 +1171,45 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return true;
}
#if !TYPE_OBJECT
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = identity;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
state = operator.APPLY_VALUE(state, entry.key);
}
return state;
}
#else
@Override
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
Objects.requireNonNull(operator);
KEY_SPECIAL_TYPE state = identity;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
state = operator.APPLY_VALUE(state, entry.key);
}
return state;
}
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
Objects.requireNonNull(operator);
KEY_TYPE state = EMPTY_VALUE;
boolean empty = true;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
if(empty) {
empty = false;
state = entry.key;
continue;
}
state = operator.APPLY_VALUE(state, entry.key);
}
return state;
}
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);

View File

@ -1,6 +1,9 @@
package speiger.src.collections.PACKAGE.utils;
import java.util.Collection;
#if TYPE_OBJECT
import java.util.function.BiFunction;
#endif
import java.util.function.Predicate;
#if PRIMITIVES
import java.util.function.JAVA_PREDICATE;
@ -194,13 +197,17 @@ public class COLLECTIONS
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesNone(filter); } }
@Override
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAll(filter); } }
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.findFirst(filter); } }
#if TYPE_OBJECT
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
#else
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(operator); } }
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.findFirst(filter); } }
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.count(filter); } }
}
@ -312,13 +319,17 @@ public class COLLECTIONS
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesNone(filter); }
@Override
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAll(filter); }
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); }
#if TYPE_OBJECT
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) { return c.reduce(identity, operator); }
#else
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(identity, operator); }
#endif
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(operator); }
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); }
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) { return c.count(filter); }
}

View File

@ -17,7 +17,6 @@ import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
/**
@ -132,10 +131,6 @@ public class PRIORITY_QUEUES
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.findFirst(filter); } }
@Override
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return queue.reduce(identity, operator); } }
@Override
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return queue.reduce(operator); } }
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.count(filter); } }
}