Compare commits
10
Commits
1f1aa995df
...
0.4.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffc34a131f | ||
|
|
a38e7b069a | ||
|
|
9c15980e68 | ||
|
|
a05689017e | ||
|
|
54c9660145 | ||
|
|
0c4ef7f6c4 | ||
|
|
61d7a88c82 | ||
|
|
dff173222d | ||
|
|
6eded1f4be | ||
|
|
07b715dd4c |
@@ -1,5 +1,20 @@
|
||||
# Changelog of versions
|
||||
|
||||
### Version 0.4.4
|
||||
- Fixed: ObjectArrayList.of was causing crashes because of a Poor implementation.
|
||||
- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they were modified during a rehash.
|
||||
- Added: Array/Collection version of enqueue and enqueueFirst to PriorityQueues.
|
||||
- Added: fillBuffer function into PrimitiveLists which allow to optimize JavaNio buffers if needed.
|
||||
|
||||
### Version 0.4.3
|
||||
- Added: Wrapper now support the Optimized Lambda replacer functions to improve performance.
|
||||
- Added: FIFO Queue has now a minimum capacity and that is now checked more consistently.
|
||||
|
||||
### Version 0.4.2
|
||||
- Added: Lists/Sets/Maps/PriorityQueues are now copy-able. with the new copy() function.
|
||||
Note: subLists/subMaps/subSets or synchronize/unmodifyable wrappers do not support that function.
|
||||
- Fixed: PriorityQueues didn't implement: hashCode/equals/toString
|
||||
|
||||
### Version 0.4.1
|
||||
- Changed: ForEach with input now provides input, value instead of value, input, this improves the usage of method references greatly
|
||||
- Added: addAll with Array-types in collections.
|
||||
|
||||
@@ -23,15 +23,17 @@ But its focus is a different one.
|
||||
New Specialized functions that were added to increase performance or reduce allocations or Quality Of life.
|
||||
To highlight things that may be wanted.
|
||||
- Iterable:
|
||||
- map/flatMap/arrayFlatMap: A Light weight version of Stream.map()
|
||||
- map/flatMap/arrayFlatMap: A Light weight version of Stream.map().
|
||||
- findFirst: Allows to find the first element of a Predicated Iterable.
|
||||
- filter: Allows to filter unwanted elements for wrapped Iterable
|
||||
- matchAny/matchNone/matchAll: Allows to find elements in a collection.
|
||||
- count: counts all valid elements in a collection
|
||||
- count: counts all valid elements in a collection.
|
||||
- forEach: Allows to input a second element into a forEach move allowing for more flexibility for Method References
|
||||
- Collection:
|
||||
- containsAny: Allows to test if another collection contains an of the elements of the tested collection.
|
||||
- primitiveStream: Provides access to the closest Java Stream Type.
|
||||
- copy: shallowCopies the collection, used instead of clone because this is better to use.
|
||||
(subCollections/synchronized/unmodifiable not supported for obvious reasons)
|
||||
- List:
|
||||
- add/get/removeElements (From FastUtil): Allows to add/get/remove an Array into/from a list. Just with less overhead
|
||||
- extractElements: Allows to remove a Range of elements from the List and get what was removed.
|
||||
@@ -70,13 +72,16 @@ repositories {
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
compile 'de.speiger:Primitive-Collections:0.4.1'
|
||||
compile 'de.speiger:Primitive-Collections:0.4.4'
|
||||
}
|
||||
```
|
||||
Direct:
|
||||
|
||||
| Version | Jar | Sources | Java Doc |
|
||||
|--------- |------------------------------------------------------------------------------------------------------------------------------ |-------------------------------------------------------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 0.4.4 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-javadoc.jar) |
|
||||
| 0.4.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-javadoc.jar) |
|
||||
| 0.4.2 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-javadoc.jar) |
|
||||
| 0.4.1 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-javadoc.jar) |
|
||||
| 0.4.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-javadoc.jar) |
|
||||
| 0.3.6 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-javadoc.jar) |
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ repositories {
|
||||
}
|
||||
|
||||
archivesBaseName = 'Primitive Collections'
|
||||
version = '0.4.1';
|
||||
version = '0.4.4';
|
||||
|
||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ public class GlobalVariables
|
||||
addSimpleMapper("JAVA_UNARY_OPERATOR", type.isObject() ? "BinaryOperator" : type == ClassType.BOOLEAN ? "" : type.getCustomJDKType().getFileType()+"UnaryOperator");
|
||||
addSimpleMapper("JAVA_SPLIT_ITERATOR", type.isPrimitiveBlocking() ? "Spliterator" : "Of"+type.getCustomJDKType().getFileType());
|
||||
addSimpleMapper("JAVA_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Stream");
|
||||
addSimpleMapper("JAVA_BUFFER", type.getFileType()+"Buffer");
|
||||
|
||||
//Final Classes
|
||||
addClassMapper("ARRAY_LIST", "ArrayList");
|
||||
@@ -184,6 +185,7 @@ public class GlobalVariables
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
|
||||
addAbstractMapper("ABSTRACT_PRIORITY_QUEUE", "Abstract%sPriorityQueue");
|
||||
addAbstractMapper("ABSTRACT_SET", "Abstract%sSet");
|
||||
addAbstractMapper("ABSTRACT_LIST", "Abstract%sList");
|
||||
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
|
||||
|
||||
@@ -78,6 +78,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
nameRemapper.put("IArray", "I%sArray");
|
||||
nameRemapper.put("AbstractMap", "Abstract%sMap");
|
||||
nameRemapper.put("AbstractCollection", "Abstract%sCollection");
|
||||
nameRemapper.put("AbstractPriorityQueue", "Abstract%sPriorityQueue");
|
||||
nameRemapper.put("AbstractSet", "Abstract%sSet");
|
||||
nameRemapper.put("AbstractList", "Abstract%sList");
|
||||
nameRemapper.put("EnumMap", "Enum2%sMap");
|
||||
|
||||
+3
@@ -35,6 +35,9 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
|
||||
+9
@@ -123,6 +123,15 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
||||
*/
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Function that does a shallow clone of the Collection itself.
|
||||
* This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted.
|
||||
* It can be compared to Cloneable but with less exception risk
|
||||
* @return a Shallow Copy of the collection
|
||||
* @note Wrappers and view collections will not support this feature
|
||||
*/
|
||||
public COLLECTION KEY_GENERIC_TYPE copy();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||
|
||||
@@ -229,6 +229,8 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
while(size < size()) REMOVE(size() - 1);
|
||||
}
|
||||
|
||||
public ABSTRACT_LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
private class SUB_LIST extends ABSTRACT_LIST KEY_GENERIC_TYPE {
|
||||
ABSTRACT_LIST KEY_GENERIC_TYPE l;
|
||||
int offset;
|
||||
|
||||
+17
-2
@@ -15,6 +15,7 @@ import java.util.function.UnaryOperator;
|
||||
#if PRIMITIVES
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||
import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
@@ -181,7 +182,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c) {
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
list.data = (KEY_TYPE[])ObjectArrays.newArray(c.getClass().getComponentType(), 0);
|
||||
list.data = (KEY_TYPE[])ObjectArrays.newArray(c, 0);
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -388,9 +389,15 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
size -= length;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
@Override
|
||||
public void fillBuffer(JAVA_BUFFER buffer) {
|
||||
buffer.put(data, 0, size);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A function to find if the Element is present in this list.
|
||||
* @param o the element that is searched for
|
||||
@@ -1015,6 +1022,14 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
grow(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ARRAY_LIST KEY_GENERIC_TYPE copy() {
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
list.data = Arrays.copyOf(data, data.length);
|
||||
list.size = size;
|
||||
return list;
|
||||
}
|
||||
|
||||
protected void grow(int capacity) {
|
||||
if(capacity < data.length) return;
|
||||
data = Arrays.copyOf(data, data == ARRAYS.EMPTY_ARRAY ? Math.max(DEFAULT_ARRAY_SIZE, capacity) : (int)Math.max(Math.min((long)data.length + (data.length >> 1), SanityChecks.MAX_ARRAY_SIZE), capacity));
|
||||
|
||||
+5
@@ -261,6 +261,11 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
return data[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMMUTABLE_LIST KEY_GENERIC_TYPE copy() {
|
||||
return new IMMUTABLE_LISTBRACES(Arrays.copyOf(data, data.length));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific foreach function that reduces (un)boxing
|
||||
*
|
||||
|
||||
@@ -2,6 +2,8 @@ package speiger.src.collections.PACKAGE.lists;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
#else if PRIMITIVES
|
||||
import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
@@ -637,6 +639,14 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return d;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
@Override
|
||||
public void fillBuffer(JAVA_BUFFER buffer) {
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next)
|
||||
buffer.put(entry.value);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Primitive
|
||||
@@ -820,6 +830,23 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
size = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_LIST KEY_GENERIC_TYPE copy() {
|
||||
LINKED_LIST KEY_GENERIC_TYPE list = new LINKED_LISTBRACES();
|
||||
list.size = size;
|
||||
if(first != null) {
|
||||
list.first = new EntryBRACES(first.value, null, null);
|
||||
Entry KEY_GENERIC_TYPE lastReturned = list.first;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first.next;entry != null;entry = entry.next) {
|
||||
Entry KEY_GENERIC_TYPE next = new EntryBRACES(entry.value, lastReturned, null);
|
||||
lastReturned.next = next;
|
||||
lastReturned = next;
|
||||
}
|
||||
list.last = lastReturned;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected Entry KEY_GENERIC_TYPE getNode(int index) {
|
||||
if(index < size >> 2) {
|
||||
Entry KEY_GENERIC_TYPE x = first;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package speiger.src.collections.PACKAGE.lists;
|
||||
|
||||
#if PRIMITIVES
|
||||
import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
import java.util.List;
|
||||
#if !TYPE_OBJECT && !TYPE_BOOLEAN
|
||||
import java.util.Objects;
|
||||
@@ -255,6 +258,14 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
*/
|
||||
public KEY_TYPE[] extractElements(int from, int to);
|
||||
|
||||
#if PRIMITIVES
|
||||
/**
|
||||
* Helper function that allows to fastFill a buffer reducing the duplication requirement
|
||||
* @param buffer where the data should be stored in.
|
||||
*/
|
||||
public default void fillBuffer(JAVA_BUFFER buffer) { buffer.put(TO_ARRAY()); }
|
||||
|
||||
#endif
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
@@ -339,6 +350,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||
*/
|
||||
public void size(int size);
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE copy();
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
||||
+5
@@ -47,6 +47,11 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
|
||||
+24
@@ -1,5 +1,6 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.customHash;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -336,6 +337,23 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_CUSTOM_HASH_MAPKV_BRACES(0, loadFactor, strategy);
|
||||
map.minCapacity = minCapacity;
|
||||
map.mask = mask;
|
||||
map.maxFill = maxFill;
|
||||
map.nullIndex = nullIndex;
|
||||
map.containsNull = containsNull;
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, values.length);
|
||||
map.links = Arrays.copyOf(links, links.length);
|
||||
map.firstIndex = firstIndex;
|
||||
map.lastIndex = lastIndex;
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -653,6 +671,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return new FastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
int index = firstIndex;
|
||||
@@ -861,6 +882,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return new KeyIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_CUSTOM_HASH_MAP.this.size();
|
||||
|
||||
+22
-1
@@ -1,6 +1,7 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.customHash;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
@@ -423,6 +424,20 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new CUSTOM_HASH_MAPKV_BRACES(0, loadFactor, strategy);
|
||||
map.minCapacity = minCapacity;
|
||||
map.mask = mask;
|
||||
map.maxFill = maxFill;
|
||||
map.nullIndex = nullIndex;
|
||||
map.containsNull = containsNull;
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, values.length);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@@ -653,7 +668,10 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
VALUE_TYPE[] newValues = NEW_VALUE_ARRAY(newSize + 1);
|
||||
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
|
||||
while(strategy.equals(keys[--i], EMPTY_KEY_VALUE));
|
||||
while(true) {
|
||||
if(--i < 0) throw new ConcurrentModificationException("Map was modified during rehash");
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) break;
|
||||
}
|
||||
if(!strategy.equals(newKeys[pos = HashUtil.mix(strategy.hashCode(keys[i])) & newMask], EMPTY_KEY_VALUE))
|
||||
while(!strategy.equals(newKeys[pos = (++pos & newMask)], EMPTY_KEY_VALUE));
|
||||
newKeys[pos] = keys[i];
|
||||
@@ -964,6 +982,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return new KeyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return CUSTOM_HASH_MAP.this.size();
|
||||
|
||||
+24
@@ -1,5 +1,6 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.hash;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -313,6 +314,23 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_HASH_MAPKV_BRACES(0, loadFactor);
|
||||
map.minCapacity = minCapacity;
|
||||
map.mask = mask;
|
||||
map.maxFill = maxFill;
|
||||
map.nullIndex = nullIndex;
|
||||
map.containsNull = containsNull;
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, values.length);
|
||||
map.links = Arrays.copyOf(links, links.length);
|
||||
map.firstIndex = firstIndex;
|
||||
map.lastIndex = lastIndex;
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -630,6 +648,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return new FastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
int index = firstIndex;
|
||||
@@ -838,6 +859,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return new KeyIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_HASH_MAP.this.size();
|
||||
|
||||
+23
-2
@@ -1,6 +1,7 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.hash;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
@@ -383,7 +384,21 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
return slot < 0 ? defaultValue : values[slot];
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
HASH_MAP KEY_VALUE_GENERIC_TYPE map = new HASH_MAPKV_BRACES(0, loadFactor);
|
||||
map.minCapacity = minCapacity;
|
||||
map.mask = mask;
|
||||
map.maxFill = maxFill;
|
||||
map.nullIndex = nullIndex;
|
||||
map.containsNull = containsNull;
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, values.length);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@@ -613,7 +628,10 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
VALUE_TYPE[] newValues = NEW_VALUE_ARRAY(newSize + 1);
|
||||
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
|
||||
while(KEY_EQUALS_NULL(keys[--i]));
|
||||
while(true) {
|
||||
if(--i < 0) throw new ConcurrentModificationException("Map was modified during rehash");
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) break;
|
||||
}
|
||||
if(KEY_EQUALS_NOT_NULL(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask]))
|
||||
while(KEY_EQUALS_NOT_NULL(newKeys[pos = (++pos & newMask)]));
|
||||
newKeys[pos] = keys[i];
|
||||
@@ -934,6 +952,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
HASH_MAP.this.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
if(containsNull) action.accept(keys[nullIndex]);
|
||||
|
||||
+27
-1
@@ -1,7 +1,8 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.immutable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
@@ -103,6 +104,10 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
/** Amount of Elements stored in the HashMap */
|
||||
protected int size;
|
||||
|
||||
/**
|
||||
* Helper constructor for copying the Map
|
||||
*/
|
||||
protected IMMUTABLE_HASH_MAP() {}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
@@ -412,6 +417,21 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new IMMUTABLE_HASH_MAPKV_BRACES();
|
||||
map.mask = mask;
|
||||
map.nullIndex = nullIndex;
|
||||
map.containsNull = containsNull;
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, values.length);
|
||||
map.links = Arrays.copyOf(links, links.length);
|
||||
map.firstIndex = firstIndex;
|
||||
map.lastIndex = lastIndex;
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
@Override
|
||||
@@ -589,6 +609,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return new FastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
int index = firstIndex;
|
||||
@@ -773,6 +796,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return new KeyIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return IMMUTABLE_HASH_MAP.this.size();
|
||||
|
||||
+25
@@ -554,6 +554,14 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
size = 0;
|
||||
}
|
||||
|
||||
public ARRAY_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
ARRAY_MAP KEY_VALUE_GENERIC_TYPE map = new ARRAY_MAPKV_BRACES();
|
||||
map.size = size;
|
||||
map.keys = Arrays.copyOf(keys, keys.length);
|
||||
map.values = Arrays.copyOf(values, keys.length);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -981,6 +989,11 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return entrySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubMap copy() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -1133,6 +1146,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return new SubFastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubMapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1316,6 +1332,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public SubKeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1698,6 +1717,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return new FastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1882,6 +1904,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
|
||||
+9
@@ -176,6 +176,15 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public ENUM_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
ENUM_MAP KEY_VALUE_GENERIC_TYPE map = new ENUM_MAPKV_BRACES(keyType);
|
||||
map.size = size;
|
||||
System.arraycopy(present, 0, map.present, 0, Math.min(present.length, map.present.length));
|
||||
System.arraycopy(values, 0, map.values, 0, Math.min(values.length, map.values.length));
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new EntrySet();
|
||||
|
||||
+16
@@ -127,6 +127,18 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_ENUM_MAPKV_BRACES(keyType);
|
||||
map.size = size;
|
||||
System.arraycopy(present, 0, map.present, 0, Math.min(present.length, map.present.length));
|
||||
System.arraycopy(values, 0, map.values, 0, Math.min(values.length, map.values.length));
|
||||
System.arraycopy(links, 0, map.links, 0, Math.min(links.length, map.links.length));
|
||||
map.firstIndex = firstIndex;
|
||||
map.lastIndex = lastIndex;
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -351,6 +363,8 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return new FastEntryIterator(fromElement);
|
||||
}
|
||||
|
||||
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
int index = firstIndex;
|
||||
@@ -477,6 +491,8 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return new KeyIterator(fromElement);
|
||||
}
|
||||
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return LINKED_ENUM_MAP.this.size();
|
||||
|
||||
+36
-1
@@ -610,6 +610,21 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return new KeyIterator(findNode(key));
|
||||
}
|
||||
|
||||
public AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE set = new AVL_TREE_MAPKV_BRACES();
|
||||
set.size = size;
|
||||
if(tree != null) {
|
||||
set.tree = tree.copy();
|
||||
Entry KEY_VALUE_GENERIC_TYPE lastFound = null;
|
||||
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
|
||||
set.first = lastFound;
|
||||
lastFound = null;
|
||||
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
|
||||
set.last = lastFound;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE keySet() {
|
||||
return navigableKeySet();
|
||||
@@ -1133,7 +1148,8 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
abstract AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE next(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
|
||||
abstract AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE previous(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
|
||||
|
||||
|
||||
@Override
|
||||
public NavigableSubMap KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public abstract NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap();
|
||||
@Override
|
||||
@@ -1952,6 +1968,9 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KeySet KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
|
||||
return new KeySetKV_BRACES(m.subMap(fromElement, fromInclusive, toElement, toInclusive));
|
||||
@@ -2320,6 +2339,22 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
Entry KEY_VALUE_GENERIC_TYPE copy() {
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = new EntryKV_BRACES(key, value, null);
|
||||
entry.state = state;
|
||||
if(left != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE newLeft = left.copy();
|
||||
entry.left = newLeft;
|
||||
newLeft.parent = entry;
|
||||
}
|
||||
if(right != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE newRight = right.copy();
|
||||
entry.right = newRight;
|
||||
newRight.parent = entry;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return key;
|
||||
|
||||
+36
@@ -609,6 +609,21 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return new KeyIterator(findNode(key));
|
||||
}
|
||||
|
||||
public RB_TREE_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||
RB_TREE_MAP KEY_VALUE_GENERIC_TYPE set = new RB_TREE_MAPKV_BRACES();
|
||||
set.size = size;
|
||||
if(tree != null) {
|
||||
set.tree = tree.copy();
|
||||
Entry KEY_VALUE_GENERIC_TYPE lastFound = null;
|
||||
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
|
||||
set.first = lastFound;
|
||||
lastFound = null;
|
||||
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
|
||||
set.last = lastFound;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE keySet() {
|
||||
return navigableKeySet();
|
||||
@@ -1187,6 +1202,8 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
abstract RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE next(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
|
||||
abstract RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE previous(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
|
||||
|
||||
@Override
|
||||
public NavigableSubMap KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public abstract NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap();
|
||||
@Override
|
||||
@@ -2018,6 +2035,9 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KeySet KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
|
||||
return new KeySetKV_BRACES(m.subMap(fromElement, fromInclusive, toElement, toInclusive));
|
||||
@@ -2388,6 +2408,22 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
Entry KEY_VALUE_GENERIC_TYPE copy() {
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = new EntryKV_BRACES(key, value, null);
|
||||
entry.state = state;
|
||||
if(left != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE newLeft = left.copy();
|
||||
entry.left = newLeft;
|
||||
newLeft.parent = entry;
|
||||
}
|
||||
if(right != null) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE newRight = right.copy();
|
||||
entry.right = newRight;
|
||||
newRight.parent = entry;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ENTRY_KEY() {
|
||||
return key;
|
||||
|
||||
+9
@@ -59,6 +59,15 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
*/
|
||||
public MAP KEY_VALUE_GENERIC_TYPE setDefaultReturnValue(VALUE_TYPE v);
|
||||
|
||||
/**
|
||||
* A Function that does a shallow clone of the Map itself.
|
||||
* This function is more optimized then a copy constructor since the Map does not have to be unsorted/resorted.
|
||||
* It can be compared to Cloneable but with less exception risk
|
||||
* @return a Shallow Copy of the Map
|
||||
* @note Wrappers and view Maps will not support this feature
|
||||
*/
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||
|
||||
/**
|
||||
* Type Specific method to reduce boxing/unboxing of values
|
||||
* @param key the key that should be inserted,
|
||||
|
||||
+2
@@ -10,6 +10,8 @@ import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||
*/
|
||||
public interface NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE extends SORTED_MAP KEY_VALUE_GENERIC_TYPE, NavigableMap<CLASS_TYPE, CLASS_VALUE_TYPE>
|
||||
{
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||
/** @return a Type Specific desendingMap */
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap();
|
||||
|
||||
+3
@@ -75,6 +75,9 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator();
|
||||
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet();
|
||||
@Override
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Helper class that implements all the essential methods for the PriorityQueues
|
||||
* @Type(T)
|
||||
*/
|
||||
public abstract class ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof PRIORITY_QUEUE) {
|
||||
PRIORITY_QUEUE KEY_GENERIC_TYPE queue = (PRIORITY_QUEUE KEY_GENERIC_TYPE)obj;
|
||||
if(queue.size() != size()) return false;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(KEY_EQUALS_NOT(queue.peek(i), peek(i))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
for (int i = 0,m=size();i<m;i++) {
|
||||
result = 31 * result + KEY_TO_HASH(peek(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(isEmpty()) return "[]";
|
||||
StringJoiner joiner = new StringJoiner(", ", "[", "]");
|
||||
for (int i = 0,m=size();i<m;i++) {
|
||||
joiner.add(KEY_TO_STRING(peek(i)));
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
}
|
||||
+22
-7
@@ -1,7 +1,7 @@
|
||||
package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Arrays;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
@@ -22,7 +22,7 @@ import speiger.src.collections.utils.ITrimmable;
|
||||
* Its specific implementation uses a backing array that grows and shrinks as it is needed.
|
||||
* @Type(T)
|
||||
*/
|
||||
public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, ITrimmable
|
||||
public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, ITrimmable
|
||||
{
|
||||
/** Max Possible ArraySize without the JVM Crashing */
|
||||
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
|
||||
@@ -34,6 +34,8 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
|
||||
protected int first;
|
||||
/** The Last Index pointer */
|
||||
protected int last;
|
||||
/** The Minimum Capacity of the Queue **/
|
||||
protected int minCapacity;
|
||||
|
||||
/**
|
||||
* Constructor using a initial array
|
||||
@@ -62,7 +64,9 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
|
||||
*/
|
||||
public ARRAY_FIFO_QUEUE(KEY_TYPE[] values, int offset, int size) {
|
||||
if (values.length < size) throw new IllegalArgumentException("Initial array (" + values.length + ") is smaller then the expected size (" + size + ")");
|
||||
if(values.length <= 0) values = NEW_KEY_ARRAY(1);
|
||||
if(values.length <= 0) values = NEW_KEY_ARRAY(MIN_CAPACITY);
|
||||
else if(values.length < MIN_CAPACITY) values = Arrays.copyOf(values, MIN_CAPACITY);
|
||||
minCapacity = MIN_CAPACITY;
|
||||
array = values;
|
||||
first = offset;
|
||||
last = (offset + size) % array.length;
|
||||
@@ -76,7 +80,8 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
|
||||
*/
|
||||
public ARRAY_FIFO_QUEUE(int capacity) {
|
||||
if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative");
|
||||
array = NEW_KEY_ARRAY(Math.max(1, capacity));
|
||||
array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity));
|
||||
minCapacity = array.length;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,6 +227,16 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
|
||||
@Override
|
||||
public void onChanged() {}
|
||||
|
||||
@Override
|
||||
public ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE copy() {
|
||||
ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_FIFO_QUEUEBRACES();
|
||||
queue.first = first;
|
||||
queue.last = last;
|
||||
queue.minCapacity = minCapacity;
|
||||
queue.array = Arrays.copyOf(array, array.length);
|
||||
return queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@@ -296,7 +311,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
|
||||
|
||||
@Override
|
||||
public boolean trim(int size) {
|
||||
int newSize = Math.max(size, size());
|
||||
int newSize = Math.max(Math.max(size, size()), minCapacity);
|
||||
if(newSize >= array.length) return false;
|
||||
KEY_TYPE[] newArray = NEW_KEY_ARRAY(newSize);
|
||||
if(first <= last) System.arraycopy(array, first, newArray, 0, last - first);
|
||||
@@ -317,7 +332,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
|
||||
*/
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
int newSize = Math.max(MIN_CAPACITY, size);
|
||||
int newSize = Math.max(minCapacity, size);
|
||||
if(array.length <= newSize) {
|
||||
clear();
|
||||
return;
|
||||
@@ -339,7 +354,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
|
||||
|
||||
protected void reduce() {
|
||||
final int size = size();
|
||||
if (array.length > MIN_CAPACITY && size <= array.length / 4) resize(size, array.length / 2);
|
||||
if (array.length > minCapacity && size <= array.length / 4) resize(size, Math.max(array.length / 2, minCapacity));
|
||||
}
|
||||
|
||||
protected void expand() {
|
||||
|
||||
+11
-1
@@ -24,7 +24,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
* It is highly suggested to use HeapPriorityQueue otherwise, unless you know why you need this specific implementation
|
||||
* @Type(T)
|
||||
*/
|
||||
public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing Array */
|
||||
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
||||
@@ -322,6 +322,16 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY
|
||||
return new Iter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() {
|
||||
ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES();
|
||||
queue.firstIndex = firstIndex;
|
||||
queue.size = size;
|
||||
queue.comparator = comparator;
|
||||
queue.array = Arrays.copyOf(array, array.length);
|
||||
return queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() {
|
||||
return comparator;
|
||||
|
||||
+10
-1
@@ -23,7 +23,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
* It is a ArrayBased Alternative to TreeSets that has less object allocations
|
||||
* @Type(T)
|
||||
*/
|
||||
public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing Array */
|
||||
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
||||
@@ -319,6 +319,15 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_
|
||||
ARRAYS.shiftDown(array, size, 0, comparator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() {
|
||||
HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES();
|
||||
queue.size = size;
|
||||
queue.comparator = comparator;
|
||||
queue.array = Arrays.copyOf(array, array.length);
|
||||
return queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() {
|
||||
return comparator;
|
||||
|
||||
+60
@@ -1,5 +1,12 @@
|
||||
package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
/**
|
||||
* A Type Speciifc PriorityDeque or Dequeue interface to allow implementations like FIFO queues.
|
||||
* @Type(T)
|
||||
@@ -11,6 +18,56 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
|
||||
* @param e the element that should be inserted into the first place
|
||||
*/
|
||||
public void enqueueFirst(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* Method to mass insert a elements into the first Index of the PriorityDequeue.
|
||||
* @param e the elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAllFirst(KEY_TYPE... e) {
|
||||
enqueueAllFirst(e, 0, e.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert a elements into the first Index of the PriorityDequeue.
|
||||
* @param e the elements that should be inserted
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAllFirst(KEY_TYPE[] e, int length) {
|
||||
enqueueAllFirst(e, 0, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert a elements into the first Index of the PriorityDequeue.
|
||||
* @param e the elements that should be inserted
|
||||
* @param offset the offset where in the array should be started
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAllFirst(KEY_TYPE[] e, int offset, int length) {
|
||||
for(int i = 0;i<length;i++)
|
||||
enqueueFirst(e[i+offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into first Index of the PriorityDequeue.
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAllFirst(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
enqueueFirst(iter.NEXT());
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Method to mass insert elements into first Index of the PriorityDequeue.
|
||||
* This method exists to add support for Java Collections to make it more useable
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAllFirst(Collection<? extends CLASS_TYPE> c) {
|
||||
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
|
||||
enqueueFirst(iter.next());
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Method to remove a element from the last place instead of the first
|
||||
* @return the last element inserted
|
||||
@@ -22,4 +79,7 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
|
||||
* @return the Last Element within the dequeue without deleting it
|
||||
*/
|
||||
public default KEY_TYPE last() { return peek(size()-1); }
|
||||
|
||||
@Override
|
||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
|
||||
}
|
||||
+64
-1
@@ -2,11 +2,14 @@ package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
/**
|
||||
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
|
||||
@@ -33,6 +36,57 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
||||
* @param e the element that should be inserted
|
||||
*/
|
||||
public void enqueue(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE... e) {
|
||||
enqueueAll(e, 0, e.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE[] e, int length) {
|
||||
enqueueAll(e, 0, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
* @param offset the offset where in the array should be started
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE[] e, int offset, int length) {
|
||||
for(int i = 0;i<length;i++)
|
||||
enqueue(e[i+offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
enqueue(iter.NEXT());
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* This method exists to add support for Java Collections to make it more useable
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAll(Collection<? extends CLASS_TYPE> c) {
|
||||
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
|
||||
enqueue(iter.next());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Method to extract a element from the PriorityQueue
|
||||
* @return a element from the Queue
|
||||
@@ -70,6 +124,15 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
||||
*/
|
||||
public void onChanged();
|
||||
|
||||
/**
|
||||
* A Function that does a shallow clone of the PriorityQueue itself.
|
||||
* This function is more optimized then a copy constructor since the PriorityQueue does not have to be unsorted/resorted.
|
||||
* It can be compared to Cloneable but with less exception risk
|
||||
* @return a Shallow Copy of the PriorityQueue
|
||||
* @note Wrappers and view PriorityQueues will not support this feature
|
||||
*/
|
||||
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy();
|
||||
|
||||
/**
|
||||
* @return the sorter of the Queue, can be null
|
||||
*/
|
||||
|
||||
@@ -538,6 +538,21 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
tree = null;
|
||||
}
|
||||
|
||||
public AVL_TREE_SET KEY_GENERIC_TYPE copy() {
|
||||
AVL_TREE_SET KEY_GENERIC_TYPE set = new AVL_TREE_SETBRACES();
|
||||
set.size = size;
|
||||
if(tree != null) {
|
||||
set.tree = tree.copy();
|
||||
Entry KEY_GENERIC_TYPE lastFound = null;
|
||||
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
|
||||
set.first = lastFound;
|
||||
lastFound = null;
|
||||
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
|
||||
set.last = lastFound;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||
|
||||
@@ -1009,6 +1024,9 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubSet KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1250,6 +1268,22 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
Entry KEY_GENERIC_TYPE copy() {
|
||||
Entry KEY_GENERIC_TYPE entry = new EntryBRACES(key, null);
|
||||
entry.state = state;
|
||||
if(left != null) {
|
||||
Entry KEY_GENERIC_TYPE newLeft = left.copy();
|
||||
entry.left = newLeft;
|
||||
newLeft.parent = entry;
|
||||
}
|
||||
if(right != null) {
|
||||
Entry KEY_GENERIC_TYPE newRight = right.copy();
|
||||
entry.right = newRight;
|
||||
newRight.parent = entry;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
int getHeight() { return state; }
|
||||
|
||||
void updateHeight() { state = (1 + Math.max(left == null ? -1 : left.getHeight(), right == null ? -1 : right.getHeight())); }
|
||||
|
||||
@@ -15,6 +15,8 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
{
|
||||
@Override
|
||||
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
@Override
|
||||
public ABSTRACT_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
@@ -450,6 +450,13 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
return new SubSet(fromIndex, size - fromIndex);
|
||||
}
|
||||
|
||||
public ARRAY_SET KEY_GENERIC_TYPE copy() {
|
||||
ARRAY_SET KEY_GENERIC_TYPE set = new ARRAY_SETBRACES();
|
||||
set.data = Arrays.copyOf(data, data.length);
|
||||
set.size = size;
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
@@ -675,7 +682,10 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
if(index != -1) return new SetIterator(index);
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SubSet copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) {
|
||||
int fromIndex = findIndex(fromElement);
|
||||
|
||||
+21
@@ -4,6 +4,7 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -50,6 +51,12 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
/** The Last Index in the Map */
|
||||
protected int lastIndex = -1;
|
||||
|
||||
/**
|
||||
* Helper constructor to optimize the copying
|
||||
* Only accessible through implementations
|
||||
*/
|
||||
protected IMMUTABLE_HASH_SET() {}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a set from unboxed values
|
||||
* @param array the elements that should be put into the set
|
||||
@@ -372,6 +379,20 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
return new SetIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMMUTABLE_HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
IMMUTABLE_HASH_SET KEY_GENERIC_TYPE set = new IMMUTABLE_HASH_SETBRACES();
|
||||
set.containsNull = containsNull;
|
||||
set.firstIndex = firstIndex;
|
||||
set.lastIndex = lastIndex;
|
||||
set.size = size;
|
||||
set.mask = mask;
|
||||
set.nullIndex = nullIndex;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
set.links = Arrays.copyOf(links, links.length);
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
|
||||
+17
@@ -4,6 +4,7 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
@@ -609,6 +610,22 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
return new SetIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE set = new LINKED_CUSTOM_HASH_SETBRACES(0, loadFactor, strategy);
|
||||
set.minCapacity = minCapacity;
|
||||
set.mask = mask;
|
||||
set.maxFill = maxFill;
|
||||
set.nullIndex = nullIndex;
|
||||
set.containsNull = containsNull;
|
||||
set.size = size;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
set.links = Arrays.copyOf(links, links.length);
|
||||
set.firstIndex = firstIndex;
|
||||
set.lastIndex = lastIndex;
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
|
||||
+17
@@ -3,6 +3,7 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -580,6 +581,22 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
return new SetIterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LINKED_HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
LINKED_HASH_SET KEY_GENERIC_TYPE set = new LINKED_HASH_SETBRACES(0, loadFactor);
|
||||
set.minCapacity = minCapacity;
|
||||
set.mask = mask;
|
||||
set.maxFill = maxFill;
|
||||
set.nullIndex = nullIndex;
|
||||
set.containsNull = containsNull;
|
||||
set.size = size;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
set.links = Arrays.copyOf(links, links.length);
|
||||
set.firstIndex = firstIndex;
|
||||
set.lastIndex = lastIndex;
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
|
||||
@@ -115,6 +115,8 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
||||
/** @return a Type Specific desendingSet */
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet();
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy();
|
||||
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
|
||||
+18
-1
@@ -2,6 +2,7 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
@@ -429,7 +430,10 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
int newMask = newSize - 1;
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
|
||||
while(strategy.equals(keys[--i], EMPTY_KEY_VALUE));
|
||||
while(true) {
|
||||
if(--i < 0) throw new ConcurrentModificationException("Set was modified during rehash");
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) break;
|
||||
}
|
||||
if(!strategy.equals(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask], EMPTY_KEY_VALUE))
|
||||
while(!strategy.equals(newKeys[pos = (++pos & newMask)], EMPTY_KEY_VALUE));
|
||||
newKeys[pos] = keys[i];
|
||||
@@ -445,6 +449,19 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
return new SetIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CUSTOM_HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
CUSTOM_HASH_SET KEY_GENERIC_TYPE set = new CUSTOM_HASH_SETBRACES(0, loadFactor, strategy);
|
||||
set.minCapacity = minCapacity;
|
||||
set.mask = mask;
|
||||
set.maxFill = maxFill;
|
||||
set.nullIndex = nullIndex;
|
||||
set.containsNull = containsNull;
|
||||
set.size = size;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if(size == 0) return;
|
||||
|
||||
+18
-1
@@ -2,6 +2,7 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
@@ -461,7 +462,10 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
int newMask = newSize - 1;
|
||||
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
||||
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
|
||||
while(KEY_EQUALS_NULL(keys[--i]));
|
||||
while(true) {
|
||||
if(--i < 0) throw new ConcurrentModificationException("Set was modified during rehash");
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i])) break;
|
||||
}
|
||||
if(KEY_EQUALS_NOT_NULL(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask]))
|
||||
while(KEY_EQUALS_NOT_NULL(newKeys[pos = (++pos & newMask)]));
|
||||
newKeys[pos] = keys[i];
|
||||
@@ -477,6 +481,19 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
return new SetIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HASH_SET KEY_GENERIC_TYPE copy() {
|
||||
HASH_SET KEY_GENERIC_TYPE set = new HASH_SETBRACES(0, loadFactor);
|
||||
set.minCapacity = minCapacity;
|
||||
set.mask = mask;
|
||||
set.maxFill = maxFill;
|
||||
set.nullIndex = nullIndex;
|
||||
set.containsNull = containsNull;
|
||||
set.size = size;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if(size == 0) return;
|
||||
|
||||
@@ -540,6 +540,21 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
tree = null;
|
||||
}
|
||||
|
||||
public RB_TREE_SET KEY_GENERIC_TYPE copy() {
|
||||
RB_TREE_SET KEY_GENERIC_TYPE set = new RB_TREE_SETBRACES();
|
||||
set.size = size;
|
||||
if(tree != null) {
|
||||
set.tree = tree.copy();
|
||||
Entry KEY_GENERIC_TYPE lastFound = null;
|
||||
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
|
||||
set.first = lastFound;
|
||||
lastFound = null;
|
||||
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
|
||||
set.last = lastFound;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||
|
||||
@@ -1070,6 +1085,9 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubSet KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -1314,6 +1332,22 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
Entry KEY_GENERIC_TYPE copy() {
|
||||
Entry KEY_GENERIC_TYPE entry = new EntryBRACES(key, null);
|
||||
entry.state = state;
|
||||
if(left != null) {
|
||||
Entry KEY_GENERIC_TYPE newLeft = left.copy();
|
||||
entry.left = newLeft;
|
||||
newLeft.parent = entry;
|
||||
}
|
||||
if(right != null) {
|
||||
Entry KEY_GENERIC_TYPE newRight = right.copy();
|
||||
entry.right = newRight;
|
||||
newRight.parent = entry;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
boolean isBlack() {
|
||||
return (state & BLACK) != 0;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ public interface SET KEY_GENERIC_TYPE extends Set<CLASS_TYPE>, COLLECTION KEY_GE
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE copy();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific remove function to reduce boxing/unboxing
|
||||
|
||||
@@ -60,6 +60,9 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator();
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE copy();
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
/**
|
||||
|
||||
+33
-1
@@ -15,7 +15,8 @@ import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
/**
|
||||
* A Helper class for Collections
|
||||
*/
|
||||
@@ -128,6 +129,9 @@ public class COLLECTIONS
|
||||
return c.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public boolean remove(Object o) { synchronized(mutex) { return c.remove(o); } }
|
||||
@@ -177,6 +181,18 @@ public class COLLECTIONS
|
||||
public boolean equals(Object obj) { synchronized(mutex) { return c.equals(obj); } }
|
||||
@Override
|
||||
public String toString() { synchronized(mutex) { return c.toString(); } }
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { synchronized(mutex) { c.forEach(input, action); } }
|
||||
@Override
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAny(filter); } }
|
||||
@Override
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesNone(filter); } }
|
||||
@Override
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAll(filter); } }
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.findFirst(filter); } }
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.count(filter); } }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,6 +238,8 @@ public class COLLECTIONS
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(c.iterator()); }
|
||||
@Override
|
||||
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean remove(Object o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -273,6 +291,18 @@ public class COLLECTIONS
|
||||
public boolean equals(Object obj) { return c.equals(obj); }
|
||||
@Override
|
||||
public String toString() { return c.toString(); }
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { c.forEach(input, action); }
|
||||
@Override
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAny(filter); }
|
||||
@Override
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesNone(filter); }
|
||||
@Override
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAll(filter); }
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); }
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { return c.count(filter); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -358,5 +388,7 @@ public class COLLECTIONS
|
||||
public void clear() {}
|
||||
@Override
|
||||
public int size() { return 0; }
|
||||
@Override
|
||||
public EmptyCollection KEY_GENERIC_TYPE copy() { return this; }
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.RandomAccess;
|
||||
import java.util.function.Consumer;
|
||||
#if PRIMITIVES
|
||||
import java.nio.JAVA_BUFFER;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
@@ -204,7 +207,11 @@ public class LISTS
|
||||
a[offset] = element;
|
||||
return a;
|
||||
}
|
||||
|
||||
#if PRIMITIVES
|
||||
@Override
|
||||
public void fillBuffer(JAVA_BUFFER buffer) { buffer.put(element); }
|
||||
#endif
|
||||
|
||||
@Override
|
||||
public void removeElements(int from, int to) { throw new UnsupportedOperationException(); }
|
||||
#if TYPE_OBJECT
|
||||
@@ -216,6 +223,9 @@ public class LISTS
|
||||
#endif
|
||||
@Override
|
||||
public int size() { return 1; }
|
||||
|
||||
@Override
|
||||
public SingletonList KEY_GENERIC_TYPE copy() { return new SingletonListBRACES(element); }
|
||||
}
|
||||
|
||||
private static class SynchronizedArrayList KEY_GENERIC_TYPE extends SynchronizedList KEY_GENERIC_TYPE implements IARRAY KEY_GENERIC_TYPE
|
||||
@@ -354,6 +364,9 @@ public class LISTS
|
||||
@Override
|
||||
public <K> K[] extractElements(int from, int to, Class<K> clz) { synchronized(mutex) { return l.extractElements(from, to, clz); } }
|
||||
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
public void fillBuffer(JAVA_BUFFER buffer) { synchronized(mutex) { l.fillBuffer(buffer); } }
|
||||
#endif
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() {
|
||||
@@ -372,6 +385,9 @@ public class LISTS
|
||||
|
||||
@Override
|
||||
public void size(int size) { synchronized(mutex) { l.size(size); } }
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
private static class UnmodifiableRandomList KEY_GENERIC_TYPE extends UnmodifiableList KEY_GENERIC_TYPE implements RandomAccess
|
||||
@@ -463,6 +479,10 @@ public class LISTS
|
||||
@Override
|
||||
public <K> K[] extractElements(int from, int to, Class<K> clz) { throw new UnsupportedOperationException(); }
|
||||
|
||||
#endif
|
||||
#if PRIMITIVES
|
||||
public void fillBuffer(JAVA_BUFFER buffer) { l.fillBuffer(buffer); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() {
|
||||
@@ -481,6 +501,9 @@ public class LISTS
|
||||
|
||||
@Override
|
||||
public void size(int size) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
private static class EmptyList KEY_GENERIC_TYPE extends COLLECTIONS.EmptyCollection KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
|
||||
@@ -563,5 +586,8 @@ public class LISTS
|
||||
|
||||
@Override
|
||||
public void size(int size) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public EmptyList KEY_GENERIC_TYPE copy() { return this; }
|
||||
}
|
||||
}
|
||||
|
||||
+42
@@ -1,15 +1,23 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
|
||||
/**
|
||||
* A Helper class for PriorityQueues
|
||||
@@ -86,6 +94,14 @@ public class PRIORITY_QUEUES
|
||||
public void clear() { synchronized(mutex) { queue.clear(); } }
|
||||
@Override
|
||||
public void enqueue(KEY_TYPE e) { synchronized(mutex) { queue.enqueue(e); } }
|
||||
@Override
|
||||
public void enqueueAll(KEY_TYPE[] e, int offset, int length) { synchronized(mutex) { queue.enqueueAll(e, offset, length); } }
|
||||
@Override
|
||||
public void enqueueAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { queue.enqueueAll(c); } }
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public void enqueueAll(Collection<? extends CLASS_TYPE> c) { synchronized(mutex) { queue.enqueueAll(c); } }
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE dequeue() { synchronized(mutex) { return queue.dequeue(); } }
|
||||
@Override
|
||||
@@ -100,6 +116,22 @@ public class PRIORITY_QUEUES
|
||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { synchronized(mutex) { return queue.comparator(); } }
|
||||
@Override
|
||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { synchronized(mutex) { return queue.TO_ARRAY(input); } }
|
||||
@Override
|
||||
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { synchronized(mutex) { queue.forEach(action); } }
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { synchronized(mutex) { queue.forEach(input, action); } }
|
||||
@Override
|
||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesAny(filter); } }
|
||||
@Override
|
||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesNone(filter); } }
|
||||
@Override
|
||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesAll(filter); } }
|
||||
@Override
|
||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.findFirst(filter); } }
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.count(filter); } }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +153,17 @@ public class PRIORITY_QUEUES
|
||||
|
||||
@Override
|
||||
public void enqueueFirst(KEY_TYPE e) { synchronized(mutex) { dequeue.enqueueFirst(e); } }
|
||||
@Override
|
||||
public void enqueueAllFirst(KEY_TYPE[] e, int offset, int length) { synchronized(mutex) { dequeue.enqueueAllFirst(e, offset, length); } }
|
||||
@Override
|
||||
public void enqueueAllFirst(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { dequeue.enqueueAllFirst(c); } }
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public void enqueueAllFirst(Collection<? extends CLASS_TYPE> c) { synchronized(mutex) { dequeue.enqueueAllFirst(c); } }
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE dequeueLast() { synchronized(mutex) { return dequeue.dequeueLast(); } }
|
||||
@Override
|
||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +190,9 @@ public class SETS
|
||||
}
|
||||
@Override
|
||||
public int size() { return 1; }
|
||||
|
||||
@Override
|
||||
public SingletonSet KEY_GENERIC_TYPE copy() { return new SingletonSetBRACES(element); }
|
||||
}
|
||||
|
||||
private static class EmptySet KEY_GENERIC_TYPE extends EmptyCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||
@@ -198,6 +201,8 @@ public class SETS
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public EmptySet KEY_GENERIC_TYPE copy() { return this; }
|
||||
}
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
@@ -245,6 +250,9 @@ public class SETS
|
||||
public KEY_TYPE getDefaultMinValue() { return n.getDefaultMinValue(); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); }
|
||||
|
||||
@@ -300,6 +308,9 @@ public class SETS
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(s.subSet(fromElement, toElement)); }
|
||||
|
||||
@@ -336,6 +347,9 @@ public class SETS
|
||||
s = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@@ -412,6 +426,9 @@ public class SETS
|
||||
public KEY_TYPE getDefaultMinValue() { synchronized(mutex) { return n.getDefaultMinValue(); } }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return synchronize(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } }
|
||||
|
||||
@@ -492,7 +509,10 @@ public class SETS
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
||||
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronize(s.subSet(fromElement, toElement), mutex); } }
|
||||
|
||||
@@ -556,6 +576,9 @@ public class SETS
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) { synchronized(mutex) { return s.remove(o); } }
|
||||
|
||||
+17
-1
@@ -277,6 +277,8 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return EQUALS_KEY_TYPE(key, this.key) ? value : defaultValue; }
|
||||
#endif
|
||||
@Override
|
||||
public SingletonMap KEY_VALUE_GENERIC_TYPE copy() { return new SingletonMapKV_BRACES(key, value); }
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keySet == null) keySet = SETS.singleton(key);
|
||||
@@ -329,6 +331,8 @@ public class MAPS
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() { return VALUE_COLLECTIONS.empty(); }
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() { return ObjectSets.empty(); }
|
||||
@Override
|
||||
public EmptyMap KEY_VALUE_GENERIC_TYPE copy() { return this; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,6 +419,8 @@ public class MAPS
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE key) { return unmodifiable(map.floorEntry(key)); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { return unmodifiable(map.ceilingEntry(key)); }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -462,6 +468,8 @@ public class MAPS
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -501,6 +509,8 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
#endif
|
||||
@Override
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
@@ -614,7 +624,9 @@ public class MAPS
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE key) { synchronized(mutex) { return map.floorEntry(key); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { synchronized(mutex) { return map.ceilingEntry(key); } }
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } }
|
||||
@@ -718,6 +730,8 @@ public class MAPS
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { synchronized(mutex) { return map.FIRST_ENTRY_VALUE(); } }
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -831,6 +845,8 @@ public class MAPS
|
||||
@Override
|
||||
public int size() { synchronized(mutex) { return super.size(); } }
|
||||
@Override
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keys == null) keys = SETS.synchronize(map.keySet(), mutex);
|
||||
return keys;
|
||||
|
||||
@@ -135,6 +135,16 @@ public abstract class BaseInt2IntMapTest
|
||||
Assert.assertTrue(map.remove(PUT_VALUE_ARRAY[51], PUT_ARRAY[51]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSort()
|
||||
{
|
||||
if(!getValidMapTests().contains(MapTests.COPY)) return;
|
||||
Int2IntMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||
Int2IntMap copy = map.copy();
|
||||
Assert.assertFalse(map == copy);
|
||||
Assert.assertEquals(map, copy);
|
||||
}
|
||||
|
||||
public static class Strategy implements IntStrategy
|
||||
{
|
||||
@Override
|
||||
|
||||
@@ -178,4 +178,13 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
|
||||
Assert.assertEquals(base, IntCollections.synchronize(collection).toString());
|
||||
Assert.assertEquals(base, IntCollections.unmodifiable(collection).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.COPY)) return;
|
||||
IntCollection collection = create(BULK_ADD_ARRAY);
|
||||
IntCollection copy = collection.copy();
|
||||
Assert.assertFalse(collection == copy);
|
||||
Assert.assertEquals(collection, copy);
|
||||
}
|
||||
}
|
||||
@@ -120,4 +120,13 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
if(!getValidPriorityQueueTests().contains(PriorityQueueTest.COPY)) return;
|
||||
IntPriorityQueue queue = create(TEST_ARRAY);
|
||||
IntPriorityQueue copy = queue.copy();
|
||||
Assert.assertFalse(queue == copy);
|
||||
Assert.assertEquals(queue, copy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,13 @@ public class ObjectArrayListTest
|
||||
testCastable(ObjectArrayList.wrap("Test", "Testing", "Testing stuff"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyCreation()
|
||||
{
|
||||
ObjectArrayList<String> test = ObjectArrayList.of(String.class);
|
||||
Assert.assertTrue(test.isCastable());
|
||||
}
|
||||
|
||||
public <T> void testCastable(IObjectArray<T> castable, boolean result)
|
||||
{
|
||||
Assert.assertTrue(castable.isCastable() == result);
|
||||
|
||||
@@ -15,5 +15,6 @@ public enum CollectionTest
|
||||
TO_ARRAY,
|
||||
CLEAR,
|
||||
WRAPPER,
|
||||
TO_STRING;
|
||||
TO_STRING,
|
||||
COPY;
|
||||
}
|
||||
|
||||
@@ -11,5 +11,6 @@ public enum MapTests
|
||||
MERGE,
|
||||
GET,
|
||||
ITERATORS,
|
||||
REMOVE;
|
||||
REMOVE,
|
||||
COPY;
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ public enum PriorityQueueTest
|
||||
PEEK,
|
||||
REMOVE,
|
||||
TO_ARRAY,
|
||||
COPY;
|
||||
}
|
||||
Reference in New Issue
Block a user