Compare commits
6
Commits
3d39d5526d
...
1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a97d017b7 | ||
|
|
374b027120 | ||
|
|
21ccbee3b2 | ||
|
|
58a9eb38b4 | ||
|
|
2f1525ab57 | ||
|
|
9f46091282 |
+1
-1
@@ -32,7 +32,7 @@
|
||||
<attribute name="gradle_used_by_scope" value="builder"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
||||
|
||||
+48
-48
@@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id "jacoco"
|
||||
id "com.vanniktech.maven.publish" version "0.28.0"
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
@@ -56,7 +57,7 @@ dependencies {
|
||||
builderImplementation 'com.google.code.gson:gson:2.10'
|
||||
builderImplementation 'de.speiger:Simple-Code-Generator:1.3.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
|
||||
testImplementation 'com.google.guava:guava-testlib:33.6.0-jre'
|
||||
|
||||
}
|
||||
|
||||
@@ -331,50 +332,49 @@ tasks.withType(PublishToMavenLocal) {
|
||||
//Maven central Start
|
||||
//Disabling due to java8 incompat, only needed to manually publishing anyways
|
||||
|
||||
//signing.useGpgCmd()
|
||||
//
|
||||
//import com.vanniktech.maven.publish.SonatypeHost
|
||||
//import com.vanniktech.maven.publish.JavaLibrary
|
||||
//import com.vanniktech.maven.publish.JavadocJar
|
||||
//
|
||||
//mavenPublishing {
|
||||
// configure(new JavaLibrary(new JavadocJar.None(), true))
|
||||
//}
|
||||
//
|
||||
//mavenPublishing {
|
||||
// publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
|
||||
//
|
||||
// signAllPublications()
|
||||
// pom {
|
||||
// name = 'Primitive Collections'
|
||||
// description = 'A Primitive Collection library that reduces memory usage and improves performance'
|
||||
// url = 'https://github.com/Speiger/Primitive-Collections'
|
||||
// version = project.version
|
||||
// group = 'io.github.speiger'
|
||||
// licenses {
|
||||
// license {
|
||||
// name = 'The Apache License, Version 2.0'
|
||||
// url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// developers {
|
||||
// developer {
|
||||
// id = 'speiger'
|
||||
// name = 'Speiger'
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// scm {
|
||||
// connection = 'scm:git:git://github.com/Speiger/Primitive-Collections.git'
|
||||
// developerConnection = 'scm:git:ssh://github.com:Speiger/Primitive-Collections.git'
|
||||
// url = 'https://github.com/Speiger/Primitive-Collections'
|
||||
// }
|
||||
//
|
||||
// issueManagement {
|
||||
// system = 'github'
|
||||
// url = 'https://github.com/Speiger/Primitive-Collections/issues'
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
signing.useGpgCmd()
|
||||
|
||||
import com.vanniktech.maven.publish.SonatypeHost
|
||||
import com.vanniktech.maven.publish.JavaLibrary
|
||||
import com.vanniktech.maven.publish.JavadocJar
|
||||
|
||||
mavenPublishing {
|
||||
configure(new JavaLibrary(new JavadocJar.None(), true))
|
||||
}
|
||||
|
||||
mavenPublishing {
|
||||
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
|
||||
|
||||
signAllPublications()
|
||||
pom {
|
||||
name = 'Primitive Collections'
|
||||
description = 'A Primitive Collection library that reduces memory usage and improves performance'
|
||||
url = 'https://github.com/Speiger/Primitive-Collections'
|
||||
version = project.version
|
||||
group = 'io.github.speiger'
|
||||
licenses {
|
||||
license {
|
||||
name = 'The Apache License, Version 2.0'
|
||||
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
}
|
||||
}
|
||||
|
||||
developers {
|
||||
developer {
|
||||
id = 'speiger'
|
||||
name = 'Speiger'
|
||||
}
|
||||
}
|
||||
|
||||
scm {
|
||||
connection = 'scm:git:git://github.com/Speiger/Primitive-Collections.git'
|
||||
developerConnection = 'scm:git:ssh://github.com:Speiger/Primitive-Collections.git'
|
||||
url = 'https://github.com/Speiger/Primitive-Collections'
|
||||
}
|
||||
|
||||
issueManagement {
|
||||
system = 'github'
|
||||
url = 'https://github.com/Speiger/Primitive-Collections/issues'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx3G
|
||||
maxMemory = 2048m
|
||||
testThreads = 4
|
||||
|
||||
RELEASE_VERSION = 0.9.0
|
||||
RELEASE_VERSION = 1.0.0
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
jdk:
|
||||
- openjdk9
|
||||
- openjdk21
|
||||
install:
|
||||
- chmod +x ./gradlew
|
||||
- ./gradlew build publishToMavenLocal
|
||||
|
||||
@@ -36,6 +36,10 @@ public class MapModule extends BaseModule
|
||||
public static final FunctionDependency ENUM_MAP = MODULE.createDependency("EnumMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_ENUM_MAP = MODULE.createDependency("LinkedEnumMap").addEntryDependency(ENUM_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
public static final FunctionDependency REF_MAP = MODULE.createDependency("ReferenceHashMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_REF_MAP = MODULE.createDependency("LinkedReferenceMap").addEntryDependency(REF_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
|
||||
public static final FunctionDependency CONCURRENT_MAP = MODULE.createDependency("ConcurrentMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency AVL_TREE_MAP = MODULE.createDependency("AVLTreeMap").addEntryDependency(SORTED_MAP).addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency RB_TREE_MAP = MODULE.createDependency("RBTreeMap").addEntryDependency(SORTED_MAP).addEntryDependency(IMPLEMENTATION);
|
||||
@@ -51,7 +55,7 @@ public class MapModule extends BaseModule
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
|
||||
List<IDependency> dependencies = new ArrayList<>(Arrays.asList(MODULE, ORDERED_MAP, SORTED_MAP, IMPLEMENTATION, WRAPPERS, ARRAY_MAP, IMMUTABLE_MAP, HASH_MAP, LINKED_MAP, CUSTOM_MAP, LINKED_CUSTOM_MAP, CONCURRENT_MAP, AVL_TREE_MAP, RB_TREE_MAP));
|
||||
if(keyType == ClassType.OBJECT) dependencies.addAll(Arrays.asList(ENUM_MAP, LINKED_ENUM_MAP));
|
||||
if(keyType == ClassType.OBJECT) dependencies.addAll(Arrays.asList(ENUM_MAP, LINKED_ENUM_MAP, REF_MAP, LINKED_REF_MAP));
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
@@ -70,6 +74,10 @@ public class MapModule extends BaseModule
|
||||
if(AVL_TREE_MAP.isEnabled()) addFlag("AVL_TREE_MAP_FEATURE");
|
||||
if(RB_TREE_MAP.isEnabled()) addFlag("RB_TREE_MAP_FEATURE");
|
||||
|
||||
if(REF_MAP.isEnabled()) addFlag("REF_MAP_FEATURE");
|
||||
if(LINKED_REF_MAP.isEnabled()) addFlag("LINKED_REF_MAP_FEATURE");
|
||||
|
||||
|
||||
if(CONCURRENT_MAP.isEnabled()) addFlag("CONCURRENT_MAP_FEATURE");
|
||||
if(IMMUTABLE_MAP.isEnabled()) addFlag("IMMUTABLE_MAP_FEATURE");
|
||||
if(HASH_MAP.isEnabled()) addFlag("MAP_FEATURE");
|
||||
@@ -85,6 +93,8 @@ public class MapModule extends BaseModule
|
||||
if(!IMMUTABLE_MAP.isEnabled()) addBlockedFiles("ImmutableOpenHashMap");
|
||||
if(!CONCURRENT_MAP.isEnabled()) addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap");
|
||||
if(!ORDERED_MAP.isEnabled()) addBlockedFiles("OrderedMap");
|
||||
if(!REF_MAP.isEnabled()) addBlockedFiles("ReferenceHashMap");
|
||||
if(!LINKED_REF_MAP.isEnabled()) addBlockedFiles("LinkedReferenceHashMap");
|
||||
if(!HASH_MAP.isEnabled()) addBlockedFiles("OpenHashMap");
|
||||
if(!LINKED_MAP.isEnabled()) addBlockedFiles("LinkedOpenHashMap");
|
||||
if(!CUSTOM_MAP.isEnabled()) addBlockedFiles("OpenCustomHashMap");
|
||||
@@ -127,6 +137,8 @@ public class MapModule extends BaseModule
|
||||
addBiRequirement("AbstractMap");
|
||||
addEnumRequirement("EnumMap");
|
||||
addEnumRequirement("LinkedEnumMap");
|
||||
addEnumRequirement("ReferenceHashMap");
|
||||
addEnumRequirement("LinkedReferenceHashMap");
|
||||
addBiRequirement("ConcurrentOpenHashMap");
|
||||
addBiRequirement("ImmutableOpenHashMap");
|
||||
addBiRequirement("OpenHashMap");
|
||||
@@ -141,6 +153,8 @@ public class MapModule extends BaseModule
|
||||
addRemapper("AbstractMap", "Abstract%sMap");
|
||||
addRemapper("EnumMap", "Enum2%sMap");
|
||||
addRemapper("LinkedEnumMap", "LinkedEnum2%sMap");
|
||||
addRemapper("ReferenceHashMap", "Reference2%sHashMap");
|
||||
addRemapper("LinkedReferenceHashMap", "Reference2%sLinkedHashMap");
|
||||
addRemapper("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
|
||||
|
||||
//Test Classes
|
||||
@@ -198,6 +212,7 @@ public class MapModule extends BaseModule
|
||||
addBiRequirement("SortedMapNavigationTester");
|
||||
addBiRequirement("OrderedMapNavigationTester");
|
||||
addBiRequirement("OrderedMapMoveTester");
|
||||
addBiRequirement("OrderedMapPutTester");
|
||||
addBiRequirement("MapConstructorTester");
|
||||
|
||||
addRemapper("TestMapGenerator", "Test%sMapGenerator");
|
||||
@@ -248,6 +263,8 @@ public class MapModule extends BaseModule
|
||||
addBiClassMapper("RB_TREE_MAP", "RBTreeMap", "2");
|
||||
addFunctionValueMappers("LINKED_ENUM_MAP", valueType.isObject() ? "LinkedEnum2ObjectMap" : "LinkedEnum2%sMap");
|
||||
addFunctionValueMappers("ENUM_MAP", valueType.isObject() ? "Enum2ObjectMap" : "Enum2%sMap");
|
||||
addFunctionValueMappers("REF_MAP", valueType.isObject() ? "Reference2ObjectHashMap" : "Reference2%sHashMap");
|
||||
addFunctionValueMappers("LINKED_REF_MAP", valueType.isObject() ? "Reference2ObjectLinkedHashMap" : "Reference2%sLinkedHashMap");
|
||||
addBiClassMapper("HASH_MAP", "OpenHashMap", "2");
|
||||
addBiClassMapper("ARRAY_MAP", "ArrayMap", "2");
|
||||
|
||||
|
||||
@@ -9,6 +9,13 @@ import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
#if IARRAY_FEATURE || TYPE_OBJECT
|
||||
@@ -225,6 +232,42 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return list;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ArrayList
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, ObjectArrayList<T>, ObjectArrayList<T>> toList() {
|
||||
return Collector.of(ObjectArrayList::new, ObjectArrayList::add, ObjectArrayList::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ArrayList
|
||||
* @Type(T)
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static <T> ARRAY_LIST KEY_GENERIC_TYPE toList(Stream<T> stream) {
|
||||
return stream.collect(ObjectArrayList::new, ObjectArrayList::add, ObjectArrayList::merge);
|
||||
}
|
||||
|
||||
private ObjectArrayList<T> merge(ObjectArrayList<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ArrayList
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static ARRAY_LIST toList(JAVA_STREAM stream) {
|
||||
return stream.collect(ARRAY_LIST::new, ARRAY_LIST::add, ARRAY_LIST::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* Appends the specified element to the end of this list.
|
||||
|
||||
+41
@@ -10,6 +10,12 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Consumer;
|
||||
@@ -172,7 +178,42 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a CopyOnWriteArrayList
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, CopyOnWriteObjectArrayList<T>, CopyOnWriteObjectArrayList<T>> toList() {
|
||||
return Collector.of(CopyOnWriteObjectArrayList::new, CopyOnWriteObjectArrayList::add, CopyOnWriteObjectArrayList::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a CopyOnWriteArrayList
|
||||
* @Type(T)
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static <T> CopyOnWriteObjectArrayList KEY_GENERIC_TYPE toList(Stream<T> stream) {
|
||||
return stream.collect(CopyOnWriteObjectArrayList::new, CopyOnWriteObjectArrayList::add, CopyOnWriteObjectArrayList::merge);
|
||||
}
|
||||
|
||||
private CopyOnWriteObjectArrayList<T> merge(CopyOnWriteObjectArrayList<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a CopyOnWriteArrayList
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static COPY_ON_WRITE_LIST toList(JAVA_STREAM stream) {
|
||||
return stream.collect(COPY_ON_WRITE_LIST::new, COPY_ON_WRITE_LIST::add, COPY_ON_WRITE_LIST::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
private void setArray(KEY_TYPE[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
+50
-4
@@ -3,12 +3,25 @@ package speiger.src.collections.PACKAGE.lists;
|
||||
import java.util.Arrays;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
#else if !TYPE_BOOLEAN
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
import java.util.Collection;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if PRIMITIVES
|
||||
import java.util.function.Supplier;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.BiFunction;
|
||||
@@ -23,6 +36,7 @@ import java.util.function.PREDICATE;
|
||||
#if !JDK_FUNCTION
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
#endif
|
||||
|
||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||
#endif
|
||||
|
||||
@@ -42,10 +56,6 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#if PRIMITIVES && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
@@ -126,6 +136,42 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
data = Arrays.copyOfRange(a, offset, offset+length);
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ImmutableList
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, COLLECTION<T>, ImmutableObjectList<T>> toList() {
|
||||
return Collector.of(COLLECTIONS::wrapper, COLLECTION::add, ImmutableObjectList::merge, E -> new IMMUTABLE_LIST<>(E.toArray((T[])new Object[E.size()])));
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ImmutableList
|
||||
* @Type(T)
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static <T> ImmutableObjectList KEY_GENERIC_TYPE toList(Stream<T> stream) {
|
||||
return stream.collect(toList());
|
||||
}
|
||||
|
||||
private static <T> COLLECTION<T> merge(COLLECTION<T> a, COLLECTION<T> b) {
|
||||
a.addAll(b);
|
||||
return a;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ImmutableList
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static IMMUTABLE_LIST toList(JAVA_STREAM stream) {
|
||||
return new IMMUTABLE_LIST(stream.collect((Supplier<COLLECTION>)COLLECTIONS::wrapper, COLLECTION::add, COLLECTION::addAll).TO_ARRAY());
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,12 @@ import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
import java.util.NoSuchElementException;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
@@ -160,6 +166,42 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
for(int i = offset,m=offset+length;i<m;add(a[i++]));
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a LinkedList
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, ObjectLinkedList<T>, ObjectLinkedList<T>> toList() {
|
||||
return Collector.of(ObjectLinkedList::new, ObjectLinkedList::add, ObjectLinkedList::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a LinkedList
|
||||
* @Type(T)
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static <T> ObjectLinkedList KEY_GENERIC_TYPE toList(Stream<T> stream) {
|
||||
return stream.collect(ObjectLinkedList::new, ObjectLinkedList::add, ObjectLinkedList::merge);
|
||||
}
|
||||
|
||||
private ObjectLinkedList<T> merge(ObjectLinkedList<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a LinkedList
|
||||
* @return a list with the contents of the Stream
|
||||
*/
|
||||
public static LINKED_LIST toList(JAVA_STREAM stream) {
|
||||
return stream.collect(LINKED_LIST::new, LINKED_LIST::add, LINKED_LIST::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE e) {
|
||||
add(size(), e);
|
||||
|
||||
+30
-23
@@ -238,13 +238,13 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(containsNull) {
|
||||
VALUE_TYPE lastValue = values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, false);
|
||||
return lastValue;
|
||||
}
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
@@ -252,7 +252,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(strategy.equals(keys[pos], key)) {
|
||||
VALUE_TYPE lastValue = values[pos];
|
||||
values[pos] = value;
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, false);
|
||||
return lastValue;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -260,7 +260,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -272,13 +272,13 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(containsNull) {
|
||||
VALUE_TYPE lastValue = values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, false);
|
||||
return lastValue;
|
||||
}
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
@@ -286,7 +286,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(strategy.equals(keys[pos], key)) {
|
||||
VALUE_TYPE lastValue = values[pos];
|
||||
values[pos] = value;
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, false);
|
||||
return lastValue;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -294,7 +294,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -307,7 +307,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
@@ -318,7 +318,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -331,7 +331,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
@@ -342,7 +342,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -353,7 +353,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(isEmpty() || strategy.equals(FIRST_ENTRY_KEY(), key)) return false;
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -361,7 +361,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], key)) {
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, false);
|
||||
return true;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -375,7 +375,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
if(isEmpty() || strategy.equals(LAST_ENTRY_KEY(), key)) return false;
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -383,7 +383,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], key)) {
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, false);
|
||||
return true;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -396,7 +396,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
moveToFirstIndex(index);
|
||||
moveToFirstIndex(index, false);
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
moveToLastIndex(index);
|
||||
moveToLastIndex(index, false);
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@@ -580,8 +580,8 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
containsNull = false;
|
||||
}
|
||||
|
||||
protected void moveToFirstIndex(int startPos) {
|
||||
if(size == 1 || firstIndex == startPos) return;
|
||||
protected void moveToFirstIndex(int startPos, boolean adding) {
|
||||
if(size == (adding ? 0 : 1) || firstIndex == startPos) return;
|
||||
if(lastIndex == startPos) {
|
||||
lastIndex = (int)(links[startPos] >>> 32);
|
||||
links[lastIndex] |= 0xFFFFFFFFL;
|
||||
@@ -598,8 +598,8 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
firstIndex = startPos;
|
||||
}
|
||||
|
||||
protected void moveToLastIndex(int startPos) {
|
||||
if(size == 1 || lastIndex == startPos) return;
|
||||
protected void moveToLastIndex(int startPos, boolean adding) {
|
||||
if(size == (adding ? 0 : 1) || lastIndex == startPos) return;
|
||||
if(firstIndex == startPos) {
|
||||
firstIndex = (int)links[startPos];
|
||||
links[lastIndex] |= 0xFFFFFFFF00000000L;
|
||||
@@ -713,6 +713,10 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -1005,9 +1009,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
|
||||
+34
-24
@@ -215,13 +215,13 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(containsNull) {
|
||||
VALUE_TYPE lastValue = values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, false);
|
||||
return lastValue;
|
||||
}
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
@@ -229,7 +229,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(KEY_EQUALS(keys[pos], key)) {
|
||||
VALUE_TYPE lastValue = values[pos];
|
||||
values[pos] = value;
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, false);
|
||||
return lastValue;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -237,7 +237,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -249,13 +249,13 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(containsNull) {
|
||||
VALUE_TYPE lastValue = values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, false);
|
||||
return lastValue;
|
||||
}
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
@@ -263,7 +263,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(KEY_EQUALS(keys[pos], key)) {
|
||||
VALUE_TYPE lastValue = values[pos];
|
||||
values[pos] = value;
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, false);
|
||||
return lastValue;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -271,7 +271,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -284,18 +284,18 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NULL(key)) {
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -308,18 +308,18 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, true);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NULL(key)) {
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, true);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
@@ -330,7 +330,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(isEmpty() || KEY_EQUALS(FIRST_ENTRY_KEY(), key)) return false;
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
moveToFirstIndex(nullIndex, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -338,7 +338,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], key)) {
|
||||
moveToFirstIndex(pos);
|
||||
moveToFirstIndex(pos, false);
|
||||
return true;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -352,7 +352,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(isEmpty() || KEY_EQUALS(LAST_ENTRY_KEY(), key)) return false;
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
moveToLastIndex(nullIndex, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -360,7 +360,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], key)) {
|
||||
moveToLastIndex(pos);
|
||||
moveToLastIndex(pos, false);
|
||||
return true;
|
||||
}
|
||||
pos = ++pos & mask;
|
||||
@@ -373,7 +373,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
moveToFirstIndex(index);
|
||||
moveToFirstIndex(index, false);
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
moveToLastIndex(index);
|
||||
moveToLastIndex(index, false);
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@@ -584,8 +584,8 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
containsNull = false;
|
||||
}
|
||||
|
||||
protected void moveToFirstIndex(int startPos) {
|
||||
if(size == 1 || firstIndex == startPos) return;
|
||||
protected void moveToFirstIndex(int startPos, boolean adding) {
|
||||
if(size == (adding ? 0 : 1) || firstIndex == startPos) return;
|
||||
if(lastIndex == startPos) {
|
||||
lastIndex = (int)(links[startPos] >>> 32);
|
||||
links[lastIndex] |= 0xFFFFFFFFL;
|
||||
@@ -602,8 +602,8 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
firstIndex = startPos;
|
||||
}
|
||||
|
||||
protected void moveToLastIndex(int startPos) {
|
||||
if(size == 1 || lastIndex == startPos) return;
|
||||
protected void moveToLastIndex(int startPos, boolean adding) {
|
||||
if(size == (adding ? 0 : 1) || lastIndex == startPos) return;
|
||||
if(firstIndex == startPos) {
|
||||
firstIndex = (int)links[startPos];
|
||||
links[lastIndex] |= 0xFFFFFFFF00000000L;
|
||||
@@ -717,6 +717,10 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -1004,6 +1008,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
|
||||
+10
@@ -637,6 +637,10 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -894,6 +898,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
|
||||
+8
@@ -868,6 +868,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -1126,6 +1130,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
+8
-1
@@ -473,6 +473,10 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -637,7 +641,10 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
public boolean add(T o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(T o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(T o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(T o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
|
||||
+1581
File diff suppressed because it is too large
Load Diff
+1572
File diff suppressed because it is too large
Load Diff
+49
@@ -9,6 +9,14 @@ import java.util.function.BiFunction;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
import java.util.NoSuchElementException;
|
||||
#if JDK_FUNCTION
|
||||
@@ -105,6 +113,47 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
this(MIN_CAPACITY);
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ArrayFIFOQueue
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, ARRAY_FIFO_QUEUE<T>, ARRAY_FIFO_QUEUE<T>> toQueue() {
|
||||
return Collector.of(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ArrayFIFOQueue
|
||||
* @Type(T)
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static <T> ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE toQueue(Stream<T> stream) {
|
||||
return stream.collect(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge);
|
||||
}
|
||||
|
||||
private ARRAY_FIFO_QUEUE<T> merge(ARRAY_FIFO_QUEUE<T> a) {
|
||||
enqueueAll(a.toArray((T[])new Object[a.size()]));
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ArrayFIFOQueue
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static ARRAY_FIFO_QUEUE toQueue(JAVA_STREAM stream) {
|
||||
return stream.collect(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge);
|
||||
}
|
||||
|
||||
private ARRAY_FIFO_QUEUE merge(ARRAY_FIFO_QUEUE a) {
|
||||
enqueueAll(a.TO_ARRAY());
|
||||
return this;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new Iter();
|
||||
|
||||
+48
@@ -10,6 +10,14 @@ import java.util.function.BiFunction;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
@@ -196,7 +204,47 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
queue.size = size;
|
||||
return queue;
|
||||
}
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ArrayPriorityQueue
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, ARRAY_PRIORITY_QUEUE<T>, ARRAY_PRIORITY_QUEUE<T>> toQueue() {
|
||||
return Collector.of(ARRAY_PRIORITY_QUEUE::new, ARRAY_PRIORITY_QUEUE::enqueue, ARRAY_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ArrayPriorityQueue
|
||||
* @Type(T)
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static <T> ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE toQueue(Stream<T> stream) {
|
||||
return stream.collect(ARRAY_PRIORITY_QUEUE::new, ARRAY_PRIORITY_QUEUE::enqueue, ARRAY_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
private ARRAY_PRIORITY_QUEUE<T> merge(ARRAY_PRIORITY_QUEUE<T> a) {
|
||||
enqueueAll(a.toArray((T[])new Object[a.size()]));
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ArrayPriorityQueue
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static ARRAY_PRIORITY_QUEUE toQueue(JAVA_STREAM stream) {
|
||||
return stream.collect(ARRAY_PRIORITY_QUEUE::new, ARRAY_PRIORITY_QUEUE::enqueue, ARRAY_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
private ARRAY_PRIORITY_QUEUE merge(ARRAY_PRIORITY_QUEUE a) {
|
||||
enqueueAll(a.TO_ARRAY());
|
||||
return this;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public void enqueue(KEY_TYPE e) {
|
||||
if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (long)(array.length >> 1), (long)SanityChecks.MAX_ARRAY_SIZE), size+1));
|
||||
|
||||
+49
@@ -10,6 +10,14 @@ import java.util.function.BiFunction;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
@@ -199,6 +207,47 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
return queue;
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ArrayFIFOQueue
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, HEAP_PRIORITY_QUEUE<T>, HEAP_PRIORITY_QUEUE<T>> toQueue() {
|
||||
return Collector.of(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ArrayFIFOQueue
|
||||
* @Type(T)
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static <T> HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE toQueue(Stream<T> stream) {
|
||||
return stream.collect(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
private HEAP_PRIORITY_QUEUE<T> merge(HEAP_PRIORITY_QUEUE<T> a) {
|
||||
enqueueAll(a.toArray((T[])new Object[a.size()]));
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ArrayFIFOQueue
|
||||
* @return a queue with the contents of the Stream
|
||||
*/
|
||||
public static HEAP_PRIORITY_QUEUE toQueue(JAVA_STREAM stream) {
|
||||
return stream.collect(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge);
|
||||
}
|
||||
|
||||
private HEAP_PRIORITY_QUEUE merge(HEAP_PRIORITY_QUEUE a) {
|
||||
enqueueAll(a.TO_ARRAY());
|
||||
return this;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
|
||||
@@ -12,6 +12,12 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
@@ -214,6 +220,42 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a AVLTreeSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, AVL_TREE_SET<T>, AVL_TREE_SET<T>> toSet() {
|
||||
return Collector.of(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a AVLTreeSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> AVL_TREE_SET KEY_GENERIC_TYPE toSet(Stream<T> stream) {
|
||||
return stream.collect(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::merge);
|
||||
}
|
||||
|
||||
private AVL_TREE_SET<T> merge(AVL_TREE_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a AVLTreeSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static AVL_TREE_SET toSet(JAVA_STREAM stream) {
|
||||
return stream.collect(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE value) { defaultMaxNotFound = value; }
|
||||
|
||||
@@ -74,6 +74,16 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
return set.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) {
|
||||
set.addLast(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) {
|
||||
set.addFirst(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
#if !TYPE_OBJECT
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
|
||||
@@ -10,6 +10,12 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
import java.util.Set;
|
||||
#if JDK_FUNCTION
|
||||
@@ -74,7 +80,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
* @param array the array that should be used for set.
|
||||
*/
|
||||
public ARRAY_SET(KEY_TYPE[] array) {
|
||||
this(array, array.length);
|
||||
this(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,6 +94,18 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
addAll(array, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructur using initial Array
|
||||
* @param array the array that should be used for set.
|
||||
* @param offset the starting offset of where the array should be copied from
|
||||
* @param length the amount of elements present within the array
|
||||
* @throws NegativeArraySizeException if the length is negative
|
||||
*/
|
||||
public ARRAY_SET(KEY_TYPE[] array, int offset, int length) {
|
||||
this(length);
|
||||
addAll(array, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
|
||||
* @param c the elements that should be added to the set.
|
||||
@@ -131,6 +149,42 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = s.iterator();iter.hasNext();data[size++] = iter.NEXT());
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ArraySet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, ARRAY_SET<T>, ARRAY_SET<T>> toList() {
|
||||
return Collector.of(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ArraySet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> ARRAY_SET KEY_GENERIC_TYPE toList(Stream<T> stream) {
|
||||
return stream.collect(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::merge);
|
||||
}
|
||||
|
||||
private ARRAY_SET<T> merge(ARRAY_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ArraySet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static ARRAY_SET toList(JAVA_STREAM stream) {
|
||||
return stream.collect(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
int index = findIndex(o);
|
||||
@@ -153,6 +207,25 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) {
|
||||
int index = findIndex(o);
|
||||
if(index == -1) {
|
||||
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
||||
System.arraycopy(data, 0, data, 1, size++);
|
||||
data[0] = o;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) {
|
||||
int index = findIndex(o);
|
||||
if(index == -1) {
|
||||
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
||||
data[size++] = o;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
int index = findIndex(o);
|
||||
|
||||
+4
@@ -264,6 +264,10 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
@Override
|
||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
+82
@@ -11,6 +11,12 @@ import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
@@ -241,6 +247,82 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a LinkedCustomHashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, LINKED_CUSTOM_HASH_SET<T>, LINKED_CUSTOM_HASH_SET<T>> toLinkedSet(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return Collector.of(() -> new LINKED_CUSTOM_HASH_SET<>(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a LinkedCustomHashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE toLinkedSet(Stream<T> stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new LINKED_CUSTOM_HASH_SET<>(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
private LINKED_CUSTOM_HASH_SET<T> merge(LINKED_CUSTOM_HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a LinkedCustomHashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static LINKED_CUSTOM_HASH_SET toList(JAVA_STREAM stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new LINKED_CUSTOM_HASH_SET(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) {
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) return;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], o)) return;
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = o;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) {
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) return;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], o)) return;
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = o;
|
||||
onNodeAdded(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
|
||||
+82
@@ -7,6 +7,12 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
@@ -212,6 +218,82 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a LinkedHashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, LINKED_HASH_SET<T>, LINKED_HASH_SET<T>> toLinkedSet() {
|
||||
return Collector.of(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a LinkedHashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> LINKED_HASH_SET KEY_GENERIC_TYPE toLinkedSet(Stream<T> stream) {
|
||||
return stream.collect(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::merge);
|
||||
}
|
||||
|
||||
private LINKED_HASH_SET<T> merge(LINKED_HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a LinkedHashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static LINKED_HASH_SET toLinkedSet(JAVA_STREAM stream) {
|
||||
return stream.collect(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) {
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) return;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], o)) return;
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = o;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) {
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) return;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
|
||||
if(KEY_EQUALS(keys[pos], o)) return;
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = o;
|
||||
onNodeAdded(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
|
||||
+42
@@ -8,6 +8,12 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
@@ -257,6 +263,42 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a CustomHashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, CUSTOM_HASH_SET<T>, CUSTOM_HASH_SET<T>> toSet(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return Collector.of(() -> new CUSTOM_HASH_SET<>(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a CustomHashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> CUSTOM_HASH_SET KEY_GENERIC_TYPE toSet(Stream<T> stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new CUSTOM_HASH_SET<>(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
private CUSTOM_HASH_SET<T> merge(CUSTOM_HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a CustomHashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static CUSTOM_HASH_SET toSet(JAVA_STREAM stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new CUSTOM_HASH_SET(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* Helper getter function to get the current strategy
|
||||
|
||||
@@ -8,6 +8,12 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
@@ -224,6 +230,42 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a HashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, HASH_SET<T>, HASH_SET<T>> toSet() {
|
||||
return Collector.of(HASH_SET::new, HASH_SET::add, HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a HashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> HASH_SET KEY_GENERIC_TYPE toSet(Stream<T> stream) {
|
||||
return stream.collect(HASH_SET::new, HASH_SET::add, HASH_SET::merge);
|
||||
}
|
||||
|
||||
private HASH_SET<T> merge(HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a HashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static HASH_SET toSet(JAVA_STREAM stream) {
|
||||
return stream.collect(HASH_SET::new, HASH_SET::add, HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.SequencedSet;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.ORDERED_COLLECTION;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
@@ -23,9 +24,9 @@ import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
* @Type(T)
|
||||
*/
|
||||
#if JAVA_VERSION>=21
|
||||
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SequencedSet<CLASS_TYPE>
|
||||
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, ORDERED_COLLECTION KEY_GENERIC_TYPE, SequencedSet<CLASS_TYPE>
|
||||
#else
|
||||
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, ORDERED_COLLECTION KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,12 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
@@ -214,6 +220,42 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a RBTreeSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, RB_TREE_SET<T>, RB_TREE_SET<T>> toSet() {
|
||||
return Collector.of(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a RBTreeSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> RB_TREE_SET KEY_GENERIC_TYPE toSet(Stream<T> stream) {
|
||||
return stream.collect(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::merge);
|
||||
}
|
||||
|
||||
private RB_TREE_SET<T> merge(RB_TREE_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a RBTreeSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static RB_TREE_SET toSet(JAVA_STREAM stream) {
|
||||
return stream.collect(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE value) { defaultMaxNotFound = value; }
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.function.IntFunction;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
import speiger.src.collections.utils.Swapper;
|
||||
|
||||
/**
|
||||
* A Helper class for Arrays
|
||||
@@ -337,6 +338,69 @@ public class ARRAYS
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Shuffle method for Arrays.
|
||||
* With a Callback for indirect shuffling
|
||||
* @param array the elements that should be shuffled
|
||||
* @param swapper the callback on the swaps
|
||||
* @ArrayType(T)
|
||||
* @note This uses the SanityChecks#getRandom
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectShuffle(KEY_TYPE[] array, Swapper swapper) {
|
||||
return indirectShuffle(array, SanityChecks.getRandom(), swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Shuffle method for Arrays.
|
||||
* With a Callback for indirect shuffling
|
||||
* @param array the elements that should be shuffled
|
||||
* @param random the Random Number Generator that should be used for the shuffling
|
||||
* @param swapper the callback on the swaps
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectShuffle(KEY_TYPE[] array, RANDOM random, Swapper swapper) {
|
||||
return indirectShuffle(array, 0, array.length, random, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Shuffle method for Arrays.
|
||||
* With a Callback for indirect shuffling
|
||||
* @param array the elements that should be shuffled
|
||||
* @param length the length of the array
|
||||
* @param random the Random Number Generator that should be used for the shuffling
|
||||
* @param swapper the callback on the swaps
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectShuffle(KEY_TYPE[] array, int length, RANDOM random, Swapper swapper) {
|
||||
return indirectShuffle(array, 0, length, random, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Shuffle method for Arrays.
|
||||
* With a Callback for indirect shuffling
|
||||
* @param array the elements that should be shuffled
|
||||
* @param offset the start array
|
||||
* @param length the length of the array
|
||||
* @param random the Random Number Generator that should be used for the shuffling
|
||||
* @param swapper the callback on the swaps
|
||||
* @ArrayType(T)
|
||||
* @return the provided sorted array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectShuffle(KEY_TYPE[] array, int offset, int length, RANDOM random, Swapper swapper) {
|
||||
for(int i = length-1; i>=0;i--) {
|
||||
int j = offset + i;
|
||||
int p = offset + random.nextInt(i + 1);
|
||||
swapper.swap(j, p);
|
||||
KEY_TYPE t = array[j];
|
||||
array[j] = array[p];
|
||||
array[p] = t;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Array Reversal method
|
||||
* @param array the Array that should flip
|
||||
@@ -575,6 +639,55 @@ public class ARRAYS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Insertion Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectInsertionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectInsertionSort(array, 0, array.length, comp, swapper);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Insertion Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectInsertionSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectInsertionSort(array, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Insertion Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectInsertionSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
for (int i = from+1;i<to; i++) {
|
||||
KEY_TYPE current = array[i];
|
||||
int j = i - 1;
|
||||
while(j >= from && comp.compare(current, array[j]) < 0) {
|
||||
swapper.swap(j+1, j);
|
||||
array[j+1] = array[j--];
|
||||
}
|
||||
array[j+1] = current;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using InsertionSort,
|
||||
* @param array the array that needs to be sorted
|
||||
@@ -661,6 +774,60 @@ public class ARRAYS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Selection Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectSelectionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectSelectionSort(array, 0, array.length, comp, swapper);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Selection Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectSelectionSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectSelectionSort(array, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Selection Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* @param array the array that needs to be sorted
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectSelectionSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
for (int i = from; i < to; i++) {
|
||||
KEY_TYPE min = array[i];
|
||||
int minId = i;
|
||||
for(int j = i+1; j < to; j++) {
|
||||
if(comp.compare(array[j], min) < 0) {
|
||||
min = array[j];
|
||||
minId = j;
|
||||
}
|
||||
}
|
||||
swapper.swap(i, minId);
|
||||
KEY_TYPE temp = array[i];
|
||||
array[i] = min;
|
||||
array[minId] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using Selection Sort,
|
||||
* @param array the array that needs to be sorted
|
||||
@@ -760,6 +927,72 @@ public class ARRAYS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* 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
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectMergeSort(array, null, 0, array.length, comp, swapper);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* 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
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectMergeSort(array, null, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* 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
|
||||
* @param supp the auxillary array that is used to simplify the sorting
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
indirectInsertionSort(array, from, to, comp, swapper);
|
||||
return;
|
||||
}
|
||||
if(supp == null) supp = Arrays.copyOf(array, to);
|
||||
int mid = (from + to) >>> 1;
|
||||
indirectMergeSort(supp, array, from, mid, comp, swapper);
|
||||
indirectMergeSort(supp, array, mid, to, comp, swapper);
|
||||
if(comp.compare(supp[mid - 1], supp[mid]) <= 0)
|
||||
{
|
||||
System.arraycopy(supp, from, array, from, to - from);
|
||||
return;
|
||||
}
|
||||
for(int p = from, q = mid;from < to;from++) {
|
||||
if(q >= to || p < mid && comp.compare(supp[p], supp[q]) < 0) {
|
||||
swapper.swap(from, p);
|
||||
array[from] = supp[p++];
|
||||
continue;
|
||||
}
|
||||
swapper.swap(from, q);
|
||||
array[from] = supp[q++];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using Merge Sort,
|
||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
@@ -856,6 +1089,56 @@ public class ARRAYS
|
||||
mergeSort(array, supp, from, to, comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using a Parallel Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* 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
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectParallelMergeSort(array, null, 0, array.length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Parallel Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* 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
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @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
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectParallelMergeSort(array, null, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Parallel Merge Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* 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
|
||||
* @param supp the auxillary array that is used to simplify the sorting
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
SanityChecks.invokeTask(new MergeSortActionCompSwapBRACES(array, supp, from, to, comp, swapper));
|
||||
return;
|
||||
}
|
||||
indirectMergeSort(array, supp, from, to, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using Parallel Merge Sort,
|
||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
@@ -1209,6 +1492,73 @@ public class ARRAYS
|
||||
if((length = d - c) > 1) quickSort(array, to - length, to, comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* 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
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] indirectQuickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectQuickSort(array, 0, array.length, comp, swapper);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* 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
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectQuickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectQuickSort(array, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* 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
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectQuickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
int length = to - from;
|
||||
if(length <= 0) return;
|
||||
if(length < BASE_THRESHOLD) {
|
||||
indirectSelectionSort(array, from, to, comp, swapper);
|
||||
return;
|
||||
}
|
||||
KEY_TYPE pivot = array[length > 128 ? subMedium(array, from, from + (length / 2), to - 1, length / 8, comp) : medium(array, from, from + (length / 2), to - 1, comp)];
|
||||
int a = from, b = a, c = to - 1, d = c;
|
||||
for(int compare;;swap(array, b++, c--, swapper)) {
|
||||
for(;b<=c && (compare = comp.compare(array[b], pivot)) <= 0;b++) {
|
||||
if(compare == 0) swap(array, a++, b, swapper);
|
||||
}
|
||||
for(;c>=b && (compare = comp.compare(array[c], pivot)) >= 0;c--) {
|
||||
if(compare == 0) swap(array, c, d--, swapper);
|
||||
}
|
||||
if(b>c) break;
|
||||
}
|
||||
swap(array, from, b, Math.min(a - from, b - a), swapper);
|
||||
swap(array, b, to, Math.min(d - c, to - d - 1), swapper);
|
||||
if((length = b - a) > 1) indirectQuickSort(array, from, from + length, comp, swapper);
|
||||
if((length = d - c) > 1) indirectQuickSort(array, to - length, to, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using Quick Sort,
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
@@ -1313,6 +1663,58 @@ public class ARRAYS
|
||||
quickSort(array, from, to, comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Parallel Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* 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
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelQuickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectParallelQuickSort(array, 0, array.length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Parallel Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* 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
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelQuickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
indirectParallelQuickSort(array, 0, length, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator using Parallel Quick Sort,
|
||||
* On top of that allows to sort other things along with it.
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
* 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
|
||||
* @param from where the array should be sorted from
|
||||
* @param to where the array should be sorted to
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @param swapper the callback which elements were swapped
|
||||
* @ArrayType(T)
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void indirectParallelQuickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
SanityChecks.invokeTask(new QuickSortActionCompSwapBRACES(array, from, to, comp, swapper));
|
||||
return;
|
||||
}
|
||||
indirectQuickSort(array, from, to, comp, swapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array according to the natural ascending order using Parallel Quick Sort,
|
||||
* This implementation is a custom of <a href="https://github.com/vigna/fastutil">FastUtil</a> quicksort but with a different code structure,
|
||||
@@ -1367,6 +1769,18 @@ public class ARRAYS
|
||||
for(int i = 0;i<length;i++,swap(a, from++, to++));
|
||||
}
|
||||
|
||||
static GENERIC_KEY_BRACES void swap(KEY_TYPE[] a, int from, int to, Swapper swapper) {
|
||||
swapper.swap(from, to);
|
||||
KEY_TYPE t = a[from];
|
||||
a[from] = a[to];
|
||||
a[to] = t;
|
||||
}
|
||||
|
||||
static GENERIC_KEY_BRACES void swap(KEY_TYPE[] a, int from, int to, int length, Swapper swapper) {
|
||||
to -= length;
|
||||
for(int i = 0;i<length;i++,swap(a, from++, to++, swapper));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -1389,16 +1803,14 @@ public class ARRAYS
|
||||
int from;
|
||||
int to;
|
||||
|
||||
QuickSortAction(KEY_TYPE[] array, int from, int to)
|
||||
{
|
||||
QuickSortAction(KEY_TYPE[] array, int from, int to) {
|
||||
this.array = array;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
int length = to - from;
|
||||
if(length <= 0) return;
|
||||
if(length < BASE_THRESHOLD) {
|
||||
@@ -1431,8 +1843,7 @@ public class ARRAYS
|
||||
int to;
|
||||
COMPARATOR KEY_GENERIC_TYPE comp;
|
||||
|
||||
QuickSortActionComp(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp)
|
||||
{
|
||||
QuickSortActionComp(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
this.array = array;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
@@ -1440,8 +1851,7 @@ public class ARRAYS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
int length = to - from;
|
||||
if(length <= 0) return;
|
||||
if(length < BASE_THRESHOLD) {
|
||||
@@ -1467,6 +1877,49 @@ public class ARRAYS
|
||||
}
|
||||
}
|
||||
|
||||
static class QuickSortActionCompSwap KEY_GENERIC_TYPE extends RecursiveAction {
|
||||
private static final long serialVersionUID = 0L;
|
||||
KEY_TYPE[] array;
|
||||
int from;
|
||||
int to;
|
||||
COMPARATOR KEY_GENERIC_TYPE comp;
|
||||
Swapper swapper;
|
||||
|
||||
QuickSortActionCompSwap(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
this.array = array;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.comp = comp;
|
||||
this.swapper = swapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute() {
|
||||
int length = to - from;
|
||||
if(length <= 0) return;
|
||||
if(length < BASE_THRESHOLD) {
|
||||
indirectSelectionSort(array, from, to, comp, swapper);
|
||||
return;
|
||||
}
|
||||
KEY_TYPE pivot = array[length > 128 ? subMedium(array, from, from + (length / 2), to - 1, length / 8, comp) : medium(array, from, from + (length / 2), to - 1, comp)];
|
||||
int a = from, b = a, c = to - 1, d = c;
|
||||
for(int compare;;swap(array, b++, c--, swapper)) {
|
||||
for(;b<=c && (compare = comp.compare(array[b], pivot)) <= 0;b++) {
|
||||
if(compare == 0) swap(array, a++, b, swapper);
|
||||
}
|
||||
for(;c>=b && (compare = comp.compare(array[c], pivot)) >= 0;c--) {
|
||||
if(compare == 0) swap(array, c, d--, swapper);
|
||||
}
|
||||
if(b>c) break;
|
||||
}
|
||||
swap(array, from, b, Math.min(a - from, b - a), swapper);
|
||||
swap(array, b, to, Math.min(d - c, to - d - 1), swapper);
|
||||
if(b - a > 1 && d - c > 1) invokeAll(new QuickSortActionCompSwapBRACES(array, from, from + (b - a), comp, swapper), new QuickSortActionCompSwapBRACES(array, to - (d - c), to, comp, swapper));
|
||||
else if(b - a > 1) new QuickSortActionCompSwapBRACES(array, from, from + (b - a), comp, swapper).invoke();
|
||||
else if(d - c > 1) new QuickSortActionCompSwapBRACES(array, to - (d - c), to, comp, swapper).invoke();
|
||||
}
|
||||
}
|
||||
|
||||
static class MergeSortAction KEY_GENERIC_TYPE extends RecursiveAction {
|
||||
private static final long serialVersionUID = 0L;
|
||||
KEY_TYPE[] array;
|
||||
@@ -1474,8 +1927,7 @@ public class ARRAYS
|
||||
int from;
|
||||
int to;
|
||||
|
||||
MergeSortAction(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to)
|
||||
{
|
||||
MergeSortAction(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) {
|
||||
this.array = array;
|
||||
this.supp = supp;
|
||||
this.from = from;
|
||||
@@ -1483,8 +1935,7 @@ public class ARRAYS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to);
|
||||
return;
|
||||
@@ -1512,8 +1963,7 @@ public class ARRAYS
|
||||
int to;
|
||||
COMPARATOR KEY_GENERIC_TYPE comp;
|
||||
|
||||
MergeSortActionComp(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp)
|
||||
{
|
||||
MergeSortActionComp(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
this.array = array;
|
||||
this.supp = supp;
|
||||
this.from = from;
|
||||
@@ -1522,8 +1972,7 @@ public class ARRAYS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to, comp);
|
||||
return;
|
||||
@@ -1543,22 +1992,64 @@ public class ARRAYS
|
||||
}
|
||||
}
|
||||
|
||||
static class MergeSortActionCompSwap KEY_GENERIC_TYPE extends RecursiveAction {
|
||||
private static final long serialVersionUID = 0L;
|
||||
KEY_TYPE[] array;
|
||||
KEY_TYPE[] supp;
|
||||
int from;
|
||||
int to;
|
||||
COMPARATOR KEY_GENERIC_TYPE comp;
|
||||
Swapper swapper;
|
||||
|
||||
MergeSortActionCompSwap(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp, Swapper swapper) {
|
||||
this.array = array;
|
||||
this.supp = supp;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.comp = comp;
|
||||
this.swapper = swapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute() {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
indirectInsertionSort(array, from, to, comp, swapper);
|
||||
return;
|
||||
}
|
||||
if(supp == null) supp = Arrays.copyOf(array, to);
|
||||
int mid = (from + to) >>> 1;
|
||||
invokeAll(new MergeSortActionCompSwapBRACES(supp, array, from, mid, comp, swapper), new MergeSortActionCompSwapBRACES(supp, array, mid, to, comp, swapper));
|
||||
if(comp.compare(supp[mid - 1], supp[mid]) <= 0)
|
||||
{
|
||||
System.arraycopy(supp, from, array, from, to - from);
|
||||
return;
|
||||
}
|
||||
for(int p = from, q = mid;from < to;from++) {
|
||||
if(q >= to || p < mid && comp.compare(supp[p], supp[q]) < 0) {
|
||||
swapper.swap(from, p);
|
||||
array[from] = supp[p++];
|
||||
continue;
|
||||
}
|
||||
swapper.swap(from, q);
|
||||
array[from] = supp[q++];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class MemFreeMergeSortAction KEY_GENERIC_TYPE extends RecursiveAction {
|
||||
private static final long serialVersionUID = 0L;
|
||||
KEY_TYPE[] array;
|
||||
int from;
|
||||
int to;
|
||||
|
||||
MemFreeMergeSortAction(KEY_TYPE[] array, int from, int to)
|
||||
{
|
||||
MemFreeMergeSortAction(KEY_TYPE[] array, int from, int to) {
|
||||
this.array = array;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to);
|
||||
return;
|
||||
@@ -1604,8 +2095,7 @@ public class ARRAYS
|
||||
int to;
|
||||
COMPARATOR KEY_GENERIC_TYPE comp;
|
||||
|
||||
MemFreeMergeSortActionComp(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp)
|
||||
{
|
||||
MemFreeMergeSortActionComp(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
this.array = array;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
@@ -1613,8 +2103,7 @@ public class ARRAYS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compute()
|
||||
{
|
||||
protected void compute() {
|
||||
if(to - from < BASE_THRESHOLD) {
|
||||
insertionSort(array, from, to, comp);
|
||||
return;
|
||||
|
||||
+15
-10
@@ -7,6 +7,11 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.function.Consumer;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
@@ -299,9 +304,8 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
* @param operator that reduces the elements.
|
||||
* @return self with the reduce action applied
|
||||
*/
|
||||
public ASYNC_BUILDER KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
task = new SimpleReduceTaskBRACES(iterable.iterator(), operator);
|
||||
return this;
|
||||
public ObjectAsyncBuilder<OPTIONAL KEY_GENERIC_TYPE> reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
return new ObjectAsyncBuilder<>(new SimpleReduceTaskBRACES(iterable.iterator(), operator));
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
@@ -435,9 +439,8 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
* @param filter that decides the desired elements
|
||||
* @return self with the findFirst function applied
|
||||
*/
|
||||
public ASYNC_BUILDER KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
task = new FindFirstTaskBRACES(iterable.iterator(), filter);
|
||||
return this;
|
||||
public ObjectAsyncBuilder<OPTIONAL KEY_GENERIC_TYPE> findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
return new ObjectAsyncBuilder<>(new FindFirstTaskBRACES(iterable.iterator(), filter));
|
||||
}
|
||||
|
||||
#if INT_ASYNC_MODULE
|
||||
@@ -590,7 +593,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
#endif
|
||||
private static class SimpleReduceTask KEY_GENERIC_TYPE extends BASE_TASK KEY_GENERIC_TYPE
|
||||
private static class SimpleReduceTask KEY_GENERIC_TYPE extends BaseObjectTask<OPTIONAL KEY_GENERIC_TYPE>
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator;
|
||||
@@ -600,6 +603,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
public SimpleReduceTask(ITERATOR KEY_GENERIC_TYPE iter, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
this.iter = iter;
|
||||
this.operator = operator;
|
||||
this.setResult(OPTIONAL.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -614,7 +618,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
if(!iter.hasNext()) {
|
||||
setResult(value);
|
||||
setResult(OPTIONAL.GET_OPTIONAL(value));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -689,7 +693,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
#endif
|
||||
private static class FindFirstTask KEY_GENERIC_TYPE extends BASE_TASK KEY_GENERIC_TYPE
|
||||
private static class FindFirstTask KEY_GENERIC_TYPE extends BaseObjectTask<OPTIONAL KEY_GENERIC_TYPE>
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
PREDICATE KEY_GENERIC_TYPE filter;
|
||||
@@ -697,6 +701,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
public FindFirstTask(ITERATOR KEY_GENERIC_TYPE iter, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
this.iter = iter;
|
||||
this.filter = filter;
|
||||
this.setResult(OPTIONAL.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -704,7 +709,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
while(shouldRun() && iter.hasNext()) {
|
||||
KEY_TYPE entry = iter.NEXT();
|
||||
if(filter.test(iter.NEXT())) {
|
||||
setResult(entry);
|
||||
setResult(OPTIONAL.GET_OPTIONAL(entry));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -147,7 +147,10 @@ public class COLLECTIONS
|
||||
return new SingletonCollectionBRACES(element);
|
||||
}
|
||||
|
||||
protected static GENERIC_KEY_BRACES CollectionWrapper KEY_GENERIC_TYPE wrapper() {
|
||||
/**
|
||||
* Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES CollectionWrapper KEY_GENERIC_TYPE wrapper() {
|
||||
return new CollectionWrapperBRACES();
|
||||
}
|
||||
|
||||
|
||||
@@ -360,6 +360,10 @@ public class SETS
|
||||
s = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -651,6 +655,10 @@ public class SETS
|
||||
s = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) { synchronized(mutex) { s.addFirst(o); } }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE o) { synchronized(mutex) { s.addLast(o); } }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
|
||||
@Override
|
||||
|
||||
@@ -755,6 +755,10 @@ public class MAPS
|
||||
set = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
|
||||
+3
-1
@@ -20,6 +20,7 @@ import speiger.src.testers.PACKAGE.generators.maps.TEST_ORDERED_MAP_GENERATOR;
|
||||
import speiger.src.testers.PACKAGE.impl.maps.DERIVED_MAP_GENERATORS;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder;
|
||||
import speiger.src.testers.objects.generators.TestObjectSetGenerator;
|
||||
@@ -41,6 +42,7 @@ public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BU
|
||||
List<Class<? extends AbstractTester>> testers = super.getTesters();
|
||||
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester.class);
|
||||
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester.class);
|
||||
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester.class);
|
||||
return testers;
|
||||
}
|
||||
|
||||
@@ -77,7 +79,7 @@ public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BU
|
||||
features.addAll(parentBuilder.getFeatures());
|
||||
features.remove(SpecialFeature.COPYING);
|
||||
features.remove(SpecialFeature.CHILDREN_COPY);
|
||||
return ORDERED_MAP_TEST_BUILDER.using(new DERIVED_MAP_GENERATORS.ReverseTestOrderedMapGenerator(delegate))
|
||||
return ORDERED_MAP_TEST_BUILDER.using(new DERIVED_MAP_GENERATORS.ReverseTestOrderedMapGeneratorKV_BRACES(delegate))
|
||||
.named(parentBuilder.getName() + " reversed").withFeatures(features)
|
||||
.suppressing(parentBuilder.getSuppressedTests()).createTestSuite();
|
||||
}
|
||||
|
||||
+93
@@ -27,6 +27,8 @@ import speiger.src.collections.PACKAGE.maps.impl.concurrent.CONCURRENT_HASH_MAP;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.reference.REF_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.reference.LINKED_REF_MAP;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.maps.impl.tree.RB_TREE_MAP;
|
||||
@@ -134,6 +136,97 @@ public class MAP_CONSTRUCTOR_TESTS
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
public static class RefMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||
{
|
||||
public RefMap() {
|
||||
setSimpleConstructor(REF_MAP::new);
|
||||
setSizeConstructor(REF_MAP::new);
|
||||
setPArrayConstructor(REF_MAP::new);
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
setArrayConstructor(REF_MAP::new);
|
||||
#endif
|
||||
setPMapConstructor(REF_MAP::new);
|
||||
setMapConstructor(REF_MAP::new);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongLoadFactorSize() {
|
||||
setSizeConstructor(T -> new REF_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F));
|
||||
try {
|
||||
testSizeConstructor_smallSize();
|
||||
fail("A Constructor using a 0 LoadFactor should error");
|
||||
} catch(IllegalStateException e) {}
|
||||
|
||||
setSizeConstructor(T -> new REF_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F));
|
||||
try {
|
||||
testSizeConstructor_smallSize();
|
||||
fail("A Constructor using a 1 LoadFactor should error");
|
||||
} catch(IllegalStateException e) {}
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
protected String[] createKeyElements() {
|
||||
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
protected String[] createValueElements() {
|
||||
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
public static class LinkedRefMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||
{
|
||||
public LinkedRefMap() {
|
||||
setSimpleConstructor(LINKED_REF_MAP::new);
|
||||
setSizeConstructor(LINKED_REF_MAP::new);
|
||||
setPArrayConstructor(LINKED_REF_MAP::new);
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
setArrayConstructor(LINKED_REF_MAP::new);
|
||||
#endif
|
||||
setPMapConstructor(LINKED_REF_MAP::new);
|
||||
setMapConstructor(LINKED_REF_MAP::new);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongLoadFactorSize() {
|
||||
setSizeConstructor(T -> new LINKED_REF_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F));
|
||||
try {
|
||||
testSizeConstructor_smallSize();
|
||||
fail("A Constructor using a 0 LoadFactor should error");
|
||||
} catch(IllegalStateException e) {
|
||||
}
|
||||
|
||||
setSizeConstructor(T -> new LINKED_REF_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F));
|
||||
try {
|
||||
testSizeConstructor_smallSize();
|
||||
fail("A Constructor using a 1 LoadFactor should error");
|
||||
} catch(IllegalStateException e) {
|
||||
}
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
protected String[] createKeyElements() {
|
||||
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
protected String[] createValueElements() {
|
||||
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if VALUE_OBJECT
|
||||
public static class EnumMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester<AnEnum, String>
|
||||
#else
|
||||
|
||||
+2
@@ -27,6 +27,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester KEY_VALUE_GENERIC_TY
|
||||
|
||||
#ignore
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
@SuppressWarnings("unlikely-arg-type")
|
||||
#endignore
|
||||
public void testContainsObject_yes() {
|
||||
assertTrue("contains(present) should return true", getMap().ENTRY_SET().contains(new AbstractMap.SimpleEntry<>(e0())));
|
||||
@@ -36,6 +37,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester KEY_VALUE_GENERIC_TY
|
||||
assertFalse("contains(notPresent) should return false", getMap().ENTRY_SET().contains(e3()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unlikely-arg-type")
|
||||
public void testContainsObject_no() {
|
||||
assertFalse("contains(notPresent) should return false", getMap().ENTRY_SET().contains(new AbstractMap.SimpleEntry<>(e3())));
|
||||
}
|
||||
|
||||
+2
@@ -136,6 +136,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester KEY_VALUE_GENERIC
|
||||
#ignore
|
||||
@CollectionSize.Require(ONE)
|
||||
@MapFeature.Require(SUPPORTS_REMOVE)
|
||||
@SuppressWarnings("unlikely-arg-type")
|
||||
#endignore
|
||||
public void testRemove_supportedObjectEntryPresent() {
|
||||
assertTrue(getMap().ENTRY_SET().remove(new AbstractMap.SimpleEntry<>(e0())));
|
||||
@@ -154,6 +155,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester KEY_VALUE_GENERIC
|
||||
#ignore
|
||||
@CollectionSize.Require(ONE)
|
||||
@MapFeature.Require(SUPPORTS_REMOVE)
|
||||
@SuppressWarnings("unlikely-arg-type")
|
||||
#endignore
|
||||
public void testRemove_supportedObjectEntryMissing() {
|
||||
assertFalse(getMap().ENTRY_SET().remove(new AbstractMap.SimpleEntry<>(e3())));
|
||||
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package speiger.src.testers.PACKAGE.tests.maps;
|
||||
|
||||
#ignore
|
||||
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
|
||||
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
|
||||
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
#endignore
|
||||
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.MapFeature;
|
||||
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.objects.lists.ObjectList;
|
||||
import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER;
|
||||
import speiger.src.testers.objects.utils.ObjectHelpers;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
private ORDERED_MAP KEY_VALUE_GENERIC_TYPE orderedMap;
|
||||
private ObjectList<MAP.Entry KEY_VALUE_GENERIC_TYPE> values;
|
||||
private KEY_TYPE a;
|
||||
private VALUE_TYPE aValue;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
orderedMap = (ORDERED_MAP KEY_VALUE_GENERIC_TYPE)getMap();
|
||||
values = ObjectHelpers.copyToList(getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements()));
|
||||
if (values.size() >= 1) {
|
||||
a = values.get(0).ENTRY_KEY();
|
||||
aValue = values.get(0).ENTRY_VALUE();
|
||||
}
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testPutFirst() {
|
||||
assertEquals(aValue, orderedMap.putFirst(a, v3()));
|
||||
assertNotEquals(v3(), orderedMap.FIRST_ENTRY_VALUE());
|
||||
assertEquals(orderedMap.getDefaultReturnValue(), orderedMap.putFirst(k4(), v4()));
|
||||
assertEquals(v4(), orderedMap.FIRST_ENTRY_VALUE());
|
||||
assertEquals(e4(), orderedMap.firstEntry());
|
||||
}
|
||||
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testPutLast() {
|
||||
assertEquals(aValue, orderedMap.putLast(a, v3()));
|
||||
assertNotEquals(v3(), orderedMap.LAST_ENTRY_VALUE());
|
||||
assertEquals(orderedMap.getDefaultReturnValue(), orderedMap.putLast(k4(), v4()));
|
||||
assertEquals(v4(), orderedMap.LAST_ENTRY_VALUE());
|
||||
assertEquals(e4(), orderedMap.lastEntry());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_REMOVE)
|
||||
@CollectionSize.Require(CollectionSize.ONE)
|
||||
#endignore
|
||||
public void testPollFirst() {
|
||||
assertFalse(orderedMap.isEmpty());
|
||||
assertEquals(e0(), orderedMap.pollFirstEntry());
|
||||
assertTrue(orderedMap.isEmpty());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_REMOVE)
|
||||
@CollectionSize.Require(CollectionSize.ONE)
|
||||
#endignore
|
||||
public void testPollLast() {
|
||||
assertFalse(orderedMap.isEmpty());
|
||||
assertEquals(e0(), orderedMap.pollLastEntry());
|
||||
assertTrue(orderedMap.isEmpty());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testUnsupportedPutFirst() {
|
||||
try { orderedMap.putFirst(a, aValue); }
|
||||
catch (UnsupportedOperationException tolerated) {}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testUnsupportedPutLast() {
|
||||
try { orderedMap.putLast(a, aValue); }
|
||||
catch (UnsupportedOperationException tolerated) {}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_REMOVE)
|
||||
#endignore
|
||||
public void testUnsupportedPollFirst() {
|
||||
try { orderedMap.pollFirstEntry(); }
|
||||
catch (UnsupportedOperationException tolerated) {}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_REMOVE)
|
||||
#endignore
|
||||
public void testUnsupportedPollLast() {
|
||||
try { orderedMap.pollFirstEntry(); }
|
||||
catch (UnsupportedOperationException tolerated) {}
|
||||
expectUnchanged();
|
||||
}
|
||||
}
|
||||
+8
-3
@@ -2,6 +2,11 @@ package speiger.src.testers.PACKAGE.tests.queue.iterators;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
|
||||
#endif
|
||||
import org.junit.Ignore;
|
||||
@@ -27,17 +32,17 @@ public class FILE_KEY_TYPEQueueFindFirstTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
@CollectionSize.Require(absent = CollectionSize.ZERO)
|
||||
#endignore
|
||||
public void testQueueFindFirst_FindFirstElements() {
|
||||
assertEquals("First Element should be found", e0(), queue.findFirst(T -> KEY_EQUALS(T, e0())));
|
||||
assertEquals("First Element should be found", e0(), queue.findFirst(T -> KEY_EQUALS(T, e0())).SUPPLY_GET());
|
||||
}
|
||||
|
||||
public void testQueueFindFirst_FindNothing() {
|
||||
assertEquals("No element should be found", EMPTY_KEY_VALUE, queue.findFirst(T -> KEY_EQUALS(T, e4())));
|
||||
assertEquals("No element should be found", OPTIONAL.empty(), queue.findFirst(T -> KEY_EQUALS(T, e4())));
|
||||
}
|
||||
|
||||
#ignore
|
||||
@CollectionSize.Require(CollectionSize.SEVERAL)
|
||||
#endignore
|
||||
public void testQueueFindFirst_FindLastElement() {
|
||||
assertEquals("Last Element should be found", e2(), queue.findFirst(T -> KEY_EQUALS(T, e2())));
|
||||
assertEquals("Last Element should be found", e2(), queue.findFirst(T -> KEY_EQUALS(T, e2())).SUPPLY_GET());
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -3,10 +3,16 @@ package speiger.src.testers.PACKAGE.tests.queue.iterators;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Objects;
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
|
||||
#endif
|
||||
import org.junit.Ignore;
|
||||
|
||||
import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER;
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
|
||||
@Ignore
|
||||
@SuppressWarnings("javadoc")
|
||||
@@ -29,7 +35,7 @@ public class FILE_KEY_TYPEQueueReduceTester KEY_GENERIC_TYPE extends ABSTRACT_QU
|
||||
}
|
||||
|
||||
public void testQueueReduce() {
|
||||
assertEquals("The sum of the queue should match", getSum(), queue.reduce(this::sum));
|
||||
assertEquals("The sum of the queue should match", size == CollectionSize.ZERO ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(getSum()), queue.reduce(this::sum));
|
||||
}
|
||||
|
||||
public void testQueueExtraReduce() {
|
||||
|
||||
@@ -12,6 +12,9 @@ import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.SetFeature;
|
||||
import com.google.common.collect.testing.features.Feature;
|
||||
#if TYPE_OBJECT
|
||||
import com.google.common.collect.testing.testers.CollectionAddTester;
|
||||
import com.google.common.collect.testing.testers.CollectionAddAllTester;
|
||||
import com.google.common.collect.testing.testers.CollectionCreationTester;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
#endif
|
||||
import junit.framework.Test;
|
||||
@@ -122,6 +125,9 @@ public class SET_TESTS extends TestCase
|
||||
#ignore
|
||||
.withFeatures(getSizes(size)).withFeatures(features);
|
||||
if(nullValues) builder.withFeatures(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||
builder.suppressing(CollectionAddTester.getAddNullUnsupportedMethod(), CollectionAddTester.getAddNullSupportedMethod());
|
||||
builder.suppressing(CollectionAddAllTester.getAddAllNullUnsupportedMethod());
|
||||
builder.suppressing(CollectionCreationTester.getCreateWithNullUnsupportedMethod());
|
||||
#endignore
|
||||
return builder.createTestSuite();
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ import speiger.src.collections.PACKAGE.maps.impl.misc.ARRAY_MAP;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.reference.REF_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.reference.LINKED_REF_MAP;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.maps.impl.tree.AVL_TREE_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.tree.RB_TREE_MAP;
|
||||
@@ -104,6 +106,7 @@ public class MAP_TESTS extends TestCase
|
||||
#if TYPE_OBJECT
|
||||
constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.EnumMap.class));
|
||||
constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.LinkedEnumMap.class));
|
||||
constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.RefMap.class));
|
||||
#endif
|
||||
constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.CustomHashMap.class));
|
||||
constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.LinkedCustomHashMap.class));
|
||||
@@ -130,27 +133,29 @@ public class MAP_TESTS extends TestCase
|
||||
}
|
||||
|
||||
public static void suite(TestSuite suite) {
|
||||
suite.addTest(mapSuite("HASH_MAP", HASH_MAP::new, getFeatures(), -1, true));
|
||||
suite.addTest(orderedMapSuite("LINKED_HASH_MAP", LINKED_HASH_MAP::new, getFeatures(), -1));
|
||||
suite.addTest(orderedMapSuite("IMMUTABLE_HASH_MAP", IMMUTABLE_HASH_MAP::new, getImmutableFeatures(), -1));
|
||||
suite.addTest(mapSuite("HASH_MAP", HASH_MAP::new, getFeatures(), -1, true, true));
|
||||
suite.addTest(orderedMapSuite("LINKED_HASH_MAP", LINKED_HASH_MAP::new, getFeatures(), -1, true));
|
||||
suite.addTest(orderedMapSuite("IMMUTABLE_HASH_MAP", IMMUTABLE_HASH_MAP::new, getImmutableFeatures(), -1, true));
|
||||
#if TYPE_OBJECT
|
||||
suite.addTest(enumMapSuite("ENUM_MAP", ENUM_MAP::new, getFeatures(), 5));
|
||||
suite.addTest(enumOrderedMapSuite("LINKED_ENUM_MAP", (K, V) -> K.length <= 0 ? new LINKED_ENUM_MAP<>(AnEnum.class) : new LINKED_ENUM_MAP<>(K, V), getFeatures(), 5));
|
||||
suite.addTest(mapSuite("REF_MAP", REF_MAP::new, getFeatures(), - 1, true, false));
|
||||
suite.addTest(orderedMapSuite("LINKED_REF_MAP", LINKED_REF_MAP::new, getFeatures(), - 1, false));
|
||||
#endif
|
||||
suite.addTest(mapSuite("CUSTOM_HASH_MAP", (K, V) -> new CUSTOM_HASH_MAPKV_BRACES(K, V, HashStrategy.INSTANCE), getFeatures(), -1, true));
|
||||
suite.addTest(orderedMapSuite("LINKED_CUSTOM_HASH_MAP", (K, V) -> new LINKED_CUSTOM_HASH_MAPKV_BRACES(K, V, HashStrategy.INSTANCE), getFeatures(), -1));
|
||||
suite.addTest(orderedMapSuite("ARRAY_MAP", ARRAY_MAP::new, getFeatures(), -1));
|
||||
suite.addTest(mapSuite("CUSTOM_HASH_MAP", (K, V) -> new CUSTOM_HASH_MAPKV_BRACES(K, V, HashStrategy.INSTANCE), getFeatures(), -1, true, true));
|
||||
suite.addTest(orderedMapSuite("LINKED_CUSTOM_HASH_MAP", (K, V) -> new LINKED_CUSTOM_HASH_MAPKV_BRACES(K, V, HashStrategy.INSTANCE), getFeatures(), -1, true));
|
||||
suite.addTest(orderedMapSuite("ARRAY_MAP", ARRAY_MAP::new, getFeatures(), -1, true));
|
||||
suite.addTest(concurrentMapSuite("CONCURRENT_HASH_MAP", CONCURRENT_HASH_MAP::new, getFeatures(), 2));
|
||||
suite.addTest(concurrentMapSuite("CONCURRENT_HASH_MAP", CONCURRENT_HASH_MAP::new, getFeatures(), 3));
|
||||
suite.addTest(navigableMapSuite("RB_TREE_MAP", RB_TREE_MAP::new, getFeatures(), -1));
|
||||
suite.addTest(navigableMapSuite("AVL_TREE_MAP", AVL_TREE_MAP::new, getFeatures(), -1));
|
||||
suite.addTest(navigableMapSuite("SynchronizedRB_TREE_MAP", (K, V) -> new RB_TREE_MAPKV_BRACES(K, V).synchronize(), getLimitedFeatures(), -1));
|
||||
suite.addTest(navigableMapSuite("UnmodifiableRB_TREE_MAP", (K, V) -> new RB_TREE_MAPKV_BRACES(K, V).unmodifiable(), getLimitedImmutableFeatures(), -1));
|
||||
suite.addTest(orderedMapSuite("SynchronizedORDERED_MAP", (K, V) -> new LINKED_HASH_MAPKV_BRACES(K, V).synchronize(), getFeatures(), -1));
|
||||
suite.addTest(orderedMapSuite("UnmodifiableORDERED_MAP", (K, V) -> new LINKED_HASH_MAPKV_BRACES(K, V).unmodifiable(), getImmutableFeatures(), -1));
|
||||
suite.addTest(mapSuite("EmptyMAP", (K, V) -> MAPS.empty(), getEmptyFeatures(), 0, false));
|
||||
suite.addTest(mapSuite("SingletonMAP", (K, V) -> MAPS.singleton(K[0], V[0]), getEmptyFeatures(), 1, false));
|
||||
suite.addTest(mapSuite("AbstractMap", SIMPLE_TEST_MAP::new, getTestFeatures(), -1, false));
|
||||
suite.addTest(orderedMapSuite("SynchronizedORDERED_MAP", (K, V) -> new LINKED_HASH_MAPKV_BRACES(K, V).synchronize(), getFeatures(), -1, true));
|
||||
suite.addTest(orderedMapSuite("UnmodifiableORDERED_MAP", (K, V) -> new LINKED_HASH_MAPKV_BRACES(K, V).unmodifiable(), getImmutableFeatures(), -1, true));
|
||||
suite.addTest(mapSuite("EmptyMAP", (K, V) -> MAPS.empty(), getEmptyFeatures(), 0, false, true));
|
||||
suite.addTest(mapSuite("SingletonMAP", (K, V) -> MAPS.singleton(K[0], V[0]), getEmptyFeatures(), 1, false, true));
|
||||
suite.addTest(mapSuite("AbstractMap", SIMPLE_TEST_MAP::new, getTestFeatures(), -1, false, true));
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
@@ -209,14 +214,14 @@ public class MAP_TESTS extends TestCase
|
||||
|
||||
#endif
|
||||
|
||||
private static Test mapSuite(String name, BiFunction<KEY_STRING_TYPE[], VALUE_STRING_TYPE[], MAP KEY_VALUE_STRING_GENERIC_TYPE> factory, Collection<Feature<?>> features, int size, boolean sorted) {
|
||||
private static Test mapSuite(String name, BiFunction<KEY_STRING_TYPE[], VALUE_STRING_TYPE[], MAP KEY_VALUE_STRING_GENERIC_TYPE> factory, Collection<Feature<?>> features, int size, boolean sorted, boolean allowNullKeys) {
|
||||
SIMPLE_MAP_TEST_GENERATOR.Maps KEY_VALUE_STRING_GENERIC_TYPE generator = new SIMPLE_MAP_TEST_GENERATOR.Maps KEY_VALUE_STRING_GENERIC_TYPE(factory);
|
||||
MAP_TEST_BUILDER KEY_VALUE_STRING_GENERIC_TYPE builder = MAP_TEST_BUILDER.using(generator);
|
||||
builder.shouldBlockKeys(sorted);
|
||||
#if TYPE_OBJECT
|
||||
generator.setKeys(createKeys());
|
||||
#ignore
|
||||
builder.withFeatures(MapFeature.ALLOWS_NULL_KEYS);
|
||||
if(allowNullKeys) builder.withFeatures(MapFeature.ALLOWS_NULL_KEYS);
|
||||
#endignore
|
||||
#endif
|
||||
#if VALUE_OBJECT
|
||||
@@ -265,13 +270,13 @@ public class MAP_TESTS extends TestCase
|
||||
return builder.named(name).createTestSuite();
|
||||
}
|
||||
|
||||
private static Test orderedMapSuite(String name, BiFunction<KEY_STRING_TYPE[], VALUE_STRING_TYPE[], ORDERED_MAP KEY_VALUE_STRING_GENERIC_TYPE> factory, Collection<Feature<?>> features, int size) {
|
||||
private static Test orderedMapSuite(String name, BiFunction<KEY_STRING_TYPE[], VALUE_STRING_TYPE[], ORDERED_MAP KEY_VALUE_STRING_GENERIC_TYPE> factory, Collection<Feature<?>> features, int size, boolean allowNullKeys) {
|
||||
SIMPLE_MAP_TEST_GENERATOR.OrderedMaps KEY_VALUE_STRING_GENERIC_TYPE generator = new SIMPLE_MAP_TEST_GENERATOR.OrderedMaps KEY_VALUE_STRING_GENERIC_TYPE(factory);
|
||||
ORDERED_MAP_TEST_BUILDER KEY_VALUE_STRING_GENERIC_TYPE builder = ORDERED_MAP_TEST_BUILDER.using(generator);
|
||||
#if TYPE_OBJECT
|
||||
generator.setKeys(createKeys());
|
||||
#ignore
|
||||
builder.withFeatures(MapFeature.ALLOWS_NULL_KEYS);
|
||||
if(allowNullKeys) builder.withFeatures(MapFeature.ALLOWS_NULL_KEYS);
|
||||
#endignore
|
||||
#endif
|
||||
#if VALUE_OBJECT
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package speiger.src.collections.utils;
|
||||
|
||||
public interface Swapper {
|
||||
public void swap(int fromIndex, int toIndex);
|
||||
}
|
||||
@@ -9,8 +9,7 @@ import speiger.src.collections.ints.maps.interfaces.Int2IntNavigableMap;
|
||||
import speiger.src.collections.tests.NavigableSetTest;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public abstract class BaseInt2IntNavigableMapTest extends BaseInt2IntSortedMapTest
|
||||
{
|
||||
public abstract class BaseInt2IntNavigableMapTest extends BaseInt2IntSortedMapTest {
|
||||
@Override
|
||||
public abstract Int2IntNavigableMap createMap(int[] keys, int[] values);
|
||||
@Override
|
||||
@@ -29,30 +28,22 @@ public abstract class BaseInt2IntNavigableMapTest extends BaseInt2IntSortedMapTe
|
||||
|
||||
@Test
|
||||
public void lowerTest() {
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.LOWER)) {
|
||||
Assert.assertTrue(createMap(TEST_ARRAY, TEST_ARRAY).lowerKey(50) < 50);
|
||||
}
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.LOWER)) { Assert.assertTrue(createMap(TEST_ARRAY, TEST_ARRAY).lowerKey(50) < 50); }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void higherTest() {
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.HIGHER)) {
|
||||
Assert.assertTrue(createMap(TEST_ARRAY, TEST_ARRAY).higherKey(50) > 50);
|
||||
}
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.HIGHER)) { Assert.assertTrue(createMap(TEST_ARRAY, TEST_ARRAY).higherKey(50) > 50); }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ceilTest() {
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.CEILING)) {
|
||||
Assert.assertTrue(createMap(TEST_ARRAY, TEST_ARRAY).ceilingKey(50) >= 50);
|
||||
}
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.CEILING)) { Assert.assertTrue(createMap(TEST_ARRAY, TEST_ARRAY).ceilingKey(50) >= 50); }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void floorTest() {
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.FLOOR)) {
|
||||
Assert.assertTrue(createMap(TEST_ARRAY, TEST_ARRAY).floorKey(50) <= 50);
|
||||
}
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.FLOOR)) { Assert.assertTrue(createMap(TEST_ARRAY, TEST_ARRAY).floorKey(50) <= 50); }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,10 +23,10 @@ public abstract class BaseInt2IntOrderedMapTest extends BaseInt2IntMapTest
|
||||
{
|
||||
if(!getValidOrderedMapTests().contains(OrderedMapTests.PUT_MOVE)) return;
|
||||
Int2IntOrderedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Assert.assertEquals(0, map.putAndMoveToFirst(120, -1));
|
||||
Assert.assertEquals(-1, map.putAndMoveToFirst(120, -1));
|
||||
Assert.assertEquals(120, map.firstIntKey());
|
||||
Assert.assertEquals(-1, map.firstIntValue());
|
||||
Assert.assertEquals(0, map.putAndMoveToLast(121, -2));
|
||||
Assert.assertEquals(-1, map.putAndMoveToLast(121, -2));
|
||||
Assert.assertEquals(121, map.lastIntKey());
|
||||
Assert.assertEquals(-2, map.lastIntValue());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user