Map Tests & BugFixes.
-Added: Tests for all map implementations. -Added: Missing Map Constructors. -Fixed: Bugs with Maps & Sets. -Fixed: Gradle Java Container. -Fixed: Some javadoc stuff. -Note: SubMap/List implementation are not really well tested and most likely buggy -Changed: set JavaDoc to be quiet for now. Later goal.
This commit is contained in:
parent
aaee550ea9
commit
0b11c3929a
12
.classpath
12
.classpath
|
@ -26,6 +26,18 @@
|
|||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/builder" path="src/builder/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="builder"/>
|
||||
<attribute name="gradle_used_by_scope" value="builder"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/builder" path="src/builder/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="builder"/>
|
||||
<attribute name="gradle_used_by_scope" value="builder"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
|
|
29
.project
29
.project
|
@ -1,23 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Primitive-Collections</name>
|
||||
<comment>Project Primitive-Collections created by Buildship.</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<comment></comment>
|
||||
<projects/>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<linkedResources/>
|
||||
<filteredResources/>
|
||||
</projectDescription>
|
||||
|
|
14
build.gradle
14
build.gradle
|
@ -18,6 +18,10 @@ repositories {
|
|||
|
||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
|
||||
|
||||
javadoc {
|
||||
options.tags = [ "implSpec", "note" ]
|
||||
}
|
||||
|
||||
eclipse {
|
||||
classpath {
|
||||
downloadJavadoc = true
|
||||
|
@ -31,6 +35,12 @@ eclipse {
|
|||
}
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.compilerArgs << '-XDignore.symbol.file'
|
||||
options.fork = true // may not needed on 1.8
|
||||
options.forkOptions.executable = 'javac' // may not needed on 1.8
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
builder
|
||||
}
|
||||
|
@ -62,9 +72,11 @@ task srcJar(type: Jar) {
|
|||
}
|
||||
|
||||
javadoc.failOnError = false
|
||||
//javadoc.options.showAll()
|
||||
javadoc.options.quiet()
|
||||
|
||||
artifacts {
|
||||
archives javadocJar
|
||||
// archives javadocJar
|
||||
archives srcJar
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||
|
||||
/**
|
||||
* A Type-Specific implementation of contains. This implementation iterates over the elements and returns true if the value match.
|
||||
* @param value that should be searched for.
|
||||
* @param e the element that should be searched for.
|
||||
* @return true if the value was found.
|
||||
*/
|
||||
@Override
|
||||
|
@ -66,9 +66,9 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||
|
||||
/**
|
||||
* A Type-Specific implementation of containsAll. This implementation iterates over all elements and checks all elements are present in the other collection.
|
||||
* @param the collection that should be checked if it contains all elements.
|
||||
* @param c the collection that should be checked if it contains all elements.
|
||||
* @return true if all elements were found in the collection
|
||||
* @throws NullPointerException if the collection is null
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
|
@ -84,7 +84,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||
* @param c the elements that should be checked for
|
||||
* @return true if any element is in this collection
|
||||
* @deprecated if this is a primitive collection
|
||||
* @throws NullPointerException if the collection is null
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
@Primitive
|
||||
|
@ -100,7 +100,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection.
|
||||
* @param c the elements that should be checked for
|
||||
* @return true if any element is in this collection
|
||||
* @throws NullPointerException if the collection is null
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
|
@ -142,7 +142,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||
* A Type-Specific implementation of removeAll. This Implementation iterates over all elements and removes them as they were found in the other collection.
|
||||
* @param c the elements that should be deleted
|
||||
* @return true if the collection was modified.
|
||||
* @throws NullPointerException if the collection is null
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
|
@ -161,7 +161,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||
* A Type-Specific implementation of retainAll. This Implementation iterates over all elements and removes them as they were not found in the other collection.
|
||||
* @param c the elements that should be kept
|
||||
* @return true if the collection was modified.
|
||||
* @throws NullPointerException if the collection is null
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
|
|
|
@ -23,7 +23,7 @@ public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
|
|||
/**
|
||||
* Returns the Previous element of the iterator.
|
||||
* @return the Previous element of the iterator.
|
||||
* @throws NoSuchElementException if the iteration has no more elements
|
||||
* @throws java.util.NoSuchElementException if the iteration has no more elements
|
||||
*/
|
||||
public KEY_TYPE PREVIOUS();
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific add function to reduce (un)boxing
|
||||
* @see Collection#add(Object)
|
||||
* @param o the element that should be added
|
||||
* @return true if the element was added to the collection
|
||||
*/
|
||||
public boolean add(KEY_TYPE o);
|
||||
|
@ -27,7 +27,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||
#endif
|
||||
/**
|
||||
* A Type-Specific addAll function to reduce (un)boxing
|
||||
* @see Collection#addAll(Collection)
|
||||
* @param c the collection of elements that should be added
|
||||
* @return true if elements were added into the collection
|
||||
*/
|
||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
@ -35,7 +35,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific contains function to reduce (un)boxing
|
||||
* @see Collection#contains(Object)
|
||||
* @param o the element that is checked for
|
||||
* @return true if the element is found in the collection
|
||||
*/
|
||||
public boolean contains(KEY_TYPE o);
|
||||
|
@ -43,14 +43,14 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||
#endif
|
||||
/**
|
||||
* A Type-Specific containsAll function to reduce (un)boxing
|
||||
* @see Collection#containsAll(Object)
|
||||
* @param c the collection of elements that should be tested for
|
||||
* @return true if all the element is found in the collection
|
||||
*/
|
||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific containsAny function to reduce (un)boxing
|
||||
* @see #containsAny(Collection)
|
||||
* @param c the collection of elements that should be tested for
|
||||
* @return true if any element was found
|
||||
*/
|
||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
@ -58,6 +58,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||
/**
|
||||
* Returns true if any element of the Collection is found in the provided collection.
|
||||
* A Small Optimization function to find out of any element is present when comparing collections and not all of them.
|
||||
* @param c the collection of elements that should be tested for
|
||||
* @return true if any element was found.
|
||||
*/
|
||||
@Primitive
|
||||
|
@ -66,6 +67,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific remove function that reduces (un)boxing.
|
||||
* @param o the element that should be removed
|
||||
* @return true if the element was removed
|
||||
* @see Collection#remove(Object)
|
||||
*/
|
||||
|
@ -74,6 +76,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||
#endif
|
||||
/**
|
||||
* A Type-Specific removeAll function that reduces (un)boxing.
|
||||
* @param c the collection of elements that should be removed
|
||||
* @return true if any element was removed
|
||||
* @see Collection#removeAll(Collection)
|
||||
*/
|
||||
|
@ -81,6 +84,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||
|
||||
/**
|
||||
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||
* @param c the collection of elements that should be kept
|
||||
* @return true if any element was removed
|
||||
* @see Collection#retainAll(Collection)
|
||||
*/
|
||||
|
@ -123,7 +127,8 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||
* <p>Removes elements that were selected by the filter
|
||||
* @see Collection#removeIf(Predicate)
|
||||
* @param filter Filters the elements that should be removed
|
||||
* @throws NullPointerException if filter is null
|
||||
* @return true if the collection was modified
|
||||
* @throws java.lang.NullPointerException if filter is null
|
||||
*/
|
||||
public default boolean remIf(JAVA_PREDICATE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
|
|
|
@ -19,7 +19,7 @@ public interface ITERATOR KEY_GENERIC_TYPE extends Iterator<CLASS_TYPE>
|
|||
* Returns the next element in the iteration.
|
||||
*
|
||||
* @return the next element in the iteration
|
||||
* @throws NoSuchElementException if the iteration has no more elements
|
||||
* @throws java.util.NoSuchElementException if the iteration has no more elements
|
||||
* @see Iterator#next()
|
||||
*/
|
||||
public KEY_TYPE NEXT();
|
||||
|
@ -45,7 +45,7 @@ public interface ITERATOR KEY_GENERIC_TYPE extends Iterator<CLASS_TYPE>
|
|||
* }</pre>
|
||||
*
|
||||
* @param action The action to be performed for each element
|
||||
* @throws NullPointerException if the specified action is null
|
||||
* @throws java.lang.NullPointerException if the specified action is null
|
||||
* @see Iterator#forEachRemaining(Consumer)
|
||||
*/
|
||||
public default void forEachRemaining(CONSUMER action) {
|
||||
|
|
|
@ -61,7 +61,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||
|
||||
/**
|
||||
* The IndexOf implementation iterates over all elements and compares them to the search value.
|
||||
* @param e the value that the index is searched for.
|
||||
* @param o the value that the index is searched for.
|
||||
* @return index of the value that was searched for. -1 if not found
|
||||
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||
*/
|
||||
|
@ -89,7 +89,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||
|
||||
/**
|
||||
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
|
||||
* @param e the value that the index is searched for.
|
||||
* @param o the value that the index is searched for.
|
||||
* @return the last index of the value that was searched for. -1 if not found
|
||||
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||
*/
|
||||
|
|
|
@ -126,13 +126,18 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
|
||||
/**
|
||||
* Creates a wrapped arraylist that uses the array as backing array
|
||||
* @param a elements that should be wrapped
|
||||
* @return a Wrapped list using the input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
|
||||
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE... a) {
|
||||
return wrap(a, a.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a wrapped arraylist that uses the array as backing array and a custom fillsize
|
||||
* @param a elements that should be wrapped
|
||||
* @param length the size of the elements within the array
|
||||
* @return a Wrapped list using the input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int length) {
|
||||
SanityChecks.checkArrayCapacity(a.length, 0, length);
|
||||
|
@ -145,6 +150,8 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a new ArrayList with a EmptyObject array of the Type requested
|
||||
* @param c the type of the array
|
||||
* @return a typed List
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c) {
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
|
@ -194,7 +201,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
* Appends the specified elements to the index of the list.
|
||||
* This function may delegate to more appropiate function if nessesary
|
||||
* @param index the index where to append the elements to
|
||||
* @param e the elements to append to the list
|
||||
* @param c the elements to append to the list
|
||||
* @throws IndexOutOfBoundsException if index is outside of the lists range
|
||||
* @deprecated if type is primitive
|
||||
*/
|
||||
|
@ -216,7 +223,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
* Appends the specified elements to the index of the list.
|
||||
* This function may delegate to more appropiate function if nessesary
|
||||
* @param index the index where to append the elements to
|
||||
* @param e the elements to append to the list
|
||||
* @param c the elements to append to the list
|
||||
* @throws IndexOutOfBoundsException if index is outside of the lists range
|
||||
* @deprecated if type is primitive
|
||||
*/
|
||||
|
@ -236,7 +243,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
/**
|
||||
* Appends the specified elements to the index of the list.
|
||||
* @param index the index where to append the elements to
|
||||
* @param e the elements to append to the list
|
||||
* @param c the elements to append to the list
|
||||
* @throws IndexOutOfBoundsException if index is outside of the lists range
|
||||
* @deprecated if type is primitive
|
||||
*/
|
||||
|
@ -277,7 +284,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
* @param a the array where the values should be inserted to
|
||||
* @param offset the startIndex of where the array should be written to
|
||||
* @param length the number of elements the values should be fetched from
|
||||
* @returns the inputArray
|
||||
* @return the inputArray
|
||||
* @throws NullPointerException if the array is null
|
||||
* @throws IndexOutOfBoundsException if from is outside of the lists range
|
||||
* @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length
|
||||
|
@ -353,7 +360,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
|
||||
/**
|
||||
* A function to find if the Element is present in this list.
|
||||
* @param e the element that is searched for
|
||||
* @param o the element that is searched for
|
||||
* @return if the element was found.
|
||||
* @deprecated if type-specific but still supported because of special edgecase Object-Comparason features
|
||||
*/
|
||||
|
@ -365,7 +372,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
|
||||
/**
|
||||
* A function to find the index of a given element
|
||||
* @param e the element that is searched for
|
||||
* @param o the element that is searched for
|
||||
* @return the index of the element if found. (if not found then -1)
|
||||
* @deprecated if type-specific but still supported because of special edgecase Object-Comparason features
|
||||
*/
|
||||
|
@ -389,7 +396,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
|
||||
/**
|
||||
* A function to find the last index of a given element
|
||||
* @param e the element that is searched for
|
||||
* @param o the element that is searched for
|
||||
* @return the last index of the element if found. (if not found then -1)
|
||||
* @deprecated if type-specific but still supported because of special edgecase Object-Comparason features
|
||||
*/
|
||||
|
@ -414,6 +421,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Sorts the elements specified by the Natural order either by using the Comparator or the elements
|
||||
* @param c the sorter of the elements, can be null
|
||||
* @see List#sort(Comparator)
|
||||
* @see ARRAYS#stableSort(KEY_TYPE[], Comparator)
|
||||
*/
|
||||
|
@ -425,6 +433,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
|
||||
/**
|
||||
* Sorts the elements specified by the Natural order either by using the Comparator or the elements using a unstable sort
|
||||
* @param c the sorter of the elements, can be null
|
||||
* @see List#sort(Comparator)
|
||||
* @see ARRAYS#unstableSort(KEY_TYPE[], Comparator)
|
||||
*/
|
||||
|
@ -437,8 +446,8 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
#else
|
||||
/**
|
||||
* A Type Specific implementation of the Collection#contains function.
|
||||
* @param the element that is searched for.
|
||||
* @returns if the element was found
|
||||
* @param e the element that is searched for.
|
||||
* @return if the element was found
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) {
|
||||
|
@ -473,8 +482,9 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
|
||||
/**
|
||||
* Sorts the elements specified by the Natural order either by using the Comparator or the elements
|
||||
* @param c the sorter of the elements, can be null
|
||||
* @see List#sort(Comparator)
|
||||
* @see ARRAYS#stableSort(KEY_TYPE[], Comparator)
|
||||
* @see ARRAYS#stableSort(KEY_TYPE[], COMPARATOR)
|
||||
*/
|
||||
@Override
|
||||
public void sort(COMPARATOR c) {
|
||||
|
@ -484,8 +494,9 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
|
||||
/**
|
||||
* Sorts the elements specified by the Natural order either by using the Comparator or the elements using a unstable sort
|
||||
* @param c the sorter of the elements, can be null
|
||||
* @see List#sort(Comparator)
|
||||
* @see ARRAYS#unstableSort(KEY_TYPE[], Comparator)
|
||||
* @see ARRAYS#unstableSort(KEY_TYPE[], COMPARATOR)
|
||||
*/
|
||||
@Override
|
||||
public void unstableSort(COMPARATOR c) {
|
||||
|
@ -541,7 +552,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
* }</pre>
|
||||
*
|
||||
* @param action The action to be performed for each element
|
||||
* @throws NullPointerException if the specified action is null
|
||||
* @throws java.util.NullPointerException if the specified action is null
|
||||
* @see Iterable#forEach(Consumer)
|
||||
*/
|
||||
@Override
|
||||
|
|
|
@ -46,7 +46,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
|||
* @param c the elements that need to be added
|
||||
* @param index index at which the specified elements is to be inserted
|
||||
* @return true if the list was modified
|
||||
* @see List#addAll(int, Object)
|
||||
* @see java.util.List#addAll(int, Collection)
|
||||
*/
|
||||
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
|
@ -78,7 +78,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
|||
/**
|
||||
* A Type-Specific set function to reduce (un)boxing
|
||||
* @param index index of the element to replace
|
||||
* @param element element to be stored at the specified position
|
||||
* @param e element to be stored at the specified position
|
||||
* @return the element previously at the specified position
|
||||
* @throws IndexOutOfBoundsException if the index is not within the list range
|
||||
* @see List#set(int, Object)
|
||||
|
@ -141,13 +141,20 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
|||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A function to fast add elements to the list
|
||||
* @param a the elements that should be added
|
||||
* @throws IndexOutOfBoundsException if from is outside of the lists range
|
||||
*/
|
||||
public default void addElements(KEY_TYPE... a) { addElements(0, a, 0, a.length); }
|
||||
|
||||
/**
|
||||
* A function to fast add elements to the list
|
||||
* @param from the index where the elements should be added into the list
|
||||
* @param a the elements that should be added
|
||||
* @throws IndexOutOfBoundsException if from is outside of the lists range
|
||||
*/
|
||||
public default void addElements(int from, KEY_TYPE[] a) { addElements(from, a, 0, a.length); }
|
||||
public default void addElements(int from, KEY_TYPE... a) { addElements(from, a, 0, a.length); }
|
||||
|
||||
/**
|
||||
* A function to fast add elements to the list
|
||||
|
@ -164,7 +171,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
|||
* A function to fast fetch elements from the list
|
||||
* @param from index where the list should be fetching elements from
|
||||
* @param a the array where the values should be inserted to
|
||||
* @returns the inputArray
|
||||
* @return the inputArray
|
||||
* @throws NullPointerException if the array is null
|
||||
* @throws IndexOutOfBoundsException if from is outside of the lists range
|
||||
* @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length
|
||||
|
@ -177,7 +184,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
|||
* @param a the array where the values should be inserted to
|
||||
* @param offset the startIndex of where the array should be written to
|
||||
* @param length the number of elements the values should be fetched from
|
||||
* @returns the inputArray
|
||||
* @return the inputArray
|
||||
* @throws NullPointerException if the array is null
|
||||
* @throws IndexOutOfBoundsException if from is outside of the lists range
|
||||
* @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length
|
||||
|
@ -255,8 +262,9 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
|||
|
||||
/**
|
||||
* Sorts the elements specified by the Natural order either by using the Comparator or the elements
|
||||
* @param c the sorter of the elements, can be null
|
||||
* @see List#sort(Comparator)
|
||||
* @see ARRAYS#stableSort(KEY_TYPE[], Comparator)
|
||||
* @see ARRAYS#stableSort(KEY_TYPE[], COMPARATOR)
|
||||
*/
|
||||
public default void sort(COMPARATOR c) {
|
||||
KEY_TYPE[] array = TO_ARRAY();
|
||||
|
@ -280,8 +288,9 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
|||
|
||||
/**
|
||||
* Sorts the elements specified by the Natural order either by using the Comparator or the elements using a unstable sort
|
||||
* @param c the sorter of the elements, can be null
|
||||
* @see List#sort(Comparator)
|
||||
* @see ARRAYS#unstableSort(KEY_TYPE[], Comparator)
|
||||
* @see ARRAYS#unstableSort(KEY_TYPE[], COMPARATOR)
|
||||
*/
|
||||
public default void unstableSort(COMPARATOR c) {
|
||||
KEY_TYPE[] array = TO_ARRAY();
|
||||
|
|
|
@ -92,7 +92,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||
|
||||
@Override
|
||||
public boolean replace(KEY_TYPE key, VALUE_TYPE oldValue, VALUE_TYPE newValue) {
|
||||
VALUE_TYPE curValue = get(key);
|
||||
VALUE_TYPE curValue = GET_VALUE(key);
|
||||
if (VALUE_EQUALS_NOT(curValue, oldValue) || (VALUE_EQUALS(curValue, getDefaultReturnValue()) && !containsKey(key))) {
|
||||
return false;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||
@Override
|
||||
public VALUE_TYPE replace(KEY_TYPE key, VALUE_TYPE value) {
|
||||
VALUE_TYPE curValue;
|
||||
if (VALUE_EQUALS_NOT((curValue = get(key)), getDefaultReturnValue()) || containsKey(key)) {
|
||||
if (VALUE_EQUALS_NOT((curValue = GET_VALUE(key)), getDefaultReturnValue()) || containsKey(key)) {
|
||||
curValue = put(key, value);
|
||||
}
|
||||
return curValue;
|
||||
|
@ -121,7 +121,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
VALUE_TYPE value = get(key);
|
||||
VALUE_TYPE value = GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(VALUE_EQUALS_NOT(value, getDefaultReturnValue()) || containsKey(key)) {
|
||||
|
@ -138,7 +138,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
VALUE_TYPE value;
|
||||
if((value = get(key)) == getDefaultReturnValue()) {
|
||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
|
@ -152,7 +152,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
VALUE_TYPE value;
|
||||
if(VALUE_EQUALS_NOT((value = get(key)), getDefaultReturnValue())) {
|
||||
if(VALUE_EQUALS_NOT((value = GET_VALUE(key)), getDefaultReturnValue()) || containsKey(key)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, value);
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
|
@ -166,7 +166,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
VALUE_TYPE oldValue = get(key);
|
||||
VALUE_TYPE oldValue = GET_VALUE(key);
|
||||
VALUE_TYPE newValue = VALUE_EQUALS(oldValue, getDefaultReturnValue()) ? value : mappingFunction.APPLY_VALUE(oldValue, value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) remove(key);
|
||||
else put(key, newValue);
|
||||
|
|
|
@ -105,6 +105,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
|
@ -120,6 +121,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);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
|
@ -137,6 +139,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
|
@ -152,6 +155,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);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
|
@ -305,7 +309,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(values == null) valuesC = new Values();
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
}
|
||||
|
||||
|
@ -425,8 +429,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
VALUE_TYPE[] newValues = NEW_VALUE_ARRAY(newSize + 1);
|
||||
long[] newLinks = new long[newSize + 1];
|
||||
int newPrev = -1;
|
||||
for(int j = size, i = firstIndex, pos = 0, prev = -1;j != 0;) {
|
||||
int i = firstIndex, prev = -1, newPrev = -1, pos;
|
||||
firstIndex = -1;
|
||||
for(int j = size; j-- != 0;) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) pos = newSize;
|
||||
else {
|
||||
pos = HashUtil.mix(strategy.hashCode(keys[i])) & newMask;
|
||||
|
@ -452,6 +457,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||
mask = newMask;
|
||||
maxFill = Math.min((int)Math.ceil(nullIndex * loadFactor), nullIndex - 1);
|
||||
keys = newKeys;
|
||||
values = newValues;
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements SORTED_MAP.FastSortedSet KEY_VALUE_GENERIC_TYPE {
|
||||
|
@ -761,7 +767,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||
}
|
||||
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry(nextEntry());
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
|
|
|
@ -154,7 +154,11 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
@Override
|
||||
@Deprecated
|
||||
public boolean containsKey(Object key) {
|
||||
return findIndex(key) >= 0;
|
||||
#if !TYPE_OBJECT
|
||||
return key instanceof CLASS_TYPE && findIndex(CLASS_TO_KEY(key)) >= 0;
|
||||
#else
|
||||
return findIndex(CLASS_TO_KEY(key)) >= 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
|
@ -186,7 +190,10 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
@Override
|
||||
@Deprecated
|
||||
public CLASS_VALUE_TYPE remove(Object key) {
|
||||
int slot = findIndex(key);
|
||||
#if !TYPE_OBJECT
|
||||
if(!(key instanceof CLASS_TYPE)) return getDefaultReturnValue();
|
||||
#endif
|
||||
int slot = findIndex(CLASS_TO_KEY(key));
|
||||
if(slot < 0) return VALUE_TO_OBJ(getDefaultReturnValue());
|
||||
return removeIndex(slot);
|
||||
}
|
||||
|
@ -228,6 +235,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
}
|
||||
return false;
|
||||
}
|
||||
#if !TYPE_OBJECT
|
||||
if(!(key instanceof CLASS_TYPE)) return false;
|
||||
#endif
|
||||
KEY_TYPE keyType = CLASS_TO_KEY(key);
|
||||
int pos = HashUtil.mix(strategy.hashCode(keyType)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
|
@ -253,14 +263,17 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE get(Object key) {
|
||||
int slot = findIndex(key);
|
||||
#if !TYPE_OBJECT
|
||||
if(!(key instanceof CLASS_TYPE)) return getDefaultReturnValue();
|
||||
#endif
|
||||
int slot = findIndex(CLASS_TO_KEY(key));
|
||||
return VALUE_TO_OBJ(slot < 0 ? getDefaultReturnValue() : values[slot]);
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
|
||||
int slot = findIndex(key);
|
||||
int slot = findIndex(CLASS_TO_KEY(key));
|
||||
return slot < 0 ? defaultValue : values[slot];
|
||||
}
|
||||
|
||||
|
@ -299,6 +312,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() { return size; }
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if(size == 0) return;
|
||||
|
@ -322,7 +338,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
}
|
||||
|
||||
#endif
|
||||
protected int findIndex(Object key) {
|
||||
protected int findIndex(CLASS_TYPE key) {
|
||||
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||
KEY_TYPE keyType = CLASS_TO_KEY(key);
|
||||
int pos = HashUtil.mix(strategy.hashCode(keyType)) & mask;
|
||||
|
@ -645,14 +661,14 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
public void forEach(Consumer VALUE_SUPER_GENERIC_TYPE action) {
|
||||
if(containsNull) action.accept(values[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--)
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i]);
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i]);
|
||||
}
|
||||
#else
|
||||
@Override
|
||||
public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) {
|
||||
if(containsNull) action.accept(values[nullIndex]);
|
||||
for(int i = nullIndex-1;i>=0;i--)
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i]);
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
|
@ -122,6 +123,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);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
|
@ -139,6 +141,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
|
@ -154,6 +157,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);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
|
@ -307,7 +311,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(values == null) valuesC = new Values();
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
}
|
||||
|
||||
|
@ -427,8 +431,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
VALUE_TYPE[] newValues = NEW_VALUE_ARRAY(newSize + 1);
|
||||
long[] newLinks = new long[newSize + 1];
|
||||
int newPrev = -1;
|
||||
for(int j = size, i = firstIndex, pos = 0, prev = -1;j != 0;) {
|
||||
int i = firstIndex, prev = -1, newPrev = -1, pos;
|
||||
firstIndex = -1;
|
||||
for(int j = size; j-- != 0;) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) pos = newSize;
|
||||
else {
|
||||
pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask;
|
||||
|
@ -454,6 +459,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||
mask = newMask;
|
||||
maxFill = Math.min((int)Math.ceil(nullIndex * loadFactor), nullIndex - 1);
|
||||
keys = newKeys;
|
||||
values = newValues;
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements SORTED_MAP.FastSortedSet KEY_VALUE_GENERIC_TYPE {
|
||||
|
@ -763,7 +769,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||
}
|
||||
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry(nextEntry());
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
|
|
|
@ -295,6 +295,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() { return size; }
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if(size == 0) return;
|
||||
|
|
|
@ -12,6 +12,7 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
|||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
|
@ -19,6 +20,7 @@ import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
|||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
|
@ -26,6 +28,9 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
|||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
||||
#endif
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||
|
@ -33,6 +38,7 @@ import speiger.src.collections.objects.sets.AbstractObjectSet;
|
|||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#endif
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
|
||||
public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
|
@ -43,6 +49,57 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
protected VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
protected FastSortedSet KEY_VALUE_GENERIC_TYPE entrySet;
|
||||
|
||||
public ARRAY_MAP() {
|
||||
this(HashUtil.DEFAULT_MIN_CAPACITY);
|
||||
}
|
||||
|
||||
public ARRAY_MAP(int minCapacity) {
|
||||
if(minCapacity < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed");
|
||||
keys = NEW_KEY_ARRAY(minCapacity);
|
||||
values = NEW_VALUE_ARRAY(minCapacity);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
public ARRAY_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) {
|
||||
this(keys, values, keys.length);
|
||||
}
|
||||
|
||||
public ARRAY_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, int length) {
|
||||
this(length);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
size = length;
|
||||
for(int i = 0,m=length;i<m;i++) {
|
||||
this.keys[i] = OBJ_TO_KEY(keys[i]);
|
||||
this.values[i] = OBJ_TO_VALUE(values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
public ARRAY_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) {
|
||||
this(keys, values, keys.length);
|
||||
}
|
||||
|
||||
public ARRAY_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, int length) {
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
this.keys = Arrays.copyOf(keys, length);
|
||||
this.values = Arrays.copyOf(values, length);
|
||||
this.size = length;
|
||||
}
|
||||
|
||||
public ARRAY_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||
this(map.size());
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
public ARRAY_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
this(map.size());
|
||||
for(ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = MAPS.fastIterator(map);iter.hasNext();size++) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = iter.next();
|
||||
keys[size] = entry.ENTRY_KEY();
|
||||
values[size] = entry.ENTRY_VALUE();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value) {
|
||||
int index = findIndex(key);
|
||||
|
@ -106,7 +163,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index >= 0) {
|
||||
if(index > 0) {
|
||||
moveIndexToFirst(index);
|
||||
return true;
|
||||
}
|
||||
|
@ -116,7 +173,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index >= 0) {
|
||||
if(index < size-1) {
|
||||
moveIndexToLast(index);
|
||||
return true;
|
||||
}
|
||||
|
@ -205,13 +262,13 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
@Override
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() {
|
||||
if(size <= 0) throw new NoSuchElementException();
|
||||
return values[size-1];
|
||||
return values[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() {
|
||||
if(size <= 0) throw new NoSuchElementException();
|
||||
return values[0];
|
||||
return values[size-1];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -266,6 +323,13 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) {
|
||||
if(size() <= 0) return;
|
||||
for(int i = 0;i<size;i++)
|
||||
action.accept(keys[i], values[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keySet == null) keySet = new KeySet();
|
||||
|
@ -518,7 +582,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index >= 0) {
|
||||
if(index > 0) {
|
||||
moveIndexToFirst(index);
|
||||
return true;
|
||||
}
|
||||
|
@ -528,7 +592,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
if(index >= 0) {
|
||||
if(index < size()-1) {
|
||||
moveIndexToLast(index);
|
||||
return true;
|
||||
}
|
||||
|
@ -650,6 +714,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE value = values[index];
|
||||
removeIndex(index);
|
||||
length--;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -659,6 +724,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
int index = findIndex(key, value);
|
||||
if(index < 0) return false;
|
||||
removeIndex(index);
|
||||
length--;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -669,6 +735,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
if(index < 0) return VALUE_TO_OBJ(getDefaultReturnValue());
|
||||
VALUE_TYPE value = values[index];
|
||||
removeIndex(index);
|
||||
length--;
|
||||
return VALUE_TO_OBJ(value);
|
||||
}
|
||||
|
||||
|
@ -677,6 +744,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
int index = findIndex(key, value);
|
||||
if(index < 0) return false;
|
||||
removeIndex(index);
|
||||
length--;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -750,8 +818,8 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
if(index == length-1) return;
|
||||
KEY_TYPE key = keys[index];
|
||||
VALUE_TYPE value = values[index];
|
||||
System.arraycopy(keys, offset+index+1, keys, offset+index, length-index-1);
|
||||
System.arraycopy(values, offset+index+1, values, offset+index, length-index-1);
|
||||
System.arraycopy(keys, index+1, keys, index, end()-index-1);
|
||||
System.arraycopy(values, index+1, values, index, end()-index-1);
|
||||
keys[end()-1] = key;
|
||||
values[end()-1] = value;
|
||||
}
|
||||
|
@ -767,7 +835,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
#if !TYPE_OBJECT
|
||||
protected int findIndex(KEY_TYPE key) {
|
||||
for(int i = length-1;i>=0;i--)
|
||||
if(KEY_EQUALS(keys[offset+i], key)) return i;
|
||||
if(KEY_EQUALS(keys[offset+i], key)) return i+offset;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -775,7 +843,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
#if !VALUE_OBJECT
|
||||
protected int findValue(VALUE_TYPE value) {
|
||||
for(int i = length-1;i>=0;i--)
|
||||
if(VALUE_EQUALS(values[offset+i], value)) return i;
|
||||
if(VALUE_EQUALS(values[offset+i], value)) return i+offset;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -783,21 +851,21 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
protected int findIndex(Object key, Object value) {
|
||||
if(key == null || value == null) return -1;
|
||||
for(int i = length-1;i>=0;i--)
|
||||
if(EQUALS_KEY_TYPE(keys[offset+i], key) && EQUALS_VALUE_TYPE(values[offset+i], value)) return i;
|
||||
if(EQUALS_KEY_TYPE(keys[offset+i], key) && EQUALS_VALUE_TYPE(values[offset+i], value)) return i+offset;
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected int findIndex(Object key) {
|
||||
if(key == null) return -1;
|
||||
for(int i = length-1;i>=0;i--)
|
||||
if(EQUALS_KEY_TYPE(keys[offset+i], key)) return i;
|
||||
if(EQUALS_KEY_TYPE(keys[offset+i], key)) return i+offset;
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected int findValue(Object value) {
|
||||
if(value == null) return -1;
|
||||
for(int i = length-1;i>=0;i--)
|
||||
if(EQUALS_VALUE_TYPE(values[offset+i], value)) return i;
|
||||
if(EQUALS_VALUE_TYPE(values[offset+i], value)) return i+offset;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1371,13 +1439,13 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
for(int i = 0;i<size;action.accept(keys[i]));
|
||||
for(int i = 0;i<size;action.accept(keys[i++]));
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_GENERIC_TYPE action) {
|
||||
for(int i = 0;i<size;action.accept(keys[i]));
|
||||
for(int i = 0;i<size;action.accept(keys[i++]));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1428,12 +1496,12 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
#if VALUE_OBJECT
|
||||
@Override
|
||||
public void forEach(Consumer<? super CLASS_VALUE_TYPE> action) {
|
||||
for(int i = 0;i<size;action.accept(values[i]));
|
||||
for(int i = 0;i<size;action.accept(values[i++]));
|
||||
}
|
||||
#else
|
||||
@Override
|
||||
public void forEach(VALUE_CONSUMER VALUE_GENERIC_TYPE action) {
|
||||
for(int i = 0;i<size;action.accept(values[i]));
|
||||
for(int i = 0;i<size;action.accept(values[i++]));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import speiger.src.collections.objects.maps.abstracts.ABSTRACT_MAP;
|
|||
import speiger.src.collections.objects.maps.interfaces.MAP;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
//import sun.misc.SharedSecrets;
|
||||
import sun.misc.SharedSecrets;
|
||||
|
||||
public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
|
@ -183,8 +183,8 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||
}
|
||||
protected boolean isSet(int index) { return (present[index >> 6] & (1L << index)) != 0; }
|
||||
private static <K extends Enum<K>> K[] getKeyUniverse(Class<K> keyType) {
|
||||
return keyType.getEnumConstants();
|
||||
// return SharedSecrets.getJavaLangAccess().getEnumConstantsShared(keyType);
|
||||
// return keyType.getEnumConstants();
|
||||
return SharedSecrets.getJavaLangAccess().getEnumConstantsShared(keyType);
|
||||
}
|
||||
|
||||
class EntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
|
|
|
@ -58,6 +58,54 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
protected NAVIGABLE_SET KEY_GENERIC_TYPE keySet;
|
||||
protected VALUE_COLLECTION VALUE_GENERIC_TYPE values;
|
||||
protected ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> entrySet;
|
||||
|
||||
public AVL_TREE_MAP() {
|
||||
}
|
||||
|
||||
public AVL_TREE_MAP(COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
public AVL_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) {
|
||||
this(keys, values, null);
|
||||
}
|
||||
|
||||
public AVL_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
for(int i = 0,m=keys.length;i<m;i++) put(OBJ_TO_KEY(keys[i]), OBJ_TO_VALUE(values[i]));
|
||||
}
|
||||
|
||||
#endif
|
||||
public AVL_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) {
|
||||
this(keys, values, null);
|
||||
}
|
||||
|
||||
public AVL_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
for(int i = 0,m=keys.length;i<m;i++) put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
public AVL_TREE_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||
this(map, null);
|
||||
}
|
||||
|
||||
public AVL_TREE_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
public AVL_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
this(map, null);
|
||||
}
|
||||
|
||||
public AVL_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
public KEY_TYPE getDefaultMaxValue() { return defaultMaxNotFound; }
|
||||
public KEY_TYPE getDefaultMinValue() { return defaultMinNotFound; }
|
||||
|
@ -324,6 +372,17 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public int size() { return size; }
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
size = 0;
|
||||
first = null;
|
||||
last = null;
|
||||
tree = null;
|
||||
}
|
||||
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE keyIterator(boolean descending) {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE iter = new KeyIterator(descending);
|
||||
return descending ? ITERATORS.invert(iter) : iter;
|
||||
|
@ -567,7 +626,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
|
||||
protected int compare(KEY_TYPE k, KEY_TYPE v) { return comparator != null ? comparator.compare(k, v) : COMPAREABLE_TO_KEY(k, v);}
|
||||
|
||||
/** From CLR */
|
||||
protected void rotateLeft(Entry KEY_VALUE_GENERIC_TYPE entry) {
|
||||
if(entry != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE right = entry.right;
|
||||
|
@ -582,7 +640,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
}
|
||||
}
|
||||
|
||||
/** From CLR */
|
||||
protected void rotateRight(Entry KEY_VALUE_GENERIC_TYPE entry) {
|
||||
if(entry != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE left = entry.left;
|
||||
|
@ -597,7 +654,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
}
|
||||
}
|
||||
|
||||
/** From CLR */
|
||||
protected void fixAfterInsertion(Entry KEY_VALUE_GENERIC_TYPE entry) {
|
||||
while(entry != null) {
|
||||
entry.updateHeight();
|
||||
|
@ -622,7 +678,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
}
|
||||
}
|
||||
|
||||
/** From CLR */
|
||||
protected void fixAfterDeletion(Entry KEY_VALUE_GENERIC_TYPE entry) {
|
||||
if(entry != null) {
|
||||
entry.updateHeight();
|
||||
|
@ -697,7 +752,61 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
public DescendingSubMap(AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE m, boolean fromStart, KEY_TYPE low, boolean loInclusive, boolean toEnd, KEY_TYPE high, boolean hiInclusive) {
|
||||
super(m, fromStart, low, loInclusive, toEnd, high, hiInclusive);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_ENTRY_KEY() { return super.LAST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { return super.POLL_LAST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_ENTRY_KEY() { return super.FIRST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() { return super.POLL_FIRST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { return super.LAST_ENTRY_VALUE(); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return super.FIRST_ENTRY_VALUE(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return super.lastEntry(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return super.firstEntry(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { return super.pollLastEntry(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { return super.pollFirstEntry(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE lowerKey(KEY_TYPE e) { return super.higherKey(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE floorKey(KEY_TYPE e) { return super.ceilingKey(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ceilingKey(KEY_TYPE e) { return super.floorKey(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE higherKey(KEY_TYPE e) { return super.lowerKey(e); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(KEY_TYPE e) { return super.higherEntry(e); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE e) { return super.ceilingEntry(e); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE e) { return super.floorEntry(e); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(KEY_TYPE e) { return super.lowerEntry(e); }
|
||||
|
||||
@Override
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE keyIterator(boolean descending) {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE iter = new SubMapKeyIterator(!descending);
|
||||
|
@ -711,7 +820,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return m.comparator().reversed(); }
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return m.comparator() == null ? null : m.comparator().reversed(); }
|
||||
|
||||
@Override
|
||||
VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE valueIterator() { return VALUE_ITERATORS.invert(new SubMapValueIterator(true)); }
|
||||
|
@ -933,7 +1042,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_KEY(KEY_TYPE key) {
|
||||
return inRange(key) ? m.remove(key) : getDefaultReturnValue();
|
||||
return inRange(key) ? m.REMOVE_KEY(key) : getDefaultReturnValue();
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
|
|
|
@ -58,6 +58,54 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
protected NAVIGABLE_SET KEY_GENERIC_TYPE keySet;
|
||||
protected VALUE_COLLECTION VALUE_GENERIC_TYPE values;
|
||||
protected ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> entrySet;
|
||||
|
||||
public RB_TREE_MAP() {
|
||||
}
|
||||
|
||||
public RB_TREE_MAP(COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
public RB_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) {
|
||||
this(keys, values, null);
|
||||
}
|
||||
|
||||
public RB_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
for(int i = 0,m=keys.length;i<m;i++) put(OBJ_TO_KEY(keys[i]), OBJ_TO_VALUE(values[i]));
|
||||
}
|
||||
|
||||
#endif
|
||||
public RB_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) {
|
||||
this(keys, values, null);
|
||||
}
|
||||
|
||||
public RB_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
for(int i = 0,m=keys.length;i<m;i++) put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
public RB_TREE_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||
this(map, null);
|
||||
}
|
||||
|
||||
public RB_TREE_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
public RB_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
this(map, null);
|
||||
}
|
||||
|
||||
public RB_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
public KEY_TYPE getDefaultMaxValue() { return defaultMaxNotFound; }
|
||||
public KEY_TYPE getDefaultMinValue() { return defaultMinNotFound; }
|
||||
|
@ -323,6 +371,17 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public int size() { return size; }
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
size = 0;
|
||||
first = null;
|
||||
last = null;
|
||||
tree = null;
|
||||
}
|
||||
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE keyIterator(boolean descending) {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE iter = new KeyIterator(descending);
|
||||
return descending ? ITERATORS.invert(iter) : iter;
|
||||
|
@ -572,7 +631,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
protected static GENERIC_KEY_VALUE_BRACES Entry KEY_VALUE_GENERIC_TYPE leftOf(Entry KEY_VALUE_GENERIC_TYPE p) { return p == null ? null : p.left; }
|
||||
protected static GENERIC_KEY_VALUE_BRACES Entry KEY_VALUE_GENERIC_TYPE rightOf(Entry KEY_VALUE_GENERIC_TYPE p) { return (p == null) ? null : p.right; }
|
||||
|
||||
/** From CLR */
|
||||
protected void rotateLeft(Entry KEY_VALUE_GENERIC_TYPE entry) {
|
||||
if(entry != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE right = entry.right;
|
||||
|
@ -587,7 +645,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
}
|
||||
}
|
||||
|
||||
/** From CLR */
|
||||
protected void rotateRight(Entry KEY_VALUE_GENERIC_TYPE entry) {
|
||||
if(entry != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE left = entry.left;
|
||||
|
@ -602,7 +659,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
}
|
||||
}
|
||||
|
||||
/** From CLR */
|
||||
protected void fixAfterInsertion(Entry KEY_VALUE_GENERIC_TYPE entry) {
|
||||
entry.setBlack(false);
|
||||
while(entry != null && entry != tree && !entry.parent.isBlack()) {
|
||||
|
@ -646,7 +702,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
tree.setBlack(true);
|
||||
}
|
||||
|
||||
/** From CLR */
|
||||
protected void fixAfterDeletion(Entry KEY_VALUE_GENERIC_TYPE entry) {
|
||||
while(entry != tree && isBlack(entry)) {
|
||||
if(entry == leftOf(parentOf(entry))) {
|
||||
|
@ -754,13 +809,67 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
public DescendingSubMap(RB_TREE_MAP KEY_VALUE_GENERIC_TYPE m, boolean fromStart, KEY_TYPE low, boolean loInclusive, boolean toEnd, KEY_TYPE high, boolean hiInclusive) {
|
||||
super(m, fromStart, low, loInclusive, toEnd, high, hiInclusive);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_ENTRY_KEY() { return super.LAST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { return super.POLL_LAST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_ENTRY_KEY() { return super.FIRST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() { return super.POLL_FIRST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { return super.LAST_ENTRY_VALUE(); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return super.FIRST_ENTRY_VALUE(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return super.lastEntry(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return super.firstEntry(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { return super.pollLastEntry(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { return super.pollFirstEntry(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE lowerKey(KEY_TYPE e) { return super.higherKey(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE floorKey(KEY_TYPE e) { return super.ceilingKey(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ceilingKey(KEY_TYPE e) { return super.floorKey(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE higherKey(KEY_TYPE e) { return super.lowerKey(e); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(KEY_TYPE e) { return super.higherEntry(e); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE e) { return super.ceilingEntry(e); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE e) { return super.floorEntry(e); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(KEY_TYPE e) { return super.lowerEntry(e); }
|
||||
|
||||
@Override
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE keyIterator(boolean descending) {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE iter = new SubMapKeyIterator(!descending);
|
||||
return descending ? iter : ITERATORS.invert(iter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE key) {
|
||||
RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = m.findNode(key);
|
||||
|
@ -768,7 +877,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return m.comparator().reversed(); }
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return m.comparator() == null ? null : m.comparator().reversed(); }
|
||||
|
||||
@Override
|
||||
VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE valueIterator() { return VALUE_ITERATORS.invert(new SubMapValueIterator(true)); }
|
||||
|
@ -990,7 +1099,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_KEY(KEY_TYPE key) {
|
||||
return inRange(key) ? m.remove(key) : getDefaultReturnValue();
|
||||
return inRange(key) ? m.REMOVE_KEY(key) : getDefaultReturnValue();
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
|
|
|
@ -38,6 +38,10 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
public AVL_TREE_SET() {
|
||||
}
|
||||
|
||||
public AVL_TREE_SET(COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
}
|
||||
|
||||
public AVL_TREE_SET(KEY_TYPE[] array) {
|
||||
this(array, 0, array.length);
|
||||
}
|
||||
|
@ -47,15 +51,41 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
for(int i = 0;i<length;i++) add(array[offset+i]);
|
||||
}
|
||||
|
||||
public AVL_TREE_SET(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
this(array, 0, array.length, comp);
|
||||
}
|
||||
|
||||
public AVL_TREE_SET(KEY_TYPE[] array, int offset, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
SanityChecks.checkArrayCapacity(array.length, offset, length);
|
||||
for(int i = 0;i<length;i++) add(array[offset+i]);
|
||||
}
|
||||
|
||||
public AVL_TREE_SET(SORTED_SET KEY_GENERIC_TYPE sortedSet) {
|
||||
comparator = sortedSet.comparator();
|
||||
addAll(sortedSet);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public AVL_TREE_SET(Collection<? extends CLASS_TYPE> collection) {
|
||||
addAll(collection);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public AVL_TREE_SET(Collection<? extends CLASS_TYPE> collection, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
addAll(collection);
|
||||
}
|
||||
|
||||
public AVL_TREE_SET(COLLECTION KEY_GENERIC_TYPE collection) {
|
||||
addAll(collection);
|
||||
}
|
||||
|
||||
public AVL_TREE_SET(COLLECTION KEY_GENERIC_TYPE collection, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
addAll(collection);
|
||||
}
|
||||
|
||||
public AVL_TREE_SET(Iterator<CLASS_TYPE> iterator) {
|
||||
#if !TYPE_OBJECT
|
||||
this(ITERATORS.wrap(iterator));
|
||||
|
@ -64,10 +94,24 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
#endif
|
||||
}
|
||||
|
||||
public AVL_TREE_SET(Iterator<CLASS_TYPE> iterator, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
#if !TYPE_OBJECT
|
||||
this(ITERATORS.wrap(iterator), comp);
|
||||
#else
|
||||
comparator = comp;
|
||||
while(iterator.hasNext()) add(iterator.next());
|
||||
#endif
|
||||
}
|
||||
|
||||
public AVL_TREE_SET(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
public AVL_TREE_SET(ITERATOR KEY_GENERIC_TYPE iterator, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE value) { defaultMaxNotFound = value; }
|
||||
|
@ -339,6 +383,14 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
@Override
|
||||
public int size() { return size; }
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
size = 0;
|
||||
first = null;
|
||||
last = null;
|
||||
tree = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||
|
||||
|
@ -533,7 +585,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
COMPARATOR KEY_GENERIC_TYPE comparator;
|
||||
DescendingSubSet(AVL_TREE_SET KEY_GENERIC_TYPE set, boolean fromStart, KEY_TYPE start, boolean loInclusive, boolean toEnd, KEY_TYPE end, boolean hiInclusive) {
|
||||
super(set, fromStart, start, loInclusive, toEnd, end, hiInclusive);
|
||||
comparator = set.comparator().reversed();
|
||||
comparator = set.comparator();
|
||||
if(comparator != null) comparator = comparator.reversed();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -346,8 +346,9 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||
int newMask = newSize - 1;
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
long[] newLinks = new long[newSize + 1];
|
||||
int newPrev = -1;
|
||||
for(int j = size, i = firstIndex, pos = 0, prev = -1;j != 0;) {
|
||||
int i = firstIndex, prev = -1, newPrev = -1, pos;
|
||||
firstIndex = -1;
|
||||
for(int j = size; j-- != 0;) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) pos = newSize;
|
||||
else {
|
||||
pos = HashUtil.mix(strategy.hashCode(keys[i])) & newMask;
|
||||
|
|
|
@ -348,8 +348,9 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||
int newMask = newSize - 1;
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
long[] newLinks = new long[newSize + 1];
|
||||
int newPrev = -1;
|
||||
for(int j = size, i = firstIndex, pos = 0, prev = -1;j != 0;) {
|
||||
int i = firstIndex, prev = -1, newPrev = -1, pos;
|
||||
firstIndex = -1;
|
||||
for(int j = size; j-- != 0;) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) pos = newSize;
|
||||
else {
|
||||
pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask;
|
||||
|
|
|
@ -38,6 +38,10 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
public RB_TREE_SET() {
|
||||
}
|
||||
|
||||
public RB_TREE_SET(COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
}
|
||||
|
||||
public RB_TREE_SET(KEY_TYPE[] array) {
|
||||
this(array, 0, array.length);
|
||||
}
|
||||
|
@ -47,14 +51,40 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
for(int i = 0;i<length;i++) add(array[offset+i]);
|
||||
}
|
||||
|
||||
public RB_TREE_SET(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
this(array, 0, array.length, comp);
|
||||
}
|
||||
|
||||
public RB_TREE_SET(KEY_TYPE[] array, int offset, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
SanityChecks.checkArrayCapacity(array.length, offset, length);
|
||||
for(int i = 0;i<length;i++) add(array[offset+i]);
|
||||
}
|
||||
|
||||
public RB_TREE_SET(SORTED_SET KEY_GENERIC_TYPE sortedSet) {
|
||||
comparator = sortedSet.comparator();
|
||||
addAll(sortedSet);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public RB_TREE_SET(Collection<? extends CLASS_TYPE> collection) {
|
||||
addAll(collection);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public RB_TREE_SET(Collection<? extends CLASS_TYPE> collection, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
addAll(collection);
|
||||
}
|
||||
|
||||
public RB_TREE_SET(COLLECTION KEY_GENERIC_TYPE collection) {
|
||||
addAll(collection);
|
||||
}
|
||||
|
||||
public RB_TREE_SET(COLLECTION KEY_GENERIC_TYPE collection, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
addAll(collection);
|
||||
}
|
||||
|
||||
public RB_TREE_SET(Iterator<CLASS_TYPE> iterator) {
|
||||
#if !TYPE_OBJECT
|
||||
|
@ -63,11 +93,25 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
while(iterator.hasNext()) add(iterator.next());
|
||||
#endif
|
||||
}
|
||||
|
||||
public RB_TREE_SET(Iterator<CLASS_TYPE> iterator, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
#if !TYPE_OBJECT
|
||||
this(ITERATORS.wrap(iterator), comp);
|
||||
#else
|
||||
comparator = comp;
|
||||
while(iterator.hasNext()) add(iterator.next());
|
||||
#endif
|
||||
}
|
||||
|
||||
public RB_TREE_SET(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
public RB_TREE_SET(ITERATOR KEY_GENERIC_TYPE iterator, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE value) { defaultMaxNotFound = value; }
|
||||
|
@ -341,6 +385,14 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
@Override
|
||||
public int size() { return size; }
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
size = 0;
|
||||
first = null;
|
||||
last = null;
|
||||
tree = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||
|
||||
|
@ -593,7 +645,8 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
COMPARATOR KEY_GENERIC_TYPE comparator;
|
||||
DescendingSubSet(RB_TREE_SET KEY_GENERIC_TYPE set, boolean fromStart, KEY_TYPE start, boolean loInclusive, boolean toEnd, KEY_TYPE end, boolean hiInclusive) {
|
||||
super(set, fromStart, start, loInclusive, toEnd, end, hiInclusive);
|
||||
comparator = set.comparator().reversed();
|
||||
comparator = set.comparator();
|
||||
if(comparator != null) comparator = comparator.reversed();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -566,7 +566,7 @@ public class ARRAYS
|
|||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
* @param array the array that needs to be sorted
|
||||
* @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
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelMergeSort(array, null, 0, array.length, comp);
|
||||
|
@ -578,7 +578,7 @@ public class ARRAYS
|
|||
* @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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelMergeSort(array, null, 0, length, comp);
|
||||
|
@ -591,7 +591,7 @@ public class ARRAYS
|
|||
* @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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
|
@ -605,7 +605,7 @@ public class ARRAYS
|
|||
* 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
|
||||
* @param array the array that needs to be sorted
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array) {
|
||||
parallelMergeSort(array, null, 0, array.length);
|
||||
|
@ -616,7 +616,7 @@ public class ARRAYS
|
|||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, int length) {
|
||||
parallelMergeSort(array, null, 0, length);
|
||||
|
@ -628,7 +628,7 @@ public class ARRAYS
|
|||
* @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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
|
@ -788,7 +788,7 @@ public class ARRAYS
|
|||
* @author Speiger
|
||||
* @param array the array that needs to be sorted
|
||||
* @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
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelMemFreeMergeSort(array, 0, array.length, comp);
|
||||
|
@ -803,7 +803,7 @@ public class ARRAYS
|
|||
* @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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelMemFreeMergeSort(array, 0, length, comp);
|
||||
|
@ -819,7 +819,7 @@ public class ARRAYS
|
|||
* @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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
|
@ -836,7 +836,7 @@ public class ARRAYS
|
|||
* It does stack allocate tiny amounts of data for shifting around elements.
|
||||
* @author Speiger
|
||||
* @param array the array that needs to be sorted
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array) {
|
||||
parallelMemFreeMergeSort(array, 0, array.length);
|
||||
|
@ -850,7 +850,7 @@ public class ARRAYS
|
|||
* @author Speiger
|
||||
* @param array the array that needs to be sorted
|
||||
* @param length the maxmium size of the array to be sorted
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length) {
|
||||
parallelMemFreeMergeSort(array, 0, length);
|
||||
|
@ -865,7 +865,7 @@ public class ARRAYS
|
|||
* @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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
|
@ -878,7 +878,7 @@ public class ARRAYS
|
|||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator 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,
|
||||
* 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.
|
||||
* 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
|
||||
*/
|
||||
|
@ -889,7 +889,7 @@ public class ARRAYS
|
|||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator 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,
|
||||
* 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.
|
||||
* 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
|
||||
|
@ -901,7 +901,7 @@ public class ARRAYS
|
|||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator 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,
|
||||
* 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.
|
||||
* 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
|
||||
|
@ -934,7 +934,7 @@ public class ARRAYS
|
|||
/**
|
||||
* 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,
|
||||
* 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.
|
||||
* and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, "Engineering a Sort Function", Software: Practice and Experience, 23(11), pages1249−1265, 1993.
|
||||
* @param array the array that needs to be sorted
|
||||
*/
|
||||
public static COMPAREABLE_KEY_BRACES void quickSort(KEY_TYPE[] array) {
|
||||
|
@ -944,7 +944,7 @@ public class ARRAYS
|
|||
/**
|
||||
* 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,
|
||||
* 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.
|
||||
* 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
|
||||
*/
|
||||
|
@ -955,7 +955,7 @@ public class ARRAYS
|
|||
/**
|
||||
* 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,
|
||||
* 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.
|
||||
* 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
|
||||
|
@ -987,10 +987,10 @@ public class ARRAYS
|
|||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator 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,
|
||||
* 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.
|
||||
* 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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelQuickSort(array, 0, array.length, comp);
|
||||
|
@ -999,11 +999,11 @@ public class ARRAYS
|
|||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator 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,
|
||||
* 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.
|
||||
* 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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
parallelQuickSort(array, 0, length, comp);
|
||||
|
@ -1012,12 +1012,12 @@ public class ARRAYS
|
|||
/**
|
||||
* Sorts the specified range of elements according to the order induced by the specified comparator 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,
|
||||
* 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.
|
||||
* 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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
|
@ -1030,9 +1030,9 @@ public class ARRAYS
|
|||
/**
|
||||
* 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,
|
||||
* 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.
|
||||
* 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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array) {
|
||||
parallelQuickSort(array, 0, array.length);
|
||||
|
@ -1041,10 +1041,10 @@ public class ARRAYS
|
|||
/**
|
||||
* 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,
|
||||
* 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.
|
||||
* 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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int length) {
|
||||
parallelQuickSort(array, 0, length);
|
||||
|
@ -1053,11 +1053,11 @@ public class ARRAYS
|
|||
/**
|
||||
* 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,
|
||||
* 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.
|
||||
* 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
|
||||
* @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
* @note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed
|
||||
*/
|
||||
public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to) {
|
||||
if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) {
|
||||
|
|
|
@ -64,7 +64,7 @@ public class ITERATORS
|
|||
|
||||
/**
|
||||
* Returns a Immutable Iterator instance based on the instance given.
|
||||
* @param l that should be made immutable/unmodifyable
|
||||
* @param iterator that should be made immutable/unmodifyable
|
||||
* @return a unmodifiable iterator wrapper. If the Iterator already a unmodifyable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE unmodifiable(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
|
@ -77,7 +77,7 @@ public class ITERATORS
|
|||
|
||||
/**
|
||||
* Returns a Immutable ListIterator instance based on the instance given.
|
||||
* @param l that should be made immutable/unmodifyable
|
||||
* @param iterator that should be made immutable/unmodifyable
|
||||
* @return a unmodifiable listiterator wrapper. If the ListIterator already a unmodifyable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST_ITERATOR KEY_GENERIC_TYPE unmodifiable(LIST_ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
|
|
|
@ -8,6 +8,7 @@ public interface ITrimmable
|
|||
{
|
||||
/**
|
||||
* Trims the original collection down to the size of the current elements
|
||||
* @return if the internal array has been trimmed.
|
||||
*/
|
||||
public default boolean trim() {
|
||||
return trim(0);
|
||||
|
@ -16,6 +17,7 @@ public interface ITrimmable
|
|||
/**
|
||||
* Trims the original collection down to the size of the current elements or the requested size depending which is bigger
|
||||
* @param size the requested trim size.
|
||||
* @return if the internal array has been trimmed.
|
||||
*/
|
||||
public boolean trim(int size);
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class SanityChecks
|
|||
* @return true if the threadcount is bigger the 1
|
||||
*/
|
||||
public static boolean canParallelTask() {
|
||||
return WORK_POOL.getParallelism() > 1 || FORCE_IGNORE_PARALLELISM;
|
||||
return getPool().getParallelism() > 1 || FORCE_IGNORE_PARALLELISM;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
package speiger.src.collections.ints.base;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import speiger.src.collections.ints.maps.interfaces.Int2IntMap;
|
||||
import speiger.src.collections.ints.utils.IntStrategy;
|
||||
import speiger.src.collections.tests.MapTests;
|
||||
|
||||
public abstract class BaseInt2IntMapTest
|
||||
{
|
||||
protected static final IntStrategy STRATEGY = new Strategy();
|
||||
protected static final int[] TEST_ARRAY = IntStream.range(0, 100).toArray();
|
||||
protected static final int[] PUT_ARRAY = IntStream.range(512, 1024).toArray();
|
||||
protected static final int[] PUT_VALUE_ARRAY = IntStream.range(0, 512).toArray();
|
||||
|
||||
public abstract Int2IntMap createMap(int[] keys, int[] values);
|
||||
public abstract Int2IntMap createEmptyMap();
|
||||
|
||||
public EnumSet<MapTests> getValidMapTests() { return EnumSet.allOf(MapTests.class); }
|
||||
|
||||
@Test
|
||||
public void testPut()
|
||||
{
|
||||
if(!getValidMapTests().contains(MapTests.PUT)) return;
|
||||
Int2IntMap putMap = createMap(PUT_ARRAY, PUT_VALUE_ARRAY);
|
||||
Assert.assertEquals(PUT_ARRAY.length, putMap.size());
|
||||
Assert.assertEquals(0, putMap.put(0, 512));
|
||||
Assert.assertEquals(1, putMap.put(513, 2));
|
||||
Assert.assertEquals(PUT_ARRAY.length + 1, putMap.size());
|
||||
Assert.assertEquals(512, putMap.addTo(0, 1));
|
||||
Assert.assertEquals(513, putMap.getInt(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutAll()
|
||||
{
|
||||
if(!getValidMapTests().contains(MapTests.PUT_ALL)) return;
|
||||
Int2IntMap putMap = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Assert.assertEquals(TEST_ARRAY.length, putMap.size());
|
||||
putMap.putAll(createMap(PUT_ARRAY, PUT_VALUE_ARRAY));
|
||||
Assert.assertEquals(TEST_ARRAY.length + PUT_ARRAY.length, putMap.size());
|
||||
putMap = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
putMap.putAll(createMap(PUT_VALUE_ARRAY, PUT_ARRAY));
|
||||
Assert.assertEquals(PUT_ARRAY.length, putMap.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContains()
|
||||
{
|
||||
if(!getValidMapTests().contains(MapTests.CONTAINS)) return;
|
||||
Int2IntMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Assert.assertTrue(map.containsKey(0));
|
||||
Assert.assertFalse(map.containsKey(-1));
|
||||
Assert.assertTrue(map.containsKey(Integer.valueOf(10)));
|
||||
Assert.assertFalse(map.containsKey(Short.valueOf((short)10)));
|
||||
Assert.assertTrue(map.containsValue(50));
|
||||
Assert.assertFalse(map.containsValue(150));
|
||||
Assert.assertTrue(map.containsValue(Integer.valueOf(10)));
|
||||
Assert.assertFalse(map.containsValue(Short.valueOf((short)10)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplace()
|
||||
{
|
||||
if(!getValidMapTests().contains(MapTests.REPLACE)) return;
|
||||
Int2IntMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Assert.assertEquals(0, map.replace(0, 512));
|
||||
Assert.assertEquals(512, map.getInt(0));
|
||||
Assert.assertTrue(map.replace(0, 512, 0));
|
||||
Assert.assertFalse(map.replace(0, 512, 0));
|
||||
map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
map.replaceInts((K, V) -> 99 - V);
|
||||
Assert.assertEquals(99, map.getInt(0));
|
||||
Assert.assertEquals(0, map.getInt(99));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompute()
|
||||
{
|
||||
if(!getValidMapTests().contains(MapTests.COMPUTE)) return;
|
||||
Int2IntMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Assert.assertEquals(512, map.computeInt(0, (K, V) -> 512));
|
||||
Assert.assertEquals(512, map.getInt(0));
|
||||
Assert.assertEquals(512, map.computeIntIfAbsent(0, T -> 0));
|
||||
Assert.assertEquals(0, map.computeIntIfPresent(0, (T, V) -> 0));
|
||||
Assert.assertEquals(0, map.computeIntIfAbsent(-10, T -> 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMerge()
|
||||
{
|
||||
if(!getValidMapTests().contains(MapTests.MERGE)) return;
|
||||
Int2IntMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Assert.assertEquals(50, map.mergeInt(1, 50, Integer::max));
|
||||
Assert.assertEquals(2, map.mergeInt(2, 50, Integer::min));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet()
|
||||
{
|
||||
if(!getValidMapTests().contains(MapTests.GET)) return;
|
||||
Int2IntMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
for(int i = 0;i<TEST_ARRAY.length;i++)
|
||||
{
|
||||
Assert.assertEquals(i, map.getInt(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIterators()
|
||||
{
|
||||
if(!getValidMapTests().contains(MapTests.ITERATORS)) return;
|
||||
Int2IntMap map = createMap(PUT_VALUE_ARRAY, PUT_ARRAY);
|
||||
map.forEach((K, V) -> Assert.assertEquals(PUT_ARRAY[K], V));
|
||||
map.int2IntEntrySet().forEach(T -> Assert.assertEquals(PUT_ARRAY[T.getIntKey()], T.getIntValue()));
|
||||
map.keySet().forEach(T -> Assert.assertEquals(PUT_VALUE_ARRAY[T], T));
|
||||
map.values().forEach(T -> Assert.assertTrue(T >= 512 && T <= 1024));
|
||||
Assert.assertTrue(map.keySet().contains(50));
|
||||
Assert.assertFalse(map.keySet().contains(-50));
|
||||
Assert.assertTrue(map.values().contains(1000));
|
||||
Assert.assertFalse(map.values().contains(-1000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove()
|
||||
{
|
||||
if(!getValidMapTests().contains(MapTests.REMOVE)) return;
|
||||
Int2IntMap map = createMap(PUT_VALUE_ARRAY, PUT_ARRAY);
|
||||
Assert.assertEquals(PUT_ARRAY[50], map.remInt(PUT_VALUE_ARRAY[50]));
|
||||
Assert.assertTrue(map.remove(PUT_VALUE_ARRAY[51], PUT_ARRAY[51]));
|
||||
}
|
||||
|
||||
public static class Strategy implements IntStrategy
|
||||
{
|
||||
@Override
|
||||
public int hashCode(int o)
|
||||
{
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(int key, int value)
|
||||
{
|
||||
return key == value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package speiger.src.collections.ints.base;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import speiger.src.collections.ints.maps.interfaces.Int2IntNavigableMap;
|
||||
import speiger.src.collections.tests.NavigableSetTest;
|
||||
|
||||
public abstract class BaseInt2IntNavigableMapTest extends BaseInt2IntSortedMapTest
|
||||
{
|
||||
@Override
|
||||
public abstract Int2IntNavigableMap createMap(int[] keys, int[] values);
|
||||
@Override
|
||||
public abstract Int2IntNavigableMap createEmptyMap();
|
||||
|
||||
public EnumSet<NavigableSetTest> getValidNavigableMapTests() { return EnumSet.allOf(NavigableSetTest.class); }
|
||||
|
||||
@Test
|
||||
public void desendingTest() {
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.DESENDING)) {
|
||||
Int2IntNavigableMap set = createMap(TEST_ARRAY, TEST_ARRAY).descendingMap();
|
||||
Assert.assertEquals(TEST_ARRAY[TEST_ARRAY.length - 1], set.firstIntKey());
|
||||
Assert.assertEquals(TEST_ARRAY[0], set.lastIntKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowerTest() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ceilTest() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void naviSubSetTest() {
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.SUB_SET)) {
|
||||
Int2IntNavigableMap set = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Int2IntNavigableMap subSet = set.subMap(25, 75);
|
||||
Assert.assertTrue(subSet.lowerKey(50) < 50);
|
||||
Assert.assertTrue(subSet.higherKey(50) > 50);
|
||||
Assert.assertTrue(subSet.ceilingKey(50) >= 50);
|
||||
Assert.assertTrue(subSet.floorKey(50) <= 50);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void naviHeadSetTest() {
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.HEAD_SET)) {
|
||||
Int2IntNavigableMap set = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Int2IntNavigableMap subSet = set.headMap(75);
|
||||
Assert.assertTrue(subSet.lowerKey(50) < 50);
|
||||
Assert.assertTrue(subSet.higherKey(50) > 50);
|
||||
Assert.assertTrue(subSet.ceilingKey(50) >= 50);
|
||||
Assert.assertTrue(subSet.floorKey(50) <= 50);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void naviTailSetTest() {
|
||||
if(getValidNavigableMapTests().contains(NavigableSetTest.TAIL_SET)) {
|
||||
Int2IntNavigableMap set = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Int2IntNavigableMap subSet = set.tailMap(25);
|
||||
Assert.assertTrue(subSet.lowerKey(50) < 50);
|
||||
Assert.assertTrue(subSet.higherKey(50) > 50);
|
||||
Assert.assertTrue(subSet.ceilingKey(50) >= 50);
|
||||
Assert.assertTrue(subSet.floorKey(50) <= 50);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package speiger.src.collections.ints.base;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import speiger.src.collections.ints.maps.interfaces.Int2IntSortedMap;
|
||||
import speiger.src.collections.tests.SortedMapTests;
|
||||
|
||||
public abstract class BaseInt2IntSortedMapTest extends BaseInt2IntMapTest
|
||||
{
|
||||
@Override
|
||||
public abstract Int2IntSortedMap createMap(int[] keys, int[] values);
|
||||
@Override
|
||||
public abstract Int2IntSortedMap createEmptyMap();
|
||||
|
||||
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.allOf(SortedMapTests.class); }
|
||||
|
||||
@Test
|
||||
public void testPutMove()
|
||||
{
|
||||
if(!getValidSortedMapTests().contains(SortedMapTests.PUT_MOVE)) return;
|
||||
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Assert.assertEquals(0, map.putAndMoveToFirst(120, -1));
|
||||
Assert.assertEquals(120, map.firstIntKey());
|
||||
Assert.assertEquals(-1, map.firstIntValue());
|
||||
Assert.assertEquals(0, map.putAndMoveToLast(121, -2));
|
||||
Assert.assertEquals(121, map.lastIntKey());
|
||||
Assert.assertEquals(-2, map.lastIntValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMove()
|
||||
{
|
||||
if(!getValidSortedMapTests().contains(SortedMapTests.MOVE)) return;
|
||||
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Assert.assertTrue(map.moveToFirst(99));
|
||||
Assert.assertFalse(map.moveToFirst(99));
|
||||
Assert.assertEquals(99, map.firstIntKey());
|
||||
Assert.assertTrue(map.moveToLast(0));
|
||||
Assert.assertFalse(map.moveToLast(0));
|
||||
Assert.assertEquals(0, map.lastIntKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMove()
|
||||
{
|
||||
if(!getValidSortedMapTests().contains(SortedMapTests.GET_MOVE)) return;
|
||||
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Assert.assertNotEquals(99, map.firstIntValue());
|
||||
Assert.assertEquals(99, map.getAndMoveToFirst(99));
|
||||
Assert.assertEquals(99, map.firstIntValue());
|
||||
Assert.assertNotEquals(0, map.lastIntValue());
|
||||
Assert.assertEquals(0, map.getAndMoveToLast(0));
|
||||
Assert.assertEquals(0, map.lastIntValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFirst()
|
||||
{
|
||||
if(!getValidSortedMapTests().contains(SortedMapTests.FIRST)) return;
|
||||
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
for(int i = 0;i<TEST_ARRAY.length;i++)
|
||||
{
|
||||
Assert.assertEquals(TEST_ARRAY[i], map.pollFirstIntKey());
|
||||
}
|
||||
Assert.assertEquals(0, map.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLast()
|
||||
{
|
||||
if(!getValidSortedMapTests().contains(SortedMapTests.LAST)) return;
|
||||
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
for(int i = TEST_ARRAY.length-1;i>=0;i--)
|
||||
{
|
||||
Assert.assertEquals(TEST_ARRAY[i], map.pollLastIntKey());
|
||||
}
|
||||
Assert.assertEquals(0, map.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubMap()
|
||||
{
|
||||
if(!getValidSortedMapTests().contains(SortedMapTests.SUB_MAP)) return;
|
||||
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Int2IntSortedMap subMap = map.subMap(25, 75);
|
||||
Assert.assertEquals(50, subMap.remInt(50));
|
||||
Assert.assertNotEquals(50, subMap.remInt(50));
|
||||
Assert.assertFalse(subMap.containsKey(20));
|
||||
Assert.assertFalse(subMap.containsKey(80));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeadMap()
|
||||
{
|
||||
if(!getValidSortedMapTests().contains(SortedMapTests.HEAD_MAP)) return;
|
||||
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Int2IntSortedMap subMap = map.headMap(75);
|
||||
Assert.assertEquals(50, subMap.remInt(50));
|
||||
Assert.assertNotEquals(50, subMap.remInt(50));
|
||||
Assert.assertFalse(subMap.containsKey(80));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTailMap()
|
||||
{
|
||||
if(!getValidSortedMapTests().contains(SortedMapTests.TAIL_MAP)) return;
|
||||
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Int2IntSortedMap subMap = map.tailMap(25);
|
||||
Assert.assertEquals(50, subMap.remInt(50));
|
||||
Assert.assertNotEquals(50, subMap.remInt(50));
|
||||
Assert.assertFalse(subMap.containsKey(20));
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package speiger.src.collections.ints.base;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -16,6 +17,7 @@ import speiger.src.collections.tests.CollectionTest;
|
|||
public abstract class BaseIntCollectionTest extends BaseIntIterableTest
|
||||
{
|
||||
protected static final int[] ADD_ARRAY = new int[]{3212, -12, 423, -182, -4912};
|
||||
protected static final int[] BULK_ADD_ARRAY = IntStream.range(200, 500).toArray();
|
||||
protected static final int[] CONTAINS_ARRAY = new int[]{23, 45, 63, 89, 32};
|
||||
|
||||
@Override
|
||||
|
@ -40,6 +42,10 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
|
|||
Assert.assertEquals(TEST_ARRAY.length, collection.size());
|
||||
collection.addAll(create(ADD_ARRAY));
|
||||
Assert.assertEquals(TEST_ARRAY.length + ADD_ARRAY.length, collection.size());
|
||||
collection = create(TEST_ARRAY);
|
||||
Assert.assertEquals(TEST_ARRAY.length, collection.size());
|
||||
collection.addAll(create(BULK_ADD_ARRAY));
|
||||
Assert.assertEquals(TEST_ARRAY.length + BULK_ADD_ARRAY.length, collection.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -15,6 +15,15 @@ public abstract class BaseIntNavigableSetTest extends BaseIntSortedSetTest
|
|||
|
||||
protected EnumSet<NavigableSetTest> getValidNavigableSetTests() { return EnumSet.allOf(NavigableSetTest.class); }
|
||||
|
||||
@Test
|
||||
public void desendingTest() {
|
||||
if(getValidNavigableSetTests().contains(NavigableSetTest.DESENDING)) {
|
||||
IntNavigableSet set = create(TEST_ARRAY).descendingSet();
|
||||
Assert.assertEquals(TEST_ARRAY[TEST_ARRAY.length - 1], set.firstInt());
|
||||
Assert.assertEquals(TEST_ARRAY[0], set.lastInt());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowerTest() {
|
||||
if(getValidNavigableSetTests().contains(NavigableSetTest.LOWER)) {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package speiger.src.collections.ints.maps;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseInt2IntNavigableMapTest;
|
||||
import speiger.src.collections.ints.maps.impl.tree.Int2IntAVLTreeMap;
|
||||
import speiger.src.collections.ints.maps.interfaces.Int2IntNavigableMap;
|
||||
import speiger.src.collections.tests.SortedMapTests;
|
||||
|
||||
public class Int2IntAVLTreeMapTest extends BaseInt2IntNavigableMapTest
|
||||
{
|
||||
@Override
|
||||
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.GET_MOVE, SortedMapTests.MOVE, SortedMapTests.PUT_MOVE)); }
|
||||
|
||||
@Override
|
||||
public Int2IntNavigableMap createMap(int[] keys, int[] values)
|
||||
{
|
||||
return new Int2IntAVLTreeMap(keys, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Int2IntNavigableMap createEmptyMap()
|
||||
{
|
||||
return new Int2IntAVLTreeMap();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package speiger.src.collections.ints.maps;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseInt2IntSortedMapTest;
|
||||
import speiger.src.collections.ints.maps.impl.misc.Int2IntArrayMap;
|
||||
import speiger.src.collections.ints.maps.interfaces.Int2IntSortedMap;
|
||||
|
||||
public class Int2IntArrayMapTest extends BaseInt2IntSortedMapTest
|
||||
{
|
||||
@Override
|
||||
public Int2IntSortedMap createMap(int[] keys, int[] values)
|
||||
{
|
||||
return new Int2IntArrayMap(keys, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Int2IntSortedMap createEmptyMap()
|
||||
{
|
||||
return new Int2IntArrayMap();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package speiger.src.collections.ints.maps;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseInt2IntMapTest;
|
||||
import speiger.src.collections.ints.maps.impl.customHash.Int2IntOpenCustomHashMap;
|
||||
import speiger.src.collections.ints.maps.interfaces.Int2IntMap;
|
||||
|
||||
public class Int2IntCustomHashMapTest extends BaseInt2IntMapTest
|
||||
{
|
||||
@Override
|
||||
public Int2IntMap createMap(int[] keys, int[] values)
|
||||
{
|
||||
return new Int2IntOpenCustomHashMap(keys, values, STRATEGY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Int2IntMap createEmptyMap()
|
||||
{
|
||||
return new Int2IntOpenCustomHashMap(STRATEGY);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package speiger.src.collections.ints.maps;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseInt2IntMapTest;
|
||||
import speiger.src.collections.ints.maps.impl.hash.Int2IntOpenHashMap;
|
||||
import speiger.src.collections.ints.maps.interfaces.Int2IntMap;
|
||||
|
||||
public class Int2IntHashMapTest extends BaseInt2IntMapTest
|
||||
{
|
||||
|
||||
@Override
|
||||
public Int2IntMap createMap(int[] keys, int[] values)
|
||||
{
|
||||
return new Int2IntOpenHashMap(keys, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Int2IntMap createEmptyMap()
|
||||
{
|
||||
return new Int2IntOpenHashMap();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package speiger.src.collections.ints.maps;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseInt2IntSortedMapTest;
|
||||
import speiger.src.collections.ints.maps.impl.customHash.Int2IntLinkedOpenCustomHashMap;
|
||||
import speiger.src.collections.ints.maps.interfaces.Int2IntSortedMap;
|
||||
import speiger.src.collections.tests.SortedMapTests;
|
||||
|
||||
public class Int2IntLinkedOpenCustomHashMapTest extends BaseInt2IntSortedMapTest
|
||||
{
|
||||
@Override
|
||||
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.SUB_MAP, SortedMapTests.TAIL_MAP, SortedMapTests.HEAD_MAP)); }
|
||||
|
||||
@Override
|
||||
public Int2IntSortedMap createMap(int[] keys, int[] values)
|
||||
{
|
||||
return new Int2IntLinkedOpenCustomHashMap(keys, values, STRATEGY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Int2IntSortedMap createEmptyMap()
|
||||
{
|
||||
return new Int2IntLinkedOpenCustomHashMap(STRATEGY);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package speiger.src.collections.ints.maps;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseInt2IntSortedMapTest;
|
||||
import speiger.src.collections.ints.maps.impl.hash.Int2IntLinkedOpenHashMap;
|
||||
import speiger.src.collections.ints.maps.interfaces.Int2IntSortedMap;
|
||||
import speiger.src.collections.tests.SortedMapTests;
|
||||
|
||||
public class Int2IntLinkedOpenHashMapTest extends BaseInt2IntSortedMapTest
|
||||
{
|
||||
@Override
|
||||
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.SUB_MAP, SortedMapTests.TAIL_MAP, SortedMapTests.HEAD_MAP)); }
|
||||
|
||||
@Override
|
||||
public Int2IntSortedMap createMap(int[] keys, int[] values)
|
||||
{
|
||||
return new Int2IntLinkedOpenHashMap(keys, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Int2IntSortedMap createEmptyMap()
|
||||
{
|
||||
return new Int2IntLinkedOpenHashMap();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package speiger.src.collections.ints.maps;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseInt2IntNavigableMapTest;
|
||||
import speiger.src.collections.ints.maps.impl.tree.Int2IntRBTreeMap;
|
||||
import speiger.src.collections.ints.maps.interfaces.Int2IntNavigableMap;
|
||||
import speiger.src.collections.tests.SortedMapTests;
|
||||
|
||||
public class Int2IntRBTreeMapTest extends BaseInt2IntNavigableMapTest
|
||||
{
|
||||
@Override
|
||||
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.GET_MOVE, SortedMapTests.MOVE, SortedMapTests.PUT_MOVE)); }
|
||||
|
||||
@Override
|
||||
public Int2IntNavigableMap createMap(int[] keys, int[] values)
|
||||
{
|
||||
return new Int2IntRBTreeMap(keys, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Int2IntNavigableMap createEmptyMap()
|
||||
{
|
||||
return new Int2IntRBTreeMap();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package speiger.src.collections.tests;
|
||||
|
||||
public enum MapTests
|
||||
{
|
||||
PUT,
|
||||
PUT_ALL,
|
||||
CONTAINS,
|
||||
REPLACE,
|
||||
COMPUTE,
|
||||
MERGE,
|
||||
GET,
|
||||
ITERATORS,
|
||||
REMOVE;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package speiger.src.collections.tests;
|
||||
|
||||
public enum NavigableMapTests
|
||||
{
|
||||
DESENDING,
|
||||
LOWER,
|
||||
HIGHER,
|
||||
CEILING,
|
||||
FLOOR,
|
||||
SUB_SET,
|
||||
HEAD_SET,
|
||||
TAIL_SET;
|
||||
}
|
|
@ -2,6 +2,7 @@ package speiger.src.collections.tests;
|
|||
|
||||
public enum NavigableSetTest
|
||||
{
|
||||
DESENDING,
|
||||
LOWER,
|
||||
HIGHER,
|
||||
CEILING,
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package speiger.src.collections.tests;
|
||||
|
||||
public enum SortedMapTests
|
||||
{
|
||||
PUT_MOVE,
|
||||
MOVE,
|
||||
GET_MOVE,
|
||||
FIRST,
|
||||
LAST,
|
||||
SUB_MAP,
|
||||
TAIL_MAP,
|
||||
HEAD_MAP;
|
||||
}
|
Loading…
Reference in New Issue