forked from Speiger/Primitive-Collections
More work.
-Added: BiFunction -Added: Function -Added: BiConsumer -Changed: Remapping Names to be more friendly for KEY_VALUE. -Added: A Bunch of Variables
This commit is contained in:
parent
a8318a3941
commit
42458bc4a3
Binary file not shown.
Binary file not shown.
|
@ -34,11 +34,21 @@ public enum ClassType
|
|||
return keyType;
|
||||
}
|
||||
|
||||
public String getValueType()
|
||||
{
|
||||
return this == OBJECT ? "V" : keyType;
|
||||
}
|
||||
|
||||
public String getClassType()
|
||||
{
|
||||
return classType;
|
||||
}
|
||||
|
||||
public String getClassValueType()
|
||||
{
|
||||
return this == OBJECT ? "V" : classType;
|
||||
}
|
||||
|
||||
public String getNonFileType()
|
||||
{
|
||||
return this == OBJECT ? "" : fileType;
|
||||
|
@ -49,6 +59,11 @@ public enum ClassType
|
|||
return fileType;
|
||||
}
|
||||
|
||||
public String getJavaFileType()
|
||||
{
|
||||
return this == OBJECT ? "Obj" : fileType;
|
||||
}
|
||||
|
||||
public String getPathType()
|
||||
{
|
||||
return pathType;
|
||||
|
@ -106,6 +121,43 @@ public enum ClassType
|
|||
}
|
||||
}
|
||||
|
||||
public boolean hasFunction(ClassType other)
|
||||
{
|
||||
if(this == other && this != BOOLEAN && !needsCustomJDKType() && !other.needsCustomJDKType()) return true;
|
||||
if(this == BOOLEAN) return false;
|
||||
if(other == BOOLEAN && !needsCustomJDKType()) return true;
|
||||
if(!needsCustomJDKType() && !other.needsCustomJDKType()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasBiFunction(ClassType other)
|
||||
{
|
||||
if(this == other && this != BOOLEAN && !needsCustomJDKType() && !other.needsCustomJDKType()) return true;
|
||||
if(this == BOOLEAN) return false;
|
||||
if(other == BOOLEAN && this == OBJECT) return true;
|
||||
if(!other.needsCustomJDKType() && this == OBJECT) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getFunctionClass(ClassType other)
|
||||
{
|
||||
if(!hasFunction(other)) return "";
|
||||
if(this == other && this != BOOLEAN) return this == OBJECT ? "java.util.function.Function" : "java.util.function."+getJavaFileType()+"UnaryOperator";
|
||||
if(other == BOOLEAN) return this == OBJECT ? "java.util.function.Predicate" : "java.util.function."+getJavaFileType()+"Predicate";
|
||||
if(!needsCustomJDKType()) return other == OBJECT ? "java.util.function."+getJavaFileType()+"Function" : (this == OBJECT ? "java.util.function.To"+other.getJavaFileType()+"Function" : "java.util.function."+getJavaFileType()+"To"+other.getJavaFileType()+"Function");
|
||||
if(!other.needsCustomJDKType()) return this == OBJECT ? "java.util.function.To"+other.getJavaFileType()+"Function" : "java.util.function."+getJavaFileType()+"To"+other.getJavaFileType()+"Function";
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getBiFunctionClass(ClassType other)
|
||||
{
|
||||
if(!hasBiFunction(other)) return "";
|
||||
if(this == other && this != BOOLEAN) return this == OBJECT ? "java.util.function.BiFunction" : "java.util.function."+getJavaFileType()+"BinaryOperator";
|
||||
if(other == BOOLEAN && this == OBJECT) return "java.util.function.BiPredicate";
|
||||
if(!other.needsCustomJDKType() && this == OBJECT) return "java.util.function.To"+other.getJavaFileType()+"BiFunction";
|
||||
return "";
|
||||
}
|
||||
|
||||
public ClassType getCustomJDKType()
|
||||
{
|
||||
switch(this)
|
||||
|
|
|
@ -19,24 +19,39 @@ public class GlobalVariables
|
|||
List<IMapper> operators = new ArrayList<>();
|
||||
Set<String> flags = new LinkedHashSet<>();
|
||||
ClassType type;
|
||||
ClassType valueType;
|
||||
|
||||
public GlobalVariables(ClassType type)
|
||||
public GlobalVariables(ClassType type, ClassType subType)
|
||||
{
|
||||
this.type = type;
|
||||
valueType = subType;
|
||||
}
|
||||
|
||||
public GlobalVariables createVariables()
|
||||
{
|
||||
addSimpleMapper("PACKAGE", type.getPathType());
|
||||
addSimpleMapper("CLASS_TYPE", type.getClassType());
|
||||
addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType());
|
||||
addSimpleMapper("KEY_TYPE", type.getKeyType());
|
||||
addSimpleMapper("EMPTY_VALUE", type.getEmptyValue());
|
||||
addSimpleMapper("VALUE_TYPE", valueType.getValueType());
|
||||
|
||||
addSimpleMapper("EMPTY_KEY_VALUE", type.getEmptyValue());
|
||||
addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue());
|
||||
|
||||
addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : "");
|
||||
addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : "");
|
||||
addSimpleMapper(" KEY_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" KEY_KEY_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+", "+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" NO_GENERIC_TYPE", type.isObject() ? "<?>" : "");
|
||||
addSimpleMapper(" KEY_COMPAREABLE_TYPE", type.isObject() ? "<"+type.getKeyType()+" extends Comparable<T>>" : "");
|
||||
addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", type.isObject() ? "<? super "+type.getKeyType()+">" : "");
|
||||
addSimpleMapper(" GENERIC_BRACES", type.isObject() ? " <"+type.getKeyType()+">" : "");
|
||||
addSimpleMapper(" COMPAREABLE_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable<T>>" : "");
|
||||
addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "<? super "+valueType.getKeyType()+">" : "");
|
||||
addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<? super "+type.getKeyType()+", ? super "+valueType.getValueType()+">" : "<? super "+type.getKeyType()+">") : (valueType.isObject() ? "<? super "+valueType.getValueType()+">" : ""));
|
||||
|
||||
addSimpleMapper(" GENERIC_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+">" : "");
|
||||
addSimpleMapper(" GENERIC_VALUE_BRACES", type.isObject() ? " <"+valueType.getValueType()+">" : "");
|
||||
addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+", "+valueType.getValueType()+">" : " <"+type.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" COMPAREABLE_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable<T>>" : "");
|
||||
addSimpleMapper("BRACES", type.isObject() ? "<>" : "");
|
||||
if(type.needsCustomJDKType())
|
||||
{
|
||||
|
@ -52,21 +67,33 @@ public class GlobalVariables
|
|||
public GlobalVariables createHelperVariables()
|
||||
{
|
||||
addArgumentMapper("EQUALS_KEY_TYPE", type.isObject() ? "Objects.equals(%2$s, %1$s)" : "Objects.equals(%2$s, KEY_TO_OBJ(%1$s))").removeBraces();
|
||||
addInjectMapper("EQUALS_NOT_NULL", type.getComparableValue()+" != "+(type.isPrimitiveBlocking() ? type.getEmptyValue() : (type.needsCast() ? type.getEmptyValue() : "0"))).removeBraces();
|
||||
addInjectMapper("EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() ? type.getEmptyValue() : (type.needsCast() ? type.getEmptyValue() : "0"))).removeBraces();
|
||||
addArgumentMapper("EQUALS_NOT", type.getEquals(true)).removeBraces();
|
||||
addArgumentMapper("EQUALS", type.getEquals(false)).removeBraces();
|
||||
addInjectMapper("KEY_EQUALS_NOT_NULL", type.getComparableValue()+" != "+(type.isPrimitiveBlocking() ? type.getEmptyValue() : (type.needsCast() ? type.getEmptyValue() : "0"))).removeBraces();
|
||||
addInjectMapper("KEY_EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() ? type.getEmptyValue() : (type.needsCast() ? type.getEmptyValue() : "0"))).removeBraces();
|
||||
addArgumentMapper("KEY_EQUALS_NOT", type.getEquals(true)).removeBraces();
|
||||
addArgumentMapper("KEY_EQUALS", type.getEquals(false)).removeBraces();
|
||||
|
||||
addArgumentMapper("COMPARE_TO_KEY", type.isObject() ? "((Comparable<T>)%1$s).compareTo((T)%2$s)" : type.getClassType()+".compare(%1$s, %2$s)").removeBraces();
|
||||
addArgumentMapper("COMPARE_TO", type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType()+".compare(%1$s, %2$s)").removeBraces();
|
||||
|
||||
addInjectMapper("KEY_TO_OBJ", type.isObject() ? "%s" : type.getClassType()+".valueOf(%s)").removeBraces();
|
||||
addInjectMapper("OBJ_TO_KEY", type.isObject() ? "%s" : "%s."+type.getKeyType()+"Value()").removeBraces();
|
||||
addInjectMapper("CLASS_TO_KEY", "(("+type.getClassType()+")%s)."+type.getKeyType()+"Value()").removeBraces();
|
||||
addSimpleMapper("APPLY", "applyAs"+type.getCustomJDKType().getNonFileType());
|
||||
addInjectMapper("TO_HASH", type.isObject() ? "%s.hashCode()" : type.getClassType()+".hashCode(%s)").removeBraces();
|
||||
|
||||
addInjectMapper("VALUE_TO_OBJ", valueType.isObject() ? "%s" : valueType.getClassType()+".valueOf(%s)").removeBraces();
|
||||
addInjectMapper("OBJ_TO_VALUE", valueType.isObject() ? "%s" : "%s."+valueType.getKeyType()+"Value()").removeBraces();
|
||||
addInjectMapper("CLASS_TO_VALUE", "(("+valueType.getClassType()+")%s)."+valueType.getKeyType()+"Value()").removeBraces();
|
||||
|
||||
addInjectMapper("KEY_TO_HASH", type.isObject() ? "%s.hashCode()" : type.getClassType()+".hashCode(%s)").removeBraces();
|
||||
|
||||
addSimpleMapper("CAST_KEY_ARRAY ", type.isObject() ? "(KEY_TYPE[])" : "");
|
||||
addSimpleMapper("EMPTY_KEY_ARRAY", type.isObject() ? "(KEY_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY");
|
||||
addInjectMapper("NEW_KEY_ARRAY", type.isObject() ? "(KEY_TYPE[])new Object[%s]" : "new KEY_TYPE[%s]").removeBraces();
|
||||
addInjectMapper("NEW_CLASS_ARRAY", type.isObject() ? "(CLASS_TYPE[])new Object[%s]" : "new CLASS_TYPE[%s]").removeBraces();
|
||||
|
||||
addSimpleMapper("CAST_VALUE_ARRAY ", valueType.isObject() ? "(VALUE_TYPE[])" : "");
|
||||
addSimpleMapper("EMPTY_VALUE_ARRAY", valueType.isObject() ? "(VALUE_TYPE[])VALUE_ARRAYS.EMPTY_ARRAY" : "VALUE_ARRAYS.EMPTY_ARRAY");
|
||||
addInjectMapper("NEW_VALUE_ARRAY", valueType.isObject() ? "(VALUE_TYPE[])new Object[%s]" : "new VALUE_TYPE[%s]").removeBraces();
|
||||
addInjectMapper("NEW_CLASS_VALUE_ARRAY", valueType.isObject() ? "(CLASS_VALUE_TYPE[])new Object[%s]" : "new CLASS_VALUE_TYPE[%s]").removeBraces();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -74,6 +101,8 @@ public class GlobalVariables
|
|||
{
|
||||
addSimpleMapper("JAVA_PREDICATE", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Predicate");
|
||||
addSimpleMapper("JAVA_CONSUMER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Consumer");
|
||||
addSimpleMapper("JAVA_FUNCTION", type.getFunctionClass(valueType));
|
||||
addSimpleMapper("JAVA_BI_FUNCTION", type.getBiFunctionClass(valueType));
|
||||
addSimpleMapper("UNARY_OPERATOR", type.isObject() ? "" : type == ClassType.BOOLEAN ? "BinaryOperator" : type.getCustomJDKType().getFileType()+"UnaryOperator");
|
||||
|
||||
//Final Classes
|
||||
|
@ -105,9 +134,12 @@ public class GlobalVariables
|
|||
//Interfaces
|
||||
addClassMapper("LIST_ITERATOR", "ListIterator");
|
||||
addClassMapper("BI_ITERATOR", "BidirectionalIterator");
|
||||
addBiClassMapper("BI_CONSUMER", "Consumer", "");
|
||||
addBiClassMapper("BI_FUNCTION", "BiFunction", "2");
|
||||
addClassMapper("ITERATOR", "Iterator");
|
||||
addClassMapper("ITERABLE", "Iterable");
|
||||
addClassMapper("COLLECTION", "Collection");
|
||||
addBiClassMapper("FUNCTION", "Function", "2");
|
||||
addClassMapper("LIST_ITER", "ListIter");
|
||||
addClassMapper("LIST", "List");
|
||||
addClassMapper("NAVIGABLE_SET", "NavigableSet");
|
||||
|
@ -134,9 +166,12 @@ public class GlobalVariables
|
|||
|
||||
public GlobalVariables createFunctions()
|
||||
{
|
||||
addSimpleMapper("APPLY_VALUE", "applyAs"+valueType.getCustomJDKType().getNonFileType());
|
||||
addSimpleMapper("APPLY", "applyAs"+type.getCustomJDKType().getNonFileType());
|
||||
addFunctionMapper("NEXT", "next");
|
||||
addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array");
|
||||
addFunctionMapper("GET_KEY", "get");
|
||||
addFunctionValueMapper("GET_VALUE", "get");
|
||||
addFunctionMapper("ENQUEUE_FIRST", "enqueueFirst");
|
||||
addFunctionMapper("ENQUEUE", "enqueue");
|
||||
addFunctionMapper("DEQUEUE_LAST", "dequeueLast");
|
||||
|
@ -161,14 +196,14 @@ public class GlobalVariables
|
|||
public GlobalVariables createFlags()
|
||||
{
|
||||
flags.add("TYPE_"+type.getCapType());
|
||||
if(!type.needsCustomJDKType())
|
||||
{
|
||||
flags.add("JDK_CONSUMER");
|
||||
}
|
||||
if(!type.isPrimitiveBlocking())
|
||||
{
|
||||
flags.add("PRIMITIVES");
|
||||
}
|
||||
flags.add("VALUE_"+valueType.getCapType());
|
||||
if(type == valueType) flags.add("SAME_TYPE");
|
||||
if(type.hasFunction(valueType)) flags.add("JDK_FUNCTION");
|
||||
if(type.hasBiFunction(valueType)) flags.add("JDK_BI_FUNCTION");
|
||||
if(!type.needsCustomJDKType()) flags.add("JDK_TYPE");
|
||||
if(!type.isPrimitiveBlocking()) flags.add("PRIMITIVES");
|
||||
if(valueType.isPrimitiveBlocking()) flags.add("VALUE_PRIMITIVES");
|
||||
if(valueType.needsCustomJDKType()) flags.add("JDK_VALUE");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -181,6 +216,15 @@ public class GlobalVariables
|
|||
return process;
|
||||
}
|
||||
|
||||
public TemplateProcess createBi(String fileName, String splitter)
|
||||
{
|
||||
TemplateProcess process = new TemplateProcess(String.format(fileName+".java", type.getFileType()+splitter+valueType.getFileType()));
|
||||
process.setPathBuilder(new PathBuilder(type.getPathType()));
|
||||
process.addFlags(flags);
|
||||
process.addMappers(operators);
|
||||
return process;
|
||||
}
|
||||
|
||||
public ClassType getType()
|
||||
{
|
||||
return type;
|
||||
|
@ -188,7 +232,14 @@ public class GlobalVariables
|
|||
|
||||
private void addClassMapper(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+replacement));
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+replacement));
|
||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, valueType.getFileType()+replacement));
|
||||
}
|
||||
|
||||
private void addBiClassMapper(String pattern, String replacement, String splitter)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+splitter+valueType.getFileType()+replacement));
|
||||
|
||||
}
|
||||
|
||||
private void addAbstractMapper(String pattern, String replacement)
|
||||
|
@ -201,6 +252,11 @@ public class GlobalVariables
|
|||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement+type.getNonFileType()));
|
||||
}
|
||||
|
||||
private void addFunctionValueMapper(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement+valueType.getNonFileType()));
|
||||
}
|
||||
|
||||
private void addFunctionMappers(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getNonFileType())));
|
||||
|
|
|
@ -17,8 +17,10 @@ public class TestBuilder extends TemplateProcessor
|
|||
{
|
||||
Map<String, EnumSet<ClassType>> blocked = new HashMap<String, EnumSet<ClassType>>();
|
||||
Map<String, String> nameRemapper = new HashMap<String, String>();
|
||||
Map<String, String> biRequired = new HashMap<String, String>();
|
||||
public static final ClassType[] TYPE = ClassType.values();
|
||||
List<GlobalVariables> varibles = new ArrayList<GlobalVariables>();
|
||||
List<GlobalVariables> variables = new ArrayList<GlobalVariables>();
|
||||
List<GlobalVariables> biVariables = new ArrayList<>();
|
||||
|
||||
public TestBuilder()
|
||||
{
|
||||
|
@ -46,17 +48,18 @@ public class TestBuilder extends TemplateProcessor
|
|||
@Override
|
||||
protected void init()
|
||||
{
|
||||
varibles.clear();
|
||||
variables.clear();
|
||||
for(ClassType clzType : TYPE)
|
||||
{
|
||||
GlobalVariables type = new GlobalVariables(clzType);
|
||||
type.createFlags();
|
||||
type.createHelperVariables();
|
||||
type.createVariables();
|
||||
type.createClassTypes();
|
||||
type.createFunctions();
|
||||
varibles.add(type);
|
||||
for(ClassType subType : TYPE)
|
||||
{
|
||||
create(clzType, subType);
|
||||
}
|
||||
}
|
||||
biRequired.put("BiConsumer", "");
|
||||
biRequired.put("Function", "2");
|
||||
biRequired.put("BiFunction", "2");
|
||||
nameRemapper.put("BiConsumer", "%sConsumer");
|
||||
nameRemapper.put("IArray", "I%sArray");
|
||||
nameRemapper.put("AbstractCollection", "Abstract%sCollection");
|
||||
nameRemapper.put("AbstractSet", "Abstract%sSet");
|
||||
|
@ -65,6 +68,18 @@ public class TestBuilder extends TemplateProcessor
|
|||
addBlockage(ClassType.BOOLEAN, "Sets", "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
|
||||
}
|
||||
|
||||
protected void create(ClassType mainType, ClassType subType)
|
||||
{
|
||||
GlobalVariables type = new GlobalVariables(mainType, subType);
|
||||
type.createFlags();
|
||||
type.createHelperVariables();
|
||||
type.createVariables();
|
||||
type.createClassTypes();
|
||||
type.createFunctions();
|
||||
if(mainType == subType) variables.add(type);
|
||||
biVariables.add(type);
|
||||
}
|
||||
|
||||
protected void addBlockage(ClassType type, String...args) {
|
||||
for(String s : args) {
|
||||
EnumSet<ClassType> set = blocked.get(s);
|
||||
|
@ -80,9 +95,22 @@ public class TestBuilder extends TemplateProcessor
|
|||
public void createProcesses(String name, Consumer<TemplateProcess> acceptor)
|
||||
{
|
||||
EnumSet<ClassType> types = blocked.get(name);
|
||||
for(int i = 0,m=varibles.size();i<m;i++)
|
||||
String splitter = biRequired.get(name);
|
||||
if(splitter != null)
|
||||
{
|
||||
GlobalVariables type = varibles.get(i);
|
||||
for(int i = 0,m=biVariables.size();i<m;i++)
|
||||
{
|
||||
GlobalVariables type = biVariables.get(i);
|
||||
if(types == null || !types.contains(type.getType()))
|
||||
{
|
||||
acceptor.accept(type.createBi(nameRemapper.getOrDefault(name, "%s"+name), splitter));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
for(int i = 0,m=variables.size();i<m;i++)
|
||||
{
|
||||
GlobalVariables type = variables.get(i);
|
||||
if(types == null || !types.contains(type.getType()))
|
||||
{
|
||||
acceptor.accept(type.create(nameRemapper.getOrDefault(name, "%s"+name)));
|
||||
|
|
|
@ -47,7 +47,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||
*/
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { if(EQUALS(iter.NEXT(), e)) return true; }
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { if(KEY_EQUALS(iter.NEXT(), e)) return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||
@Override
|
||||
public boolean REMOVE_KEY(KEY_TYPE e) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(EQUALS(iter.NEXT(), e)) {
|
||||
if(KEY_EQUALS(iter.NEXT(), e)) {
|
||||
iter.remove();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2,21 +2,13 @@ package speiger.src.collections.PACKAGE.functions;
|
|||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
#if !TYPE_BOOLEAN
|
||||
#if !JDK_CONSUMER
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Type-Specific Consumer interface that reduces (un)boxing and allows to merge other consumer types into this interface
|
||||
*/
|
||||
@FunctionalInterface
|
||||
#if JDK_TYPE && !TYPE_BOOLEAN
|
||||
public interface CONSUMER extends Consumer<CLASS_TYPE>, JAVA_CONSUMER
|
||||
#else
|
||||
|
||||
/**
|
||||
* Type-Specific Consumer interface that reduces (un)boxing and allows to merge other consumer types into this interface
|
||||
*/
|
||||
public interface CONSUMER extends Consumer<CLASS_TYPE>
|
||||
#endif
|
||||
{
|
||||
|
@ -28,16 +20,6 @@ public interface CONSUMER extends Consumer<CLASS_TYPE>
|
|||
*/
|
||||
void accept(KEY_TYPE t);
|
||||
|
||||
#if !JDK_CONSUMER
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void accept(JAVA_TYPE t) { accept(SanityChecks.SANITY_CAST(t)); }
|
||||
|
||||
#endif
|
||||
public default CONSUMER andThen(CONSUMER after) {
|
||||
Objects.requireNonNull(after);
|
||||
return T -> {accept(T); after.accept(T);};
|
||||
|
@ -61,8 +43,8 @@ public interface CONSUMER extends Consumer<CLASS_TYPE>
|
|||
Objects.requireNonNull(after);
|
||||
return T -> {accept(T); after.accept(KEY_TO_OBJ(T));};
|
||||
}
|
||||
#if JDK_TYPE && PRIMITIVES
|
||||
|
||||
#if PRIMITIVES
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package speiger.src.collections.PACKAGE.functions.consumer;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public interface BI_CONSUMER KEY_VALUE_GENERIC_TYPE extends BiConsumer<CLASS_TYPE, CLASS_VALUE_TYPE>
|
||||
{
|
||||
void accept(KEY_TYPE k, VALUE_TYPE v);
|
||||
|
||||
public default BI_CONSUMER KEY_VALUE_GENERIC_TYPE andThen(BI_CONSUMER KEY_VALUE_GENERIC_TYPE after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (K, V) -> {accept(K, V); after.accept(K, V);};
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void accept(CLASS_TYPE k, CLASS_VALUE_TYPE v) { accept(OBJ_TO_KEY(k), OBJ_TO_VALUE(v)); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default BI_CONSUMER KEY_VALUE_GENERIC_TYPE andThen(BiConsumer<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (K, V) -> {accept(K, V); after.accept(KEY_TO_OBJ(K), VALUE_TO_OBJ(V));};
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package speiger.src.collections.PACKAGE.functions.function;
|
||||
|
||||
@FunctionalInterface
|
||||
#if JDK_BI_FUNCTION
|
||||
public interface BI_FUNCTION KEY_VALUE_GENERIC_TYPE extends JAVA_BI_FUNCTION KEY_KEY_VALUE_GENERIC_TYPE
|
||||
#else
|
||||
public interface BI_FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE k, KEY_TYPE v);
|
||||
#if JDK_BI_FUNCTION
|
||||
#if VALUE_BOOLEAN
|
||||
|
||||
@Override
|
||||
public default VALUE_TYPE test(KEY_TYPE k, KEY_TYPE v) { return GET_VALUE(k, v); }
|
||||
#else if VALUE_OBJECT
|
||||
|
||||
@Override
|
||||
public default VALUE_TYPE apply(KEY_TYPE k, KEY_TYPE v) { return GET_VALUE(k, v); }
|
||||
#else
|
||||
|
||||
@Override
|
||||
public default VALUE_TYPE APPLY_VALUE(KEY_TYPE k, KEY_TYPE v) { return GET_VALUE(k, v); }
|
||||
#endif
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package speiger.src.collections.PACKAGE.functions.function;
|
||||
|
||||
#if JDK_FUNCTION && VALUE_BOOLEAN
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
|
||||
@FunctionalInterface
|
||||
#if JDK_FUNCTION
|
||||
public interface FUNCTION KEY_VALUE_GENERIC_TYPE extends JAVA_FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
#else
|
||||
public interface FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE k);
|
||||
#if JDK_FUNCTION
|
||||
#if VALUE_BOOLEAN
|
||||
|
||||
@Override
|
||||
public default VALUE_TYPE test(KEY_TYPE k) { return GET_VALUE(k); }
|
||||
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE andType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> GET_VALUE(T) && other.GET_VALUE(T);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE and(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> GET_VALUE(T) && other.test(T);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE negate() {
|
||||
return T -> !GET_VALUE(T);
|
||||
}
|
||||
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE orType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> GET_VALUE(T) || other.GET_VALUE(T);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE or(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> GET_VALUE(T) || other.test(T);
|
||||
}
|
||||
#else if VALUE_OBJECT
|
||||
|
||||
@Override
|
||||
public default VALUE_TYPE apply(KEY_TYPE k) { return GET_VALUE(k); }
|
||||
#else
|
||||
|
||||
@Override
|
||||
public default VALUE_TYPE APPLY_VALUE(KEY_TYPE k) { return GET_VALUE(k); }
|
||||
#endif
|
||||
#endif
|
||||
}
|
|
@ -125,7 +125,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||
public int indexOf(KEY_TYPE e) {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator();
|
||||
while(iter.hasNext()) {
|
||||
if(EQUALS(iter.NEXT(), e))
|
||||
if(KEY_EQUALS(iter.NEXT(), e))
|
||||
return iter.previousIndex();
|
||||
}
|
||||
return -1;
|
||||
|
@ -140,7 +140,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||
public int lastIndexOf(KEY_TYPE e) {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(size());
|
||||
while(iter.hasPrevious()) {
|
||||
if(EQUALS(iter.PREVIOUS(), e))
|
||||
if(KEY_EQUALS(iter.PREVIOUS(), e))
|
||||
return iter.nextIndex();
|
||||
}
|
||||
return -1;
|
||||
|
@ -164,7 +164,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||
LIST_ITERATOR e1 = listIterator();
|
||||
LIST_ITERATOR e2 = ((LIST)l).listIterator();
|
||||
while (e1.hasNext() && e2.hasNext()) {
|
||||
if(!(EQUALS(e1.NEXT(), e2.NEXT())))
|
||||
if(!(KEY_EQUALS(e1.NEXT(), e2.NEXT())))
|
||||
return false;
|
||||
}
|
||||
return !(e1.hasNext() || e2.hasNext());
|
||||
|
@ -190,7 +190,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||
#if TYPE_OBJECT
|
||||
hashCode = 31 * hashCode + i.next().hashCode();
|
||||
#else
|
||||
hashCode = 31 * hashCode + TO_HASH(i.NEXT());
|
||||
hashCode = 31 * hashCode + KEY_TO_HASH(i.NEXT());
|
||||
#endif
|
||||
return hashCode;
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||
|
||||
@Override
|
||||
public void size(int size) {
|
||||
while(size > size()) add(EMPTY_VALUE);
|
||||
while(size > size()) add(EMPTY_KEY_VALUE);
|
||||
while(size < size()) REMOVE(size() - 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -127,14 +127,14 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
/**
|
||||
* Creates a wrapped arraylist that uses the array as backing array
|
||||
*/
|
||||
public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
|
||||
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
|
||||
return wrap(a, a.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a wrapped arraylist that uses the array as backing array and a custom fillsize
|
||||
*/
|
||||
public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int length) {
|
||||
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int length) {
|
||||
SanityChecks.checkArrayCapacity(a.length, 0, length);
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
list.data = a;
|
||||
|
@ -146,7 +146,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
/**
|
||||
* Creates a new ArrayList with a EmptyObject array of the Type requested
|
||||
*/
|
||||
public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c) {
|
||||
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c) {
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
list.data = (KEY_TYPE[])ObjectArrays.newArray(c.getClass().getComponentType(), 0);
|
||||
return list;
|
||||
|
@ -453,7 +453,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
@Override
|
||||
public int indexOf(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(EQUALS(data[i], e)) return i;
|
||||
if(KEY_EQUALS(data[i], e)) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -466,7 +466,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
@Override
|
||||
public int lastIndexOf(KEY_TYPE e) {
|
||||
for(int i = size - 1;i>=0;i--) {
|
||||
if(EQUALS(data[i], e)) return i;
|
||||
if(KEY_EQUALS(data[i], e)) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -853,7 +853,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
if(size > data.length)
|
||||
data = Arrays.copyOf(data, size);
|
||||
else if(size < size() && size >= 0)
|
||||
Arrays.fill(data, size, size(), EMPTY_VALUE);
|
||||
Arrays.fill(data, size, size(), EMPTY_KEY_VALUE);
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,22 +65,22 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY
|
|||
comparator = comp;
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) {
|
||||
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) {
|
||||
return wrap(array, array.length);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) {
|
||||
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) {
|
||||
ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES();
|
||||
queue.array = array;
|
||||
queue.size = size;
|
||||
return queue;
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
return wrap(array, array.length, comp);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES(comp);
|
||||
queue.array = array;
|
||||
queue.size = size;
|
||||
|
@ -120,14 +120,14 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY
|
|||
@Override
|
||||
public boolean REMOVE(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
if(EQUALS(e, array[i])) return removeIndex(i);
|
||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean REMOVE_LAST(KEY_TYPE e) {
|
||||
for(int i = size-1;i>=0;i--)
|
||||
if(EQUALS(e, array[i])) return removeIndex(i);
|
||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY
|
|||
array[size] = null;
|
||||
#endif
|
||||
if(index == firstIndex) firstIndex = -1;
|
||||
else if(index >= firstIndex) firstIndex--;
|
||||
else if(firstIndex != -1 && index >= firstIndex) firstIndex--;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -190,13 +190,13 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY
|
|||
int index = size-1;
|
||||
KEY_TYPE value = array[index];
|
||||
if(comparator == null) {
|
||||
for(int i = index;firstIndex == -1 && i>=0;i--) {
|
||||
for(int i = index;i>=0;i--) {
|
||||
if(COMPARE_TO_KEY(array[i], value) < 0)
|
||||
value = array[index = i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(int i = index;firstIndex == -1 && i>=0;i--) {
|
||||
for(int i = index;i>=0;i--) {
|
||||
if(comparator.compare(array[i], value) < 0)
|
||||
value = array[index = i];
|
||||
}
|
||||
|
|
|
@ -68,11 +68,11 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_
|
|||
ARRAYS.heapify(array, size, comp);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) {
|
||||
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) {
|
||||
return wrap(array, array.length);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) {
|
||||
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) {
|
||||
HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES();
|
||||
queue.array = array;
|
||||
queue.size = size;
|
||||
|
@ -80,11 +80,11 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_
|
|||
return queue;
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
return wrap(array, array.length, comp);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES(comp);
|
||||
queue.array = array;
|
||||
queue.size = size;
|
||||
|
@ -138,14 +138,14 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_
|
|||
@Override
|
||||
public boolean REMOVE(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
if(EQUALS(e, array[i])) return removeIndex(i);
|
||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean REMOVE_LAST(KEY_TYPE e) {
|
||||
for(int i = size-1;i>=0;i--)
|
||||
if(EQUALS(e, array[i])) return removeIndex(i);
|
||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,11 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
|
|||
{
|
||||
public void ENQUEUE_FIRST(KEY_TYPE e);
|
||||
public KEY_TYPE DEQUEUE_LAST();
|
||||
public default KEY_TYPE LAST_KEY() { return PEEK(size()-1); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
public default void enqueueFirst(CLASS_TYPE e) { ENQUEUE_FIRST(OBJ_TO_KEY(e)); }
|
||||
public default CLASS_TYPE dequeueLast() { return KEY_TO_OBJ(DEQUEUE_LAST()); }
|
||||
public default CLASS_TYPE last() { return peek(size()-1); }
|
||||
#endif
|
||||
}
|
|
@ -24,8 +24,7 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue<CLA
|
|||
public KEY_TYPE DEQUEUE();
|
||||
|
||||
public KEY_TYPE PEEK(int index);
|
||||
public default KEY_TYPE FIRST_KEY() { return peek(0); }
|
||||
public default KEY_TYPE LAST_KEY() { return peek(size()-1); }
|
||||
public default KEY_TYPE FIRST_KEY() { return PEEK(0); }
|
||||
|
||||
public boolean REMOVE(KEY_TYPE e);
|
||||
public boolean REMOVE_LAST(KEY_TYPE e);
|
||||
|
@ -44,7 +43,6 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue<CLA
|
|||
|
||||
public default CLASS_TYPE peek(int index) { return KEY_TO_OBJ(PEEK(index)); }
|
||||
public default CLASS_TYPE first() { return peek(0); }
|
||||
public default CLASS_TYPE last() { return peek(size()-1); }
|
||||
|
||||
public default boolean remove(CLASS_TYPE e) { return REMOVE(OBJ_TO_KEY(e)); }
|
||||
public default boolean removeLast(CLASS_TYPE e) { return REMOVE_LAST(OBJ_TO_KEY(e)); }
|
||||
|
|
|
@ -361,17 +361,17 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) {
|
||||
return new AscendingSubSetBRACES(this, true, EMPTY_VALUE, true, false, toElement, inclusive);
|
||||
return new AscendingSubSetBRACES(this, true, EMPTY_KEY_VALUE, true, false, toElement, inclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) {
|
||||
return new AscendingSubSetBRACES(this, false, fromElement, inclusive, true, EMPTY_VALUE, true);
|
||||
return new AscendingSubSetBRACES(this, false, fromElement, inclusive, true, EMPTY_KEY_VALUE, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() {
|
||||
return new DescendingSubSetBRACES(this, true, EMPTY_VALUE, true, true, EMPTY_VALUE, true);
|
||||
return new DescendingSubSetBRACES(this, true, EMPTY_KEY_VALUE, true, true, EMPTY_KEY_VALUE, true);
|
||||
}
|
||||
|
||||
protected void removeNode(Entry KEY_GENERIC_TYPE entry) {
|
||||
|
|
|
@ -14,7 +14,7 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||
int hashCode = 1;
|
||||
ITERATOR KEY_GENERIC_TYPE i = iterator();
|
||||
while(i.hasNext())
|
||||
hashCode = 31 * hashCode + TO_HASH(i.NEXT());
|
||||
hashCode = 31 * hashCode + KEY_TO_HASH(i.NEXT());
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||
ITERATOR e1 = iterator();
|
||||
ITERATOR e2 = ((SET)l).iterator();
|
||||
while (e1.hasNext() && e2.hasNext()) {
|
||||
if(!(EQUALS(e1.NEXT(), e2.NEXT())))
|
||||
if(!(KEY_EQUALS(e1.NEXT(), e2.NEXT())))
|
||||
return false;
|
||||
}
|
||||
return !(e1.hasNext() || e2.hasNext());
|
||||
|
|
|
@ -164,7 +164,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||
size--;
|
||||
if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
||||
#if TYPE_OBJECT
|
||||
data[size] = EMPTY_VALUE;
|
||||
data[size] = EMPTY_KEY_VALUE;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||
size--;
|
||||
if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
||||
#if TYPE_OBJECT
|
||||
data[size] = EMPTY_VALUE;
|
||||
data[size] = EMPTY_KEY_VALUE;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||
KEY_TYPE result = data[0];
|
||||
System.arraycopy(data, 1, data, 0, size - 1);
|
||||
#if TYPE_OBJECT
|
||||
data[size-1] = EMPTY_VALUE;
|
||||
data[size-1] = EMPTY_KEY_VALUE;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||
size--;
|
||||
#if TYPE_OBJECT
|
||||
KEY_TYPE result = data[size];
|
||||
data[size] = EMPTY_VALUE;
|
||||
data[size] = EMPTY_KEY_VALUE;
|
||||
return result;
|
||||
#else
|
||||
return data[size];
|
||||
|
@ -214,7 +214,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||
#if !TYPE_OBJECT
|
||||
protected int findIndex(KEY_TYPE o) {
|
||||
for(int i = size-1;i>=0;i--)
|
||||
if(EQUALS(data[i], o)) return i;
|
||||
if(KEY_EQUALS(data[i], o)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -407,7 +407,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||
length--;
|
||||
if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
||||
#if TYPE_OBJECT
|
||||
data[size] = EMPTY_VALUE;
|
||||
data[size] = EMPTY_KEY_VALUE;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -422,7 +422,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||
KEY_TYPE result = data[offset];
|
||||
System.arraycopy(data, offset+1, data, offset, size-offset);
|
||||
#if TYPE_OBJECT
|
||||
data[size] = EMPTY_VALUE;
|
||||
data[size] = EMPTY_KEY_VALUE;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||
length--;
|
||||
System.arraycopy(data, end()+1, data, end(), size-end());
|
||||
#if TYPE_OBJECT
|
||||
data[size] = EMPTY_VALUE;
|
||||
data[size] = EMPTY_KEY_VALUE;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
@ -487,7 +487,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||
#if !TYPE_OBJECT
|
||||
protected int findIndex(KEY_TYPE o) {
|
||||
for(int i = length-1;i>=0;i--)
|
||||
if(EQUALS(data[offset+i], o)) return i + offset;
|
||||
if(KEY_EQUALS(data[offset+i], o)) return i + offset;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
#endif
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
if(strategy.equals(o, EMPTY_VALUE)) {
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
return false;
|
||||
|
@ -116,7 +116,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_VALUE)) {
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], o)) {
|
||||
moveToFirstIndex(pos);
|
||||
return false;
|
||||
|
@ -132,7 +132,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) {
|
||||
if(strategy.equals(o, EMPTY_VALUE)) {
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
return false;
|
||||
|
@ -142,7 +142,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_VALUE)) {
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], o)) {
|
||||
moveToLastIndex(pos);
|
||||
return false;
|
||||
|
@ -159,7 +159,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
if(strategy.equals(FIRST_KEY(), o)) return false;
|
||||
if(strategy.equals(o, EMPTY_VALUE)) {
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
return true;
|
||||
|
@ -167,7 +167,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_VALUE)) {
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], o)) {
|
||||
moveToFirstIndex(pos);
|
||||
return true;
|
||||
|
@ -182,7 +182,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
if(strategy.equals(LAST_KEY(), o)) return false;
|
||||
if(strategy.equals(o, EMPTY_VALUE)) {
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
return true;
|
||||
|
@ -190,7 +190,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_VALUE)) {
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], o)) {
|
||||
moveToLastIndex(pos);
|
||||
return true;
|
||||
|
@ -252,9 +252,9 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(strategy.equals(result, EMPTY_VALUE)) {
|
||||
if(strategy.equals(result, EMPTY_KEY_VALUE)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_VALUE;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
|
@ -275,9 +275,9 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL;
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(strategy.equals(result, EMPTY_VALUE)) {
|
||||
if(strategy.equals(result, EMPTY_KEY_VALUE)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_VALUE;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
|
@ -350,10 +350,10 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
long[] newLinks = new long[newSize + 1];
|
||||
int newPrev = -1;
|
||||
for(int j = size, i = firstIndex, pos = 0, prev = -1;j != 0;) {
|
||||
if(strategy.equals(keys[i], EMPTY_VALUE)) pos = newSize;
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) pos = newSize;
|
||||
else {
|
||||
pos = HashUtil.mix(strategy.hashCode(keys[i])) & newMask;
|
||||
while(!strategy.equals(newKeys[pos], EMPTY_VALUE)) pos = ++pos & newMask;
|
||||
while(!strategy.equals(newKeys[pos], EMPTY_KEY_VALUE)) pos = ++pos & newMask;
|
||||
}
|
||||
newKeys[pos] = keys[i];
|
||||
if(prev != -1) {
|
||||
|
@ -415,7 +415,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
}
|
||||
|
||||
SetIterator(KEY_TYPE from) {
|
||||
if(strategy.equals(from, EMPTY_VALUE)) {
|
||||
if(strategy.equals(from, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
previous = nullIndex;
|
||||
|
@ -428,7 +428,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(from)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_VALUE)) {
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], from)) {
|
||||
next = (int)links[pos];
|
||||
previous = pos;
|
||||
|
@ -481,7 +481,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
if(current == nullIndex) {
|
||||
current = -1;
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_VALUE;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
}
|
||||
else {
|
||||
int slot, last, startPos = current;
|
||||
|
@ -490,8 +490,8 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
while(true) {
|
||||
startPos = ((last = startPos) + 1) & mask;
|
||||
while(true){
|
||||
if(strategy.equals((current = keys[startPos]), EMPTY_VALUE)) {
|
||||
keys[last] = EMPTY_VALUE;
|
||||
if(strategy.equals((current = keys[startPos]), EMPTY_KEY_VALUE)) {
|
||||
keys[last] = EMPTY_KEY_VALUE;
|
||||
return;
|
||||
}
|
||||
slot = HashUtil.mix(strategy.hashCode(current)) & mask;
|
||||
|
|
|
@ -108,7 +108,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
#endif
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
if(EQUALS_NULL(o)) {
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
return false;
|
||||
|
@ -117,9 +117,9 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
onNodeAdded(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(TO_HASH(o)) & mask;
|
||||
while(EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(EQUALS(keys[pos], o)) {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], o)) {
|
||||
moveToFirstIndex(pos);
|
||||
return false;
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) {
|
||||
if(EQUALS_NULL(o)) {
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
return false;
|
||||
|
@ -143,9 +143,9 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
onNodeAdded(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(TO_HASH(o)) & mask;
|
||||
while(EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(EQUALS(keys[pos], o)) {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], o)) {
|
||||
moveToLastIndex(pos);
|
||||
return false;
|
||||
}
|
||||
|
@ -160,17 +160,17 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
if(EQUALS(FIRST_KEY(), o)) return false;
|
||||
if(EQUALS_NULL(o)) {
|
||||
if(KEY_EQUALS(FIRST_KEY(), o)) return false;
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(TO_HASH(o)) & mask;
|
||||
while(EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(EQUALS(keys[pos], o)) {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], o)) {
|
||||
moveToFirstIndex(pos);
|
||||
return true;
|
||||
}
|
||||
|
@ -183,17 +183,17 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
if(EQUALS(LAST_KEY(), o)) return false;
|
||||
if(EQUALS_NULL(o)) {
|
||||
if(KEY_EQUALS(LAST_KEY(), o)) return false;
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(TO_HASH(o)) & mask;
|
||||
while(EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(EQUALS(keys[pos], o)) {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], o)) {
|
||||
moveToLastIndex(pos);
|
||||
return true;
|
||||
}
|
||||
|
@ -254,9 +254,9 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(EQUALS_NULL(result)) {
|
||||
if(KEY_EQUALS_NULL(result)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_VALUE;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
|
@ -277,9 +277,9 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL;
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(EQUALS_NULL(result)) {
|
||||
if(KEY_EQUALS_NULL(result)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_VALUE;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
|
@ -352,10 +352,10 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
long[] newLinks = new long[newSize + 1];
|
||||
int newPrev = -1;
|
||||
for(int j = size, i = firstIndex, pos = 0, prev = -1;j != 0;) {
|
||||
if(EQUALS_NULL(keys[i])) pos = newSize;
|
||||
if(KEY_EQUALS_NULL(keys[i])) pos = newSize;
|
||||
else {
|
||||
pos = HashUtil.mix(TO_HASH(keys[i])) & newMask;
|
||||
while(EQUALS_NOT_NULL(newKeys[pos])) pos = ++pos & newMask;
|
||||
pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask;
|
||||
while(KEY_EQUALS_NOT_NULL(newKeys[pos])) pos = ++pos & newMask;
|
||||
}
|
||||
newKeys[pos] = keys[i];
|
||||
if(prev != -1) {
|
||||
|
@ -417,21 +417,21 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
}
|
||||
|
||||
SetIterator(KEY_TYPE from) {
|
||||
if(EQUALS_NULL(from)) {
|
||||
if(KEY_EQUALS_NULL(from)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
previous = nullIndex;
|
||||
}
|
||||
else throw new NoSuchElementException("The null element is not in the set");
|
||||
}
|
||||
else if(EQUALS(keys[lastIndex], from)) {
|
||||
else if(KEY_EQUALS(keys[lastIndex], from)) {
|
||||
previous = lastIndex;
|
||||
index = size;
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(TO_HASH(from)) & mask;
|
||||
while(EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(EQUALS(keys[pos], from)) {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(from)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], from)) {
|
||||
next = (int)links[pos];
|
||||
previous = pos;
|
||||
break;
|
||||
|
@ -483,7 +483,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
if(current == nullIndex) {
|
||||
current = -1;
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_VALUE;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
}
|
||||
else {
|
||||
int slot, last, startPos = current;
|
||||
|
@ -492,11 +492,11 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
while(true) {
|
||||
startPos = ((last = startPos) + 1) & mask;
|
||||
while(true){
|
||||
if(EQUALS_NULL((current = keys[startPos]))) {
|
||||
keys[last] = EMPTY_VALUE;
|
||||
if(KEY_EQUALS_NULL((current = keys[startPos]))) {
|
||||
keys[last] = EMPTY_KEY_VALUE;
|
||||
return;
|
||||
}
|
||||
slot = HashUtil.mix(TO_HASH(current)) & mask;
|
||||
slot = HashUtil.mix(KEY_TO_HASH(current)) & mask;
|
||||
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
||||
startPos = ++startPos & mask;
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
if(strategy.equals(o, EMPTY_VALUE)) {
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) return false;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
|
@ -126,9 +126,9 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(!strategy.equals(current, EMPTY_VALUE)) {
|
||||
if(!strategy.equals(current, EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(current, o)) return false;
|
||||
while(!strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_VALUE))
|
||||
while(!strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE))
|
||||
if(strategy.equals(current, o)) return false;
|
||||
}
|
||||
keys[pos] = o;
|
||||
|
@ -156,26 +156,26 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
if(strategy.equals((KEY_TYPE)o, EMPTY_VALUE)) return containsNull;
|
||||
if(strategy.equals((KEY_TYPE)o, EMPTY_KEY_VALUE)) return containsNull;
|
||||
int pos = HashUtil.mix(strategy.hashCode((KEY_TYPE)o)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(strategy.equals(current, EMPTY_VALUE)) return false;
|
||||
if(strategy.equals(current, EMPTY_KEY_VALUE)) return false;
|
||||
if(strategy.equals(current, (KEY_TYPE)o)) return true;
|
||||
while(true) {
|
||||
if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_VALUE)) return false;
|
||||
if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE)) return false;
|
||||
else if(strategy.equals(current, (KEY_TYPE)o)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
if(strategy.equals((KEY_TYPE)o, EMPTY_VALUE)) return (containsNull ? removeNullIndex() : false);
|
||||
if(strategy.equals((KEY_TYPE)o, EMPTY_KEY_VALUE)) return (containsNull ? removeNullIndex() : false);
|
||||
int pos = HashUtil.mix(strategy.hashCode((KEY_TYPE)o)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(strategy.equals(current, EMPTY_VALUE)) return false;
|
||||
if(strategy.equals(current, EMPTY_KEY_VALUE)) return false;
|
||||
if(strategy.equals(current, (KEY_TYPE)o)) return removeIndex(pos);
|
||||
while(true) {
|
||||
if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_VALUE)) return false;
|
||||
if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE)) return false;
|
||||
else if(strategy.equals(current, (KEY_TYPE)o)) return removeIndex(pos);
|
||||
}
|
||||
}
|
||||
|
@ -183,26 +183,26 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||
#else
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE o) {
|
||||
if(strategy.equals(o, EMPTY_VALUE)) return containsNull;
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) return containsNull;
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(strategy.equals(current, EMPTY_VALUE)) return false;
|
||||
if(strategy.equals(current, EMPTY_KEY_VALUE)) return false;
|
||||
if(strategy.equals(current, o)) return true;
|
||||
while(true) {
|
||||
if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_VALUE)) return false;
|
||||
if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE)) return false;
|
||||
else if(strategy.equals(current, o)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
if(strategy.equals(o, EMPTY_VALUE)) return (containsNull ? removeNullIndex() : false);
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) return (containsNull ? removeNullIndex() : false);
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(strategy.equals(current, EMPTY_VALUE)) return false;
|
||||
if(strategy.equals(current, EMPTY_KEY_VALUE)) return false;
|
||||
if(strategy.equals(current, o)) return removeIndex(pos);
|
||||
while(true) {
|
||||
if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_VALUE)) return false;
|
||||
if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE)) return false;
|
||||
else if(strategy.equals(current, o)) return removeIndex(pos);
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||
|
||||
protected boolean removeNullIndex() {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_VALUE;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
size--;
|
||||
onNodeRemoved(nullIndex);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
|
@ -259,8 +259,8 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||
while(true) {
|
||||
startPos = ((last = startPos) + 1) & mask;
|
||||
while(true){
|
||||
if(strategy.equals((current = keys[startPos]), EMPTY_VALUE)) {
|
||||
keys[last] = EMPTY_VALUE;
|
||||
if(strategy.equals((current = keys[startPos]), EMPTY_KEY_VALUE)) {
|
||||
keys[last] = EMPTY_KEY_VALUE;
|
||||
return;
|
||||
}
|
||||
slot = HashUtil.mix(strategy.hashCode(current)) & mask;
|
||||
|
@ -276,9 +276,9 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||
int newMask = newSize - 1;
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
|
||||
while(strategy.equals(keys[--i], EMPTY_VALUE));
|
||||
if(!strategy.equals(newKeys[pos = HashUtil.mix(TO_HASH(keys[i])) & newMask], EMPTY_VALUE))
|
||||
while(!strategy.equals(newKeys[pos = (++pos & newMask)], EMPTY_VALUE));
|
||||
while(strategy.equals(keys[--i], EMPTY_KEY_VALUE));
|
||||
if(!strategy.equals(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask], EMPTY_KEY_VALUE))
|
||||
while(!strategy.equals(newKeys[pos = (++pos & newMask)], EMPTY_KEY_VALUE));
|
||||
newKeys[pos] = keys[i];
|
||||
}
|
||||
nullIndex = newSize;
|
||||
|
@ -297,7 +297,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||
if(size == 0) return;
|
||||
size = 0;
|
||||
containsNull = false;
|
||||
Arrays.fill(keys, EMPTY_VALUE);
|
||||
Arrays.fill(keys, EMPTY_KEY_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -326,7 +326,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||
nextIndex = -pos - 1;
|
||||
break;
|
||||
}
|
||||
if(EQUALS_NOT_NULL(keys[pos])){
|
||||
if(KEY_EQUALS_NOT_NULL(keys[pos])){
|
||||
nextIndex = pos;
|
||||
break;
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
if(lastReturned == nullIndex) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_VALUE;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
}
|
||||
else if(pos >= 0) shiftKeys(pos);
|
||||
else {
|
||||
|
@ -372,8 +372,8 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||
while(true) {
|
||||
startPos = ((last = startPos) + 1) & mask;
|
||||
while(true){
|
||||
if(strategy.equals((current = keys[startPos]), EMPTY_VALUE)) {
|
||||
keys[last] = EMPTY_VALUE;
|
||||
if(strategy.equals((current = keys[startPos]), EMPTY_KEY_VALUE)) {
|
||||
keys[last] = EMPTY_KEY_VALUE;
|
||||
return;
|
||||
}
|
||||
slot = HashUtil.mix(strategy.hashCode(current)) & mask;
|
||||
|
|
|
@ -111,18 +111,18 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
if(EQUALS_NULL(o)) {
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) return false;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(TO_HASH(o)) & mask;
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(EQUALS_NOT_NULL(current)) {
|
||||
if(EQUALS(current, o)) return false;
|
||||
while(EQUALS_NOT_NULL((current = keys[pos = (++pos & mask)])))
|
||||
if(EQUALS(current, o)) return false;
|
||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||
if(KEY_EQUALS(current, o)) return false;
|
||||
while(KEY_EQUALS_NOT_NULL((current = keys[pos = (++pos & mask)])))
|
||||
if(KEY_EQUALS(current, o)) return false;
|
||||
}
|
||||
keys[pos] = o;
|
||||
onNodeAdded(pos);
|
||||
|
@ -151,10 +151,10 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||
if(o == null) return containsNull;
|
||||
int pos = HashUtil.mix(o.hashCode()) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(EQUALS_NULL(current)) return false;
|
||||
if(KEY_EQUALS_NULL(current)) return false;
|
||||
if(EQUALS_KEY_TYPE(current, o)) return true;
|
||||
while(true) {
|
||||
if(EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
else if(EQUALS_KEY_TYPE(current, o)) return true;
|
||||
}
|
||||
}
|
||||
|
@ -164,10 +164,10 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||
if(o == null) return (containsNull ? removeNullIndex() : false);
|
||||
int pos = HashUtil.mix(o.hashCode()) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(EQUALS_NULL(current)) return false;
|
||||
if(KEY_EQUALS_NULL(current)) return false;
|
||||
if(EQUALS_KEY_TYPE(current, o)) return removeIndex(pos);
|
||||
while(true) {
|
||||
if(EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
else if(EQUALS_KEY_TYPE(current, o)) return removeIndex(pos);
|
||||
}
|
||||
}
|
||||
|
@ -175,27 +175,27 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE o) {
|
||||
if(EQUALS_NULL(o)) return containsNull;
|
||||
int pos = HashUtil.mix(TO_HASH(o)) & mask;
|
||||
if(KEY_EQUALS_NULL(o)) return containsNull;
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(EQUALS_NULL(current)) return false;
|
||||
if(EQUALS(current, o)) return true;
|
||||
if(KEY_EQUALS_NULL(current)) return false;
|
||||
if(KEY_EQUALS(current, o)) return true;
|
||||
while(true) {
|
||||
if(EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
else if(EQUALS(current, o)) return true;
|
||||
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
else if(KEY_EQUALS(current, o)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
if(EQUALS_NULL(o)) return (containsNull ? removeNullIndex() : false);
|
||||
int pos = HashUtil.mix(TO_HASH(o)) & mask;
|
||||
if(KEY_EQUALS_NULL(o)) return (containsNull ? removeNullIndex() : false);
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(EQUALS_NULL(current)) return false;
|
||||
if(EQUALS(current, o)) return removeIndex(pos);
|
||||
if(KEY_EQUALS_NULL(current)) return false;
|
||||
if(KEY_EQUALS(current, o)) return removeIndex(pos);
|
||||
while(true) {
|
||||
if(EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
else if(EQUALS(current, o)) return removeIndex(pos);
|
||||
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
||||
else if(KEY_EQUALS(current, o)) return removeIndex(pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||
|
||||
protected boolean removeNullIndex() {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_VALUE;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
size--;
|
||||
onNodeRemoved(nullIndex);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
|
@ -251,11 +251,11 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||
while(true) {
|
||||
startPos = ((last = startPos) + 1) & mask;
|
||||
while(true){
|
||||
if(EQUALS_NULL((current = keys[startPos]))) {
|
||||
keys[last] = EMPTY_VALUE;
|
||||
if(KEY_EQUALS_NULL((current = keys[startPos]))) {
|
||||
keys[last] = EMPTY_KEY_VALUE;
|
||||
return;
|
||||
}
|
||||
slot = HashUtil.mix(TO_HASH(current)) & mask;
|
||||
slot = HashUtil.mix(KEY_TO_HASH(current)) & mask;
|
||||
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
||||
startPos = ++startPos & mask;
|
||||
}
|
||||
|
@ -268,9 +268,9 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||
int newMask = newSize - 1;
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
|
||||
while(EQUALS_NULL(keys[--i]));
|
||||
if(EQUALS_NOT_NULL(newKeys[pos = HashUtil.mix(TO_HASH(keys[i])) & newMask]))
|
||||
while(EQUALS_NOT_NULL(newKeys[pos = (++pos & newMask)]));
|
||||
while(KEY_EQUALS_NULL(keys[--i]));
|
||||
if(KEY_EQUALS_NOT_NULL(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask]))
|
||||
while(KEY_EQUALS_NOT_NULL(newKeys[pos = (++pos & newMask)]));
|
||||
newKeys[pos] = keys[i];
|
||||
}
|
||||
nullIndex = newSize;
|
||||
|
@ -289,7 +289,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||
if(size == 0) return;
|
||||
size = 0;
|
||||
containsNull = false;
|
||||
Arrays.fill(keys, EMPTY_VALUE);
|
||||
Arrays.fill(keys, EMPTY_KEY_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -319,7 +319,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||
nextIndex = -pos - 1;
|
||||
break;
|
||||
}
|
||||
if(EQUALS_NOT_NULL(keys[pos])){
|
||||
if(KEY_EQUALS_NOT_NULL(keys[pos])){
|
||||
nextIndex = pos;
|
||||
break;
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
if(lastReturned == nullIndex) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_VALUE;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
}
|
||||
else if(pos >= 0) shiftKeys(pos);
|
||||
else {
|
||||
|
@ -365,11 +365,11 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||
while(true) {
|
||||
startPos = ((last = startPos) + 1) & mask;
|
||||
while(true){
|
||||
if(EQUALS_NULL((current = keys[startPos]))) {
|
||||
keys[last] = EMPTY_VALUE;
|
||||
if(KEY_EQUALS_NULL((current = keys[startPos]))) {
|
||||
keys[last] = EMPTY_KEY_VALUE;
|
||||
return;
|
||||
}
|
||||
slot = HashUtil.mix(TO_HASH(current)) & mask;
|
||||
slot = HashUtil.mix(KEY_TO_HASH(current)) & mask;
|
||||
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
||||
startPos = ++startPos & mask;
|
||||
}
|
||||
|
|
|
@ -363,17 +363,17 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) {
|
||||
return new AscendingSubSetBRACES(this, true, EMPTY_VALUE, true, false, toElement, inclusive);
|
||||
return new AscendingSubSetBRACES(this, true, EMPTY_KEY_VALUE, true, false, toElement, inclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) {
|
||||
return new AscendingSubSetBRACES(this, false, fromElement, inclusive, true, EMPTY_VALUE, true);
|
||||
return new AscendingSubSetBRACES(this, false, fromElement, inclusive, true, EMPTY_KEY_VALUE, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() {
|
||||
return new DescendingSubSetBRACES(this, true, EMPTY_VALUE, true, true, EMPTY_VALUE, true);
|
||||
return new DescendingSubSetBRACES(this, true, EMPTY_KEY_VALUE, true, true, EMPTY_KEY_VALUE, true);
|
||||
}
|
||||
|
||||
protected void removeNode(Entry KEY_GENERIC_TYPE entry) {
|
||||
|
@ -406,11 +406,11 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
}
|
||||
|
||||
protected int compare(KEY_TYPE k, KEY_TYPE v) { return comparator != null ? comparator.compare(k, v) : COMPARE_TO_KEY(k, v);}
|
||||
protected static GENERIC_BRACES boolean isBlack(Entry KEY_GENERIC_TYPE p) { return p == null || p.isBlack(); }
|
||||
protected static GENERIC_BRACES Entry KEY_GENERIC_TYPE parentOf(Entry KEY_GENERIC_TYPE p) { return (p == null ? null : p.parent); }
|
||||
protected static GENERIC_BRACES void setBlack(Entry KEY_GENERIC_TYPE p, boolean c) { if(p != null) p.setBlack(c); }
|
||||
protected static GENERIC_BRACES Entry KEY_GENERIC_TYPE leftOf(Entry KEY_GENERIC_TYPE p) { return p == null ? null : p.left; }
|
||||
protected static GENERIC_BRACES Entry KEY_GENERIC_TYPE rightOf(Entry KEY_GENERIC_TYPE p) { return (p == null) ? null : p.right; }
|
||||
protected static GENERIC_KEY_BRACES boolean isBlack(Entry KEY_GENERIC_TYPE p) { return p == null || p.isBlack(); }
|
||||
protected static GENERIC_KEY_BRACES Entry KEY_GENERIC_TYPE parentOf(Entry KEY_GENERIC_TYPE p) { return (p == null ? null : p.parent); }
|
||||
protected static GENERIC_KEY_BRACES void setBlack(Entry KEY_GENERIC_TYPE p, boolean c) { if(p != null) p.setBlack(c); }
|
||||
protected static GENERIC_KEY_BRACES Entry KEY_GENERIC_TYPE leftOf(Entry KEY_GENERIC_TYPE p) { return p == null ? null : p.left; }
|
||||
protected static GENERIC_KEY_BRACES Entry KEY_GENERIC_TYPE rightOf(Entry KEY_GENERIC_TYPE p) { return (p == null) ? null : p.right; }
|
||||
|
||||
/** From CLR */
|
||||
protected void rotateLeft(Entry KEY_GENERIC_TYPE entry) {
|
||||
|
|
|
@ -100,13 +100,13 @@ public class ARRAYS
|
|||
* @param length the lenght the array should be.
|
||||
* @return a Array with the requested type and length
|
||||
*/
|
||||
public static GENERIC_BRACES KEY_TYPE[] newArray(Class<KEY_TYPE> clz, int length) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] newArray(Class<KEY_TYPE> clz, int length) {
|
||||
if(clz == Object.class) return (KEY_TYPE[])new Object[length];
|
||||
return (KEY_TYPE[]) java.lang.reflect.Array.newInstance(clz, length);
|
||||
}
|
||||
|
||||
#endif
|
||||
public static GENERIC_BRACES int shiftDown(KEY_TYPE[] data, int size, int index, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES int shiftDown(KEY_TYPE[] data, int size, int index, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
int half = size >>> 1;
|
||||
KEY_TYPE value = data[index];
|
||||
if(comp != null) {
|
||||
|
@ -135,7 +135,7 @@ public class ARRAYS
|
|||
return index;
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES int shiftUp(KEY_TYPE[] data, int index, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES int shiftUp(KEY_TYPE[] data, int index, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
KEY_TYPE value = data[index];
|
||||
if(comp != null) {
|
||||
while(index > 0) {
|
||||
|
@ -159,16 +159,16 @@ public class ARRAYS
|
|||
return index;
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES KEY_TYPE[] heapify(KEY_TYPE[] data, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] heapify(KEY_TYPE[] data, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||
for(int i = (size >>> 1) - 1;i>=0;shiftDown(data, size, i--, comp));
|
||||
return data;
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array) {
|
||||
return shuffle(array, SanityChecks.getRandom());
|
||||
}
|
||||
|
||||
public static GENERIC_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];
|
||||
|
@ -185,7 +185,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void stableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
stableSort(array, 0, array.length, comp);
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ public class ARRAYS
|
|||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void stableSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
stableSort(array, 0, length, comp);
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@ public class ARRAYS
|
|||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void stableSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
mergeSort(array, null, from, to, comp);
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ public class ARRAYS
|
|||
* Stable sort referres to Mergesort or Insertionsort
|
||||
* @param array the array that needs to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void stableSort(KEY_TYPE[] array) {
|
||||
public static COMPAREABLE_KEY_BRACES void stableSort(KEY_TYPE[] array) {
|
||||
stableSort(array, 0, array.length);
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void stableSort(KEY_TYPE[] array, int length) {
|
||||
public static COMPAREABLE_KEY_BRACES void stableSort(KEY_TYPE[] array, int length) {
|
||||
stableSort(array, 0, length);
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ public class ARRAYS
|
|||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void stableSort(KEY_TYPE[] array, int from, int to) {
|
||||
public static COMPAREABLE_KEY_BRACES void stableSort(KEY_TYPE[] array, int from, int to) {
|
||||
mergeSort(array, null, from, to);
|
||||
}
|
||||
|
||||
|
@ -254,7 +254,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void unstableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
unstableSort(array, 0, array.length, comp);
|
||||
}
|
||||
|
||||
|
@ -266,7 +266,7 @@ public class ARRAYS
|
|||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void unstableSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
unstableSort(array, 0, length, comp);
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ public class ARRAYS
|
|||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void unstableSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
quickSort(array, from, to, comp);
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ public class ARRAYS
|
|||
* Unstable sort referres to QuickSort or SelectionSort
|
||||
* @param array the array that needs to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void unstableSort(KEY_TYPE[] array) {
|
||||
public static COMPAREABLE_KEY_BRACES void unstableSort(KEY_TYPE[] array) {
|
||||
unstableSort(array, 0, array.length);
|
||||
}
|
||||
|
||||
|
@ -300,7 +300,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void unstableSort(KEY_TYPE[] array, int length) {
|
||||
public static COMPAREABLE_KEY_BRACES void unstableSort(KEY_TYPE[] array, int length) {
|
||||
unstableSort(array, 0, length);
|
||||
}
|
||||
|
||||
|
@ -312,7 +312,7 @@ public class ARRAYS
|
|||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void unstableSort(KEY_TYPE[] array, int from, int to) {
|
||||
public static COMPAREABLE_KEY_BRACES void unstableSort(KEY_TYPE[] array, int from, int to) {
|
||||
quickSort(array, from, to);
|
||||
}
|
||||
|
||||
|
@ -321,7 +321,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void insertionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
insertionSort(array, 0, array.length, comp);
|
||||
}
|
||||
|
||||
|
@ -331,7 +331,7 @@ public class ARRAYS
|
|||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void insertionSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
insertionSort(array, 0, length, comp);
|
||||
}
|
||||
|
||||
|
@ -342,7 +342,7 @@ public class ARRAYS
|
|||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void insertionSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
for (int i = from+1;i<to; i++) {
|
||||
KEY_TYPE current = array[i];
|
||||
int j = i - 1;
|
||||
|
@ -357,7 +357,7 @@ public class ARRAYS
|
|||
* Sorts an array according to the natural ascending order using InsertionSort,
|
||||
* @param array the array that needs to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void insertionSort(KEY_TYPE[] array) {
|
||||
public static COMPAREABLE_KEY_BRACES void insertionSort(KEY_TYPE[] array) {
|
||||
insertionSort(array, 0, array.length);
|
||||
}
|
||||
|
||||
|
@ -366,7 +366,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void insertionSort(KEY_TYPE[] array, int length) {
|
||||
public static COMPAREABLE_KEY_BRACES void insertionSort(KEY_TYPE[] array, int length) {
|
||||
insertionSort(array, 0, length);
|
||||
}
|
||||
|
||||
|
@ -375,7 +375,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param from where the array should be sorted from
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void insertionSort(KEY_TYPE[] array, int from, int to) {
|
||||
public static COMPAREABLE_KEY_BRACES void insertionSort(KEY_TYPE[] array, int from, int to) {
|
||||
for (int i = from+1;i<to; i++) {
|
||||
KEY_TYPE current = array[i];
|
||||
int j = i - 1;
|
||||
|
@ -391,7 +391,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void selectionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void selectionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
selectionSort(array, 0, array.length, comp);
|
||||
}
|
||||
|
||||
|
@ -401,7 +401,7 @@ public class ARRAYS
|
|||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void selectionSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void selectionSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
selectionSort(array, 0, length, comp);
|
||||
}
|
||||
|
||||
|
@ -412,7 +412,7 @@ public class ARRAYS
|
|||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void selectionSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void selectionSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
for (int i = from; i < to; i++) {
|
||||
KEY_TYPE min = array[i];
|
||||
int minId = i;
|
||||
|
@ -432,7 +432,7 @@ public class ARRAYS
|
|||
* Sorts an array according to the natural ascending order using Selection Sort,
|
||||
* @param array the array that needs to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void selectionSort(KEY_TYPE[] array) {
|
||||
public static COMPAREABLE_KEY_BRACES void selectionSort(KEY_TYPE[] array) {
|
||||
selectionSort(array, 0, array.length);
|
||||
}
|
||||
|
||||
|
@ -441,7 +441,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void selectionSort(KEY_TYPE[] array, int length) {
|
||||
public static COMPAREABLE_KEY_BRACES void selectionSort(KEY_TYPE[] array, int length) {
|
||||
selectionSort(array, 0, length);
|
||||
}
|
||||
|
||||
|
@ -450,7 +450,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param from where the array should be sorted from
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void selectionSort(KEY_TYPE[] array, int from, int to) {
|
||||
public static COMPAREABLE_KEY_BRACES void selectionSort(KEY_TYPE[] array, int from, int to) {
|
||||
for (int i = from; i < to; i++) {
|
||||
KEY_TYPE min = array[i];
|
||||
int minId = i;
|
||||
|
@ -472,7 +472,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void mergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void mergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
mergeSort(array, null, 0, array.length, comp);
|
||||
}
|
||||
|
||||
|
@ -483,7 +483,7 @@ public class ARRAYS
|
|||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void mergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void mergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
mergeSort(array, null, 0, length, comp);
|
||||
}
|
||||
|
||||
|
@ -495,7 +495,7 @@ public class ARRAYS
|
|||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void mergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void mergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to, comp);
|
||||
return;
|
||||
|
@ -520,7 +520,7 @@ public class ARRAYS
|
|||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
* @param array the array that needs to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void mergeSort(KEY_TYPE[] array) {
|
||||
public static COMPAREABLE_KEY_BRACES void mergeSort(KEY_TYPE[] array) {
|
||||
mergeSort(array, null, 0, array.length);
|
||||
}
|
||||
|
||||
|
@ -530,7 +530,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void mergeSort(KEY_TYPE[] array, int length) {
|
||||
public static COMPAREABLE_KEY_BRACES void mergeSort(KEY_TYPE[] array, int length) {
|
||||
mergeSort(array, null, 0, length);
|
||||
}
|
||||
|
||||
|
@ -541,7 +541,7 @@ public class ARRAYS
|
|||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void mergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) {
|
||||
public static COMPAREABLE_KEY_BRACES void mergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to);
|
||||
return;
|
||||
|
@ -568,7 +568,7 @@ public class ARRAYS
|
|||
* @param comp the Comparator that decides the sorting order
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_BRACES void parallelMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelMergeSort(array, null, 0, array.length, comp);
|
||||
}
|
||||
|
||||
|
@ -580,7 +580,7 @@ public class ARRAYS
|
|||
* @param comp the Comparator that decides the sorting order
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_BRACES void parallelMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelMergeSort(array, null, 0, length, comp);
|
||||
}
|
||||
|
||||
|
@ -593,7 +593,7 @@ public class ARRAYS
|
|||
* @param comp the Comparator that decides the sorting order
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
SanityChecks.invokeTask(new MergeSortActionCompBRACES(array, supp, from, to, comp));
|
||||
return;
|
||||
|
@ -607,7 +607,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void parallelMergeSort(KEY_TYPE[] array) {
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array) {
|
||||
parallelMergeSort(array, null, 0, array.length);
|
||||
}
|
||||
|
||||
|
@ -618,7 +618,7 @@ public class ARRAYS
|
|||
* @param length the maxmium size of the array to be sorted
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void parallelMergeSort(KEY_TYPE[] array, int length) {
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, int length) {
|
||||
parallelMergeSort(array, null, 0, length);
|
||||
}
|
||||
|
||||
|
@ -630,7 +630,7 @@ public class ARRAYS
|
|||
* @param to where the array should be sorted to
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) {
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
SanityChecks.invokeTask(new MergeSortActionBRACES(array, supp, from, to));
|
||||
return;
|
||||
|
@ -644,7 +644,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void memFreeMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
memFreeMergeSort(array, 0, array.length, comp);
|
||||
}
|
||||
|
||||
|
@ -655,7 +655,7 @@ public class ARRAYS
|
|||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void memFreeMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
memFreeMergeSort(array, 0, length, comp);
|
||||
}
|
||||
|
||||
|
@ -667,7 +667,7 @@ public class ARRAYS
|
|||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void memFreeMergeSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to, comp);
|
||||
return;
|
||||
|
@ -714,7 +714,7 @@ public class ARRAYS
|
|||
* @author Speiger
|
||||
* @param array the array that needs to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void memFreeMergeSort(KEY_TYPE[] array) {
|
||||
public static COMPAREABLE_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array) {
|
||||
memFreeMergeSort(array, 0, array.length);
|
||||
}
|
||||
|
||||
|
@ -727,7 +727,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void memFreeMergeSort(KEY_TYPE[] array, int length) {
|
||||
public static COMPAREABLE_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int length) {
|
||||
memFreeMergeSort(array, 0, length);
|
||||
}
|
||||
|
||||
|
@ -741,7 +741,7 @@ public class ARRAYS
|
|||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void memFreeMergeSort(KEY_TYPE[] array, int from, int to) {
|
||||
public static COMPAREABLE_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int from, int to) {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to);
|
||||
return;
|
||||
|
@ -790,7 +790,7 @@ public class ARRAYS
|
|||
* @param comp the Comparator that decides the sorting order
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelMemFreeMergeSort(array, 0, array.length, comp);
|
||||
}
|
||||
|
||||
|
@ -805,7 +805,7 @@ public class ARRAYS
|
|||
* @param comp the Comparator that decides the sorting order
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelMemFreeMergeSort(array, 0, length, comp);
|
||||
}
|
||||
|
||||
|
@ -821,7 +821,7 @@ public class ARRAYS
|
|||
* @param comp the Comparator that decides the sorting order
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
SanityChecks.invokeTask(new MemFreeMergeSortActionCompBRACES(array, from, to, comp));
|
||||
return;
|
||||
|
@ -838,7 +838,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array) {
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array) {
|
||||
parallelMemFreeMergeSort(array, 0, array.length);
|
||||
}
|
||||
|
||||
|
@ -852,7 +852,7 @@ public class ARRAYS
|
|||
* @param length the maxmium size of the array to be sorted
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length) {
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length) {
|
||||
parallelMemFreeMergeSort(array, 0, length);
|
||||
}
|
||||
|
||||
|
@ -867,7 +867,7 @@ public class ARRAYS
|
|||
* @param to where the array should be sorted to
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to) {
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
SanityChecks.invokeTask(new MemFreeMergeSortActionBRACES(array, from, to));
|
||||
return;
|
||||
|
@ -882,7 +882,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void quickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
quickSort(array, 0, array.length, comp);
|
||||
}
|
||||
|
||||
|
@ -894,7 +894,7 @@ public class ARRAYS
|
|||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void quickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
quickSort(array, 0, length, comp);
|
||||
}
|
||||
|
||||
|
@ -907,7 +907,7 @@ public class ARRAYS
|
|||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
*/
|
||||
public static GENERIC_BRACES void quickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
int length = to - from;
|
||||
if(length <= 0) return;
|
||||
if(length < BASE_THRESHOLD) {
|
||||
|
@ -937,7 +937,7 @@ public class ARRAYS
|
|||
* and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages1249−1265, 1993.
|
||||
* @param array the array that needs to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void quickSort(KEY_TYPE[] array) {
|
||||
public static COMPAREABLE_KEY_BRACES void quickSort(KEY_TYPE[] array) {
|
||||
quickSort(array, 0, array.length);
|
||||
}
|
||||
|
||||
|
@ -948,7 +948,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void quickSort(KEY_TYPE[] array, int length) {
|
||||
public static COMPAREABLE_KEY_BRACES void quickSort(KEY_TYPE[] array, int length) {
|
||||
quickSort(array, 0, length);
|
||||
}
|
||||
|
||||
|
@ -960,7 +960,7 @@ public class ARRAYS
|
|||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void quickSort(KEY_TYPE[] array, int from, int to) {
|
||||
public static COMPAREABLE_KEY_BRACES void quickSort(KEY_TYPE[] array, int from, int to) {
|
||||
int length = to - from;
|
||||
if(length <= 0) return;
|
||||
if(length < BASE_THRESHOLD) {
|
||||
|
@ -992,7 +992,7 @@ public class ARRAYS
|
|||
* @param comp the Comparator that decides the sorting order
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_BRACES void parallelQuickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelQuickSort(array, 0, array.length, comp);
|
||||
}
|
||||
|
||||
|
@ -1005,7 +1005,7 @@ public class ARRAYS
|
|||
* @param comp the Comparator that decides the sorting order
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_BRACES void parallelQuickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelQuickSort(array, 0, length, comp);
|
||||
}
|
||||
|
||||
|
@ -1019,7 +1019,7 @@ public class ARRAYS
|
|||
* @param comp the Comparator that decides the sorting order
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
SanityChecks.invokeTask(new QuickSortActionCompBRACES(array, from, to, comp));
|
||||
return;
|
||||
|
@ -1034,7 +1034,7 @@ public class ARRAYS
|
|||
* @param array the array that needs to be sorted
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void parallelQuickSort(KEY_TYPE[] array) {
|
||||
public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array) {
|
||||
parallelQuickSort(array, 0, array.length);
|
||||
}
|
||||
|
||||
|
@ -1046,7 +1046,7 @@ public class ARRAYS
|
|||
* @param length the maxmium size of the array to be sorted
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void parallelQuickSort(KEY_TYPE[] array, int length) {
|
||||
public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int length) {
|
||||
parallelQuickSort(array, 0, length);
|
||||
}
|
||||
|
||||
|
@ -1059,7 +1059,7 @@ public class ARRAYS
|
|||
* @param to where the array should be sorted to
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to) {
|
||||
public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
SanityChecks.invokeTask(new QuickSortActionBRACES(array, from, to));
|
||||
return;
|
||||
|
@ -1067,30 +1067,30 @@ public class ARRAYS
|
|||
quickSort(array, from, to);
|
||||
}
|
||||
|
||||
static GENERIC_BRACES void swap(KEY_TYPE[] a, int from, int to) {
|
||||
static GENERIC_KEY_BRACES void swap(KEY_TYPE[] a, int from, int to) {
|
||||
KEY_TYPE t = a[from];
|
||||
a[from] = a[to];
|
||||
a[to] = t;
|
||||
}
|
||||
|
||||
static GENERIC_BRACES void swap(KEY_TYPE[] a, int from, int to, int length) {
|
||||
static GENERIC_KEY_BRACES void swap(KEY_TYPE[] a, int from, int to, int length) {
|
||||
to -= length;
|
||||
for(int i = 0;i<length;i++,swap(a, from++, to++));
|
||||
}
|
||||
|
||||
static GENERIC_BRACES int subMedium(KEY_TYPE[] data, int a, int b, int c, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
static GENERIC_KEY_BRACES int subMedium(KEY_TYPE[] data, int a, int b, int c, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
return medium(data, medium(data, a, a + length, a + (length * 2), comp), medium(data, b - length, b, b + length, comp), medium(data, c - (length * 2), c - length, c, comp), comp);
|
||||
}
|
||||
|
||||
static GENERIC_BRACES int medium(KEY_TYPE[] data, int a, int b, int c, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
static GENERIC_KEY_BRACES int medium(KEY_TYPE[] data, int a, int b, int c, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
return comp.compare(data[a], data[b]) < 0 ? (comp.compare(data[b], data[c]) < 0 ? b : comp.compare(data[a], data[c]) < 0 ? c : a) : (comp.compare(data[b], data[c]) > 0 ? b : comp.compare(data[a], data[c]) > 0 ? c : a);
|
||||
}
|
||||
|
||||
static COMPAREABLE_BRACES int subMedium(KEY_TYPE[] data, int a, int b, int c, int length) {
|
||||
static COMPAREABLE_KEY_BRACES int subMedium(KEY_TYPE[] data, int a, int b, int c, int length) {
|
||||
return medium(data, medium(data, a, a + length, a + (length * 2)), medium(data, b - length, b, b + length), medium(data, c - (length * 2), c - length, c));
|
||||
}
|
||||
|
||||
static COMPAREABLE_BRACES int medium(KEY_TYPE[] data, int a, int b, int c) {
|
||||
static COMPAREABLE_KEY_BRACES int medium(KEY_TYPE[] data, int a, int b, int c) {
|
||||
return COMPARE_TO(data[a], data[b]) < 0 ? (COMPARE_TO(data[b], data[c]) < 0 ? b : COMPARE_TO(data[a], data[c]) < 0 ? c : a) : (COMPARE_TO(data[b], data[c]) > 0 ? b : COMPARE_TO(data[a], data[c]) > 0 ? c : a);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public class COLLECTIONS
|
|||
* Returns a Immutable EmptyCollection instance that is automatically casted.
|
||||
* @return an empty collection
|
||||
*/
|
||||
public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE emptyCollection() {
|
||||
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE emptyCollection() {
|
||||
#if TYPE_OBJECT
|
||||
return (COLLECTION<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
|
@ -38,7 +38,7 @@ public class COLLECTIONS
|
|||
* @param l that should be made immutable/unmodifyable
|
||||
* @return a unmodifiable collection wrapper. If the Collection already a unmodifyable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE unmodifiableCollection(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE unmodifiableCollection(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
return c instanceof UnmodifiableCollection ? c : new UnmodifiableCollectionBRACES(c);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class COLLECTIONS
|
|||
* @param l that should be synchronized
|
||||
* @return a synchronized collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE synchronizedCollection(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE synchronizedCollection(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
return c instanceof SynchronizedCollection ? c : new SynchronizedCollectionBRACES(c);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class COLLECTIONS
|
|||
* @param mutex is the controller of the synchronization block.
|
||||
* @return a synchronized collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE synchronizedCollection(COLLECTION KEY_GENERIC_TYPE c, Object mutex) {
|
||||
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE synchronizedCollection(COLLECTION KEY_GENERIC_TYPE c, Object mutex) {
|
||||
return c instanceof SynchronizedCollection ? c : new SynchronizedCollectionBRACES(c, mutex);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ public class ITERATORS
|
|||
* Returns a Immutable EmptyIterator instance that is automatically casted.
|
||||
* @return an empty iterator
|
||||
*/
|
||||
public static GENERIC_BRACES EmptyIterator KEY_GENERIC_TYPE emptyIterator() {
|
||||
public static GENERIC_KEY_BRACES EmptyIterator KEY_GENERIC_TYPE emptyIterator() {
|
||||
#if TYPE_OBJECT
|
||||
return (EmptyIterator<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
|
@ -29,11 +29,11 @@ public class ITERATORS
|
|||
* @param l that should be made immutable/unmodifyable
|
||||
* @return a unmodifiable iterator wrapper. If the Iterator already a unmodifyable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_BRACES ITERATOR KEY_GENERIC_TYPE unmodifiable(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE unmodifiable(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
return iterator instanceof UnmodifiableIterator ? iterator : new UnmodifiableIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES BI_ITERATOR KEY_GENERIC_TYPE unmodifiable(BI_ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
public static GENERIC_KEY_BRACES BI_ITERATOR KEY_GENERIC_TYPE unmodifiable(BI_ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
return iterator instanceof UnmodifiableBiIterator ? iterator : new UnmodifiableBiIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class ITERATORS
|
|||
* @param l that should be made immutable/unmodifyable
|
||||
* @return a unmodifiable listiterator wrapper. If the ListIterator already a unmodifyable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_BRACES LIST_ITERATOR KEY_GENERIC_TYPE unmodifiable(LIST_ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
public static GENERIC_KEY_BRACES LIST_ITERATOR KEY_GENERIC_TYPE unmodifiable(LIST_ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
return iterator instanceof UnmodifiableListIterator ? iterator : new UnmodifiableListIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class ITERATORS
|
|||
* @param a the array that should be wrapped
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
|
||||
return wrap(a, 0, a.length);
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class ITERATORS
|
|||
* @param end the index that should be ended.
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) {
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) {
|
||||
return new ArrayIteratorBRACES(a, start, end);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ public class ITERATORS
|
|||
* @param i the source iterator
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i) {
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i) {
|
||||
return unwrap(a, i, 0, a.length);
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ public class ITERATORS
|
|||
* @param offset the array offset where the start should be
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i, int offset) {
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i, int offset) {
|
||||
return unwrap(a, i, offset, a.length - offset);
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ public class ITERATORS
|
|||
* @return the amount of elements that were inserted into the array.
|
||||
* @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array
|
||||
*/
|
||||
public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i, int offset, int max) {
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i, int offset, int max) {
|
||||
if(max < 0) throw new IllegalStateException("The max size is smaller then 0");
|
||||
if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size");
|
||||
int index = 0;
|
||||
|
@ -117,7 +117,7 @@ public class ITERATORS
|
|||
* @param i the source iterator
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) {
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) {
|
||||
return unwrap(a, i, 0, a.length);
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ public class ITERATORS
|
|||
* @param offset the array offset where the start should be
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) {
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) {
|
||||
return unwrap(a, i, offset, a.length - offset);
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ public class ITERATORS
|
|||
* @return the amount of elements that were inserted into the array.
|
||||
* @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array
|
||||
*/
|
||||
public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) {
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) {
|
||||
if(max < 0) throw new IllegalStateException("The max size is smaller then 0");
|
||||
if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size");
|
||||
int index = 0;
|
||||
|
@ -159,7 +159,7 @@ public class ITERATORS
|
|||
* @param i the source iterator
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) {
|
||||
public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) {
|
||||
return unwrap(a, i, 0, a.length);
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ public class ITERATORS
|
|||
* @param offset the array offset where the start should be
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) {
|
||||
public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) {
|
||||
return unwrap(a, i, offset, a.length - offset);
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ public class ITERATORS
|
|||
* @return the amount of elements that were inserted into the array.
|
||||
* @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array
|
||||
*/
|
||||
public static GENERIC_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) {
|
||||
public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) {
|
||||
if(max < 0) throw new IllegalStateException("The max size is smaller then 0");
|
||||
if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size");
|
||||
int index = 0;
|
||||
|
@ -324,7 +324,7 @@ public class ITERATORS
|
|||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
return EMPTY_VALUE;
|
||||
return EMPTY_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -334,7 +334,7 @@ public class ITERATORS
|
|||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
return EMPTY_VALUE;
|
||||
return EMPTY_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,7 +23,7 @@ public class LISTS
|
|||
* Returns a Immutable EmptyList instance that is automatically casted.
|
||||
* @return an empty list
|
||||
*/
|
||||
public static GENERIC_BRACES EmptyList KEY_GENERIC_TYPE emptyList() {
|
||||
public static GENERIC_KEY_BRACES EmptyList KEY_GENERIC_TYPE emptyList() {
|
||||
#if TYPE_OBJECT
|
||||
return (EmptyList<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
|
@ -36,7 +36,7 @@ public class LISTS
|
|||
* @param l that should be made immutable/unmodifyable
|
||||
* @return a unmodifiable list wrapper. If the list is implementing RandomAccess that is also transferred. If the List already a unmodifyable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_BRACES LIST KEY_GENERIC_TYPE unmodifiableList(LIST KEY_GENERIC_TYPE l) {
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE unmodifiableList(LIST KEY_GENERIC_TYPE l) {
|
||||
return l instanceof UnmodifiableList ? l : l instanceof RandomAccess ? new UnmodifiableRandomListBRACES(l) : new UnmodifiableListBRACES(l);
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class LISTS
|
|||
* @param l that should be synchronized
|
||||
* @return a synchronized list wrapper. If the list is implementing RandomAccess or IARRAY that is also transferred. If the List already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_BRACES LIST KEY_GENERIC_TYPE synchronizedList(LIST KEY_GENERIC_TYPE l) {
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE synchronizedList(LIST KEY_GENERIC_TYPE l) {
|
||||
return l instanceof SynchronizedList ? l : (l instanceof IARRAY ? new SynchronizedArrayListBRACES(l) : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l) : new SynchronizedListBRACES(l)));
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class LISTS
|
|||
* @param mutex is the controller of the synchronization block.
|
||||
* @return a synchronized list wrapper. If the list is implementing RandomAccess or IARRAY that is also transferred. If the List already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_BRACES LIST KEY_GENERIC_TYPE synchronizedList(LIST KEY_GENERIC_TYPE l, Object mutex) {
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE synchronizedList(LIST KEY_GENERIC_TYPE l, Object mutex) {
|
||||
return l instanceof SynchronizedList ? l : (l instanceof IARRAY ? new SynchronizedArrayListBRACES(l, mutex) : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l, mutex) : new SynchronizedListBRACES(l, mutex)));
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ public class SETS
|
|||
{
|
||||
public static final SET NO_GENERIC_TYPE EMPTY = new EmptySetBRACES();
|
||||
|
||||
public static GENERIC_BRACES SET KEY_GENERIC_TYPE empty() {
|
||||
public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE empty() {
|
||||
#if TYPE_OBJECT
|
||||
return (SET<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
|
@ -28,39 +28,39 @@ public class SETS
|
|||
#endif
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES SET KEY_GENERIC_TYPE synchronizedSet(SET KEY_GENERIC_TYPE s) {
|
||||
public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE synchronizedSet(SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof SynchronizedSet ? s : (s instanceof ITrimmable ? new SynchronizedTrimSetBRACES(s) : new SynchronizedSetBRACES(s));
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES SET KEY_GENERIC_TYPE synchronizedSet(SET KEY_GENERIC_TYPE s, Object mutex) {
|
||||
public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE synchronizedSet(SET KEY_GENERIC_TYPE s, Object mutex) {
|
||||
return s instanceof SynchronizedSet ? s : (s instanceof ITrimmable ? new SynchronizedTrimSetBRACES(s, mutex) : new SynchronizedSetBRACES(s, mutex));
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES SORTED_SET KEY_GENERIC_TYPE synchronizedSet(SORTED_SET KEY_GENERIC_TYPE s) {
|
||||
public static GENERIC_KEY_BRACES SORTED_SET KEY_GENERIC_TYPE synchronizedSet(SORTED_SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s) : new SynchronizedSortedSetBRACES(s));
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES SORTED_SET KEY_GENERIC_TYPE synchronizedSet(SORTED_SET KEY_GENERIC_TYPE s, Object mutex) {
|
||||
public static GENERIC_KEY_BRACES SORTED_SET KEY_GENERIC_TYPE synchronizedSet(SORTED_SET KEY_GENERIC_TYPE s, Object mutex) {
|
||||
return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s, mutex) : new SynchronizedSortedSetBRACES(s, mutex));
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE synchronizedSet(NAVIGABLE_SET KEY_GENERIC_TYPE s) {
|
||||
public static GENERIC_KEY_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE synchronizedSet(NAVIGABLE_SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof SynchronizedNavigableSet ? s : (s instanceof ITrimmable ? new SynchronizedNavigableTrimSetBRACES(s) : new SynchronizedNavigableSetBRACES(s));
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE synchronizedSet(NAVIGABLE_SET KEY_GENERIC_TYPE s, Object mutex) {
|
||||
public static GENERIC_KEY_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE synchronizedSet(NAVIGABLE_SET KEY_GENERIC_TYPE s, Object mutex) {
|
||||
return s instanceof SynchronizedNavigableSet ? s : (s instanceof ITrimmable ? new SynchronizedNavigableTrimSetBRACES(s, mutex) : new SynchronizedNavigableSetBRACES(s, mutex));
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES SET KEY_GENERIC_TYPE unmodifiable(SET KEY_GENERIC_TYPE s) {
|
||||
public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE unmodifiable(SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof SynchronizedSet ? s : new SynchronizedSetBRACES(s);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES SORTED_SET KEY_GENERIC_TYPE unmodifiable(SORTED_SET KEY_GENERIC_TYPE s) {
|
||||
public static GENERIC_KEY_BRACES SORTED_SET KEY_GENERIC_TYPE unmodifiable(SORTED_SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof SynchronizedSortedSet ? s : new SynchronizedSortedSetBRACES(s);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable(NAVIGABLE_SET KEY_GENERIC_TYPE s) {
|
||||
public static GENERIC_KEY_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable(NAVIGABLE_SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof UnmodifiableNavigableSet ? s : new UnmodifiableNavigableSetBRACES(s);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package speiger.src.collections.ints.base;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
|
@ -9,6 +7,7 @@ import org.junit.Assert;
|
|||
import org.junit.Test;
|
||||
|
||||
import speiger.src.collections.ints.queues.IntPriorityQueue;
|
||||
import speiger.src.collections.ints.utils.IntArrays;
|
||||
import speiger.src.collections.tests.IterableTest;
|
||||
import speiger.src.collections.tests.PriorityQueueTest;
|
||||
|
||||
|
@ -19,6 +18,7 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
|||
@Override
|
||||
protected EnumSet<IterableTest> getValidIterableTests() { return EnumSet.of(IterableTest.FOR_EACH, IterableTest.ITERATOR_FOR_EACH, IterableTest.ITERATOR_LOOP, IterableTest.ITERATOR_SKIP); }
|
||||
protected EnumSet<PriorityQueueTest> getValidPriorityQueueTests() { return EnumSet.allOf(PriorityQueueTest.class); }
|
||||
protected boolean isUnsortedRead() { return true; }
|
||||
|
||||
@Test
|
||||
public void testEnqueue() {
|
||||
|
@ -26,11 +26,12 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
|||
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
||||
for(int i = 0;i<100;i++) {
|
||||
queue.enqueueInt(i);
|
||||
Assert.assertEquals(i, queue.lastInt());
|
||||
}
|
||||
for(int i = 0;i<100;i++) {
|
||||
Assert.assertEquals(i, queue.firstInt());
|
||||
Assert.assertEquals(99, queue.lastInt());
|
||||
Assert.assertEquals(i, queue.dequeueInt());
|
||||
}
|
||||
queue = create(TEST_ARRAY);
|
||||
for(int i = 0;i<100;i++) {
|
||||
Assert.assertEquals(i, queue.dequeueInt());
|
||||
}
|
||||
}
|
||||
|
@ -42,10 +43,17 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
|||
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
||||
for(int i = 0;i<100;i++) {
|
||||
queue.enqueueInt(i);
|
||||
Assert.assertEquals(i, queue.lastInt());
|
||||
}
|
||||
for(int i = 0;i<100;i++) {
|
||||
assertEquals(i, queue.peekInt(i));
|
||||
if(isUnsortedRead()) {
|
||||
for(int i = 0;i<100;i++) {
|
||||
int value = queue.peekInt(i);
|
||||
Assert.assertTrue(value >= 0 && value < 100);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(int i = 0;i<100;i++) {
|
||||
Assert.assertEquals(i, queue.peekInt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,21 +64,19 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
|||
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
||||
for(int i = 0;i<100;i++) {
|
||||
queue.enqueueInt(i);
|
||||
Assert.assertEquals(i, queue.lastInt());
|
||||
}
|
||||
queue.removeInt(40);
|
||||
for(int i = 0;i<99;i++) {
|
||||
if(i >= 40) assertEquals(i + 1, queue.dequeueInt());
|
||||
else assertEquals(i, queue.dequeueInt());
|
||||
if(i >= 40) Assert.assertEquals(i + 1, queue.dequeueInt());
|
||||
else Assert.assertEquals(i, queue.dequeueInt());
|
||||
}
|
||||
for(int i = 0;i<100;i++) {
|
||||
queue.enqueueInt(i);
|
||||
Assert.assertEquals(i, queue.lastInt());
|
||||
}
|
||||
queue.removeLastInt(40);
|
||||
for(int i = 0;i<99;i++) {
|
||||
if(i >= 40) assertEquals(i + 1, queue.dequeueInt());
|
||||
else assertEquals(i, queue.dequeueInt());
|
||||
if(i >= 40) Assert.assertEquals(i + 1, queue.dequeueInt());
|
||||
else Assert.assertEquals(i, queue.dequeueInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,36 +85,45 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
|||
@SuppressWarnings("deprecation")
|
||||
public void testToArray() {
|
||||
if(getValidPriorityQueueTests().contains(PriorityQueueTest.TO_ARRAY)) {
|
||||
IntPriorityQueue q = create(EMPTY_ARRAY);
|
||||
Integer[] ref = new Integer[100];
|
||||
Integer[] shiftArray = new Integer[100];
|
||||
int[] primRef = new int[100];
|
||||
int[] shiftPrimArray = new int[100];
|
||||
for(int i = 0; i < 100; i++) {
|
||||
q.enqueue(i);
|
||||
assertEquals(i, q.lastInt());
|
||||
ref[i] = Integer.valueOf(i);
|
||||
primRef[i] = i;
|
||||
shiftPrimArray[(i+80) % 100] = i;
|
||||
shiftArray[(i+80) % 100] = Integer.valueOf(i);
|
||||
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
||||
if(isUnsortedRead()) {
|
||||
for(int i = 0;i<100;i++) {
|
||||
queue.enqueueInt(i);
|
||||
}
|
||||
int[] array = queue.toIntArray();
|
||||
IntArrays.stableSort(array);
|
||||
Assert.assertArrayEquals(TEST_ARRAY, array);
|
||||
int[] data = queue.toIntArray(new int[100]);
|
||||
int[] nonData = queue.toIntArray(new int[0]);
|
||||
IntArrays.stableSort(data);
|
||||
IntArrays.stableSort(nonData);
|
||||
Assert.assertArrayEquals(array, data);
|
||||
Assert.assertArrayEquals(array, nonData);
|
||||
}
|
||||
assertArrayEquals(q.toArray(), ref);
|
||||
assertArrayEquals(q.toArray(new Integer[100]), ref);
|
||||
assertArrayEquals(q.toArray(null), ref);
|
||||
assertArrayEquals(q.toIntArray(), primRef);
|
||||
assertArrayEquals(q.toIntArray(new int[100]), primRef);
|
||||
assertArrayEquals(q.toIntArray(null), primRef);
|
||||
IntPriorityQueue other = create(q.toIntArray());
|
||||
for(int i = 0;i<100;i++) {
|
||||
assertEquals(other.peekInt(i), primRef[i]);
|
||||
else {
|
||||
Integer[] ref = IntArrays.wrap(TEST_ARRAY);
|
||||
Integer[] shiftArray = new Integer[100];
|
||||
int[] shiftPrimArray = new int[100];
|
||||
for(int i = 0; i < 100; i++) {
|
||||
queue.enqueue(i);
|
||||
shiftPrimArray[(i+80) % 100] = i;
|
||||
shiftArray[(i+80) % 100] = Integer.valueOf(i);
|
||||
}
|
||||
Assert.assertArrayEquals(ref, queue.toArray());
|
||||
Assert.assertArrayEquals(ref, queue.toArray(new Integer[100]));
|
||||
Assert.assertArrayEquals(ref, queue.toArray(null));
|
||||
Assert.assertArrayEquals(TEST_ARRAY, queue.toIntArray());
|
||||
Assert.assertArrayEquals(TEST_ARRAY, queue.toIntArray(new int[100]));
|
||||
Assert.assertArrayEquals(TEST_ARRAY, queue.toIntArray(null));
|
||||
IntPriorityQueue other = create(queue.toIntArray());
|
||||
for(int i = 0;i<20;i++) {
|
||||
other.dequeueInt();
|
||||
other.enqueue(i);
|
||||
}
|
||||
Assert.assertArrayEquals(shiftPrimArray, other.toIntArray());
|
||||
Assert.assertArrayEquals(shiftPrimArray, other.toIntArray(new int[100]));
|
||||
Assert.assertArrayEquals(shiftArray, other.toArray());
|
||||
}
|
||||
for(int i = 0;i<20;i++) {
|
||||
other.dequeueInt();
|
||||
other.enqueue(i);
|
||||
}
|
||||
assertArrayEquals(other.toIntArray(), shiftPrimArray);
|
||||
assertArrayEquals(other.toIntArray(new int[100]), shiftPrimArray);
|
||||
assertArrayEquals(other.toArray(), shiftArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,7 @@ public class IntArrayFIFOQueueTests extends BaseIntPriorityQueueTest
|
|||
{
|
||||
@Override
|
||||
protected IntPriorityQueue create(int[] data){return new IntArrayFIFOQueue(data);}
|
||||
|
||||
@Override
|
||||
protected boolean isUnsortedRead() { return false; }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package speiger.src.collections.ints.queues;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseIntPriorityQueueTest;
|
||||
|
||||
public class IntArrayPriorityQueueTests extends BaseIntPriorityQueueTest
|
||||
{
|
||||
@Override
|
||||
protected IntPriorityQueue create(int[] data) {
|
||||
return new IntArrayPriorityQueue(data);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package speiger.src.collections.ints.queues;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseIntPriorityQueueTest;
|
||||
|
||||
public class IntHeapPriorityQueueTests extends BaseIntPriorityQueueTest
|
||||
{
|
||||
@Override
|
||||
protected IntPriorityQueue create(int[] data) {
|
||||
return new IntHeapPriorityQueue(data);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue