From 4db9c69a5408a3e861fcefe6426a9cb2e82af990 Mon Sep 17 00:00:00 2001 From: Speiger Date: Thu, 14 May 2026 02:54:57 +0200 Subject: [PATCH] Source Sync --- .../templates/lists/ArrayList.template | 43 ++++++++++++++ .../templates/lists/CopyOnWriteList.template | 41 ++++++++++++++ .../templates/lists/ImmutableList.template | 54 ++++++++++++++++-- .../templates/lists/LinkedList.template | 42 ++++++++++++++ .../LinkedOpenCustomHashMap.template | 44 +++++++-------- .../maps/impl/hash/LinkedOpenHashMap.template | 44 +++++++-------- .../templates/queues/ArrayFIFOQueue.template | 49 ++++++++++++++++ .../queues/ArrayPriorityQueue.template | 48 ++++++++++++++++ .../queues/HeapPriorityQueue.template | 49 ++++++++++++++++ .../templates/sets/AVLTreeSet.template | 42 ++++++++++++++ .../templates/sets/ArraySet.template | 56 ++++++++++++++++++- .../sets/LinkedOpenCustomHashSet.template | 42 ++++++++++++++ .../templates/sets/LinkedOpenHashSet.template | 42 ++++++++++++++ .../templates/sets/OpenCustomHashSet.template | 42 ++++++++++++++ .../templates/sets/OpenHashSet.template | 42 ++++++++++++++ .../templates/sets/RBTreeSet.template | 42 ++++++++++++++ .../templates/utils/AsyncBuilder.template | 25 +++++---- .../templates/utils/Collections.template | 5 +- .../maps/OrderedMapTestSuiteBuilder.template | 2 +- .../tests/maps/OrderedMapPutTester.template | 16 ++---- .../lists/CopyOnWriteBooleanArrayList.java | 1 - .../queues/BooleanArrayPriorityQueue.java | 1 - .../booleans/utils/BooleanAsyncBuilder.java | 21 +++---- .../booleans/utils/BooleanCollections.java | 5 +- .../bytes/lists/CopyOnWriteByteArrayList.java | 1 - .../bytes/lists/ImmutableByteList.java | 7 ++- .../Byte2BooleanLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Byte2ByteLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Byte2CharLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Byte2DoubleLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Byte2FloatLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Byte2IntLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Byte2LongLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Byte2ObjectLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Byte2ShortLinkedOpenCustomHashMap.java | 44 +++++++-------- .../hash/Byte2BooleanLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Byte2ByteLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Byte2CharLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Byte2DoubleLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Byte2FloatLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Byte2IntLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Byte2LongLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Byte2ObjectLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Byte2ShortLinkedOpenHashMap.java | 44 +++++++-------- .../bytes/queues/ByteArrayPriorityQueue.java | 1 - .../collections/bytes/sets/ByteArraySet.java | 14 ++++- .../bytes/utils/ByteAsyncBuilder.java | 21 +++---- .../bytes/utils/ByteCollections.java | 5 +- .../chars/lists/CopyOnWriteCharArrayList.java | 1 - .../chars/lists/ImmutableCharList.java | 7 ++- .../Char2BooleanLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Char2ByteLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Char2CharLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Char2DoubleLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Char2FloatLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Char2IntLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Char2LongLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Char2ObjectLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Char2ShortLinkedOpenCustomHashMap.java | 44 +++++++-------- .../hash/Char2BooleanLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Char2ByteLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Char2CharLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Char2DoubleLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Char2FloatLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Char2IntLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Char2LongLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Char2ObjectLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Char2ShortLinkedOpenHashMap.java | 44 +++++++-------- .../chars/queues/CharArrayPriorityQueue.java | 1 - .../collections/chars/sets/CharArraySet.java | 14 ++++- .../chars/utils/CharAsyncBuilder.java | 21 +++---- .../chars/utils/CharCollections.java | 5 +- .../lists/CopyOnWriteDoubleArrayList.java | 9 +++ .../doubles/lists/DoubleArrayList.java | 11 ++++ .../doubles/lists/DoubleLinkedList.java | 10 ++++ .../doubles/lists/ImmutableDoubleList.java | 16 +++++- ...Double2BooleanLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Double2ByteLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Double2CharLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Double2DoubleLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Double2FloatLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Double2IntLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Double2LongLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Double2ObjectLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Double2ShortLinkedOpenCustomHashMap.java | 44 +++++++-------- .../hash/Double2BooleanLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Double2ByteLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Double2CharLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Double2DoubleLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Double2FloatLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Double2IntLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Double2LongLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Double2ObjectLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Double2ShortLinkedOpenHashMap.java | 44 +++++++-------- .../doubles/queues/DoubleArrayFIFOQueue.java | 15 +++++ .../queues/DoubleArrayPriorityQueue.java | 14 +++++ .../queues/DoubleHeapPriorityQueue.java | 15 +++++ .../doubles/sets/DoubleAVLTreeSet.java | 10 ++++ .../doubles/sets/DoubleArraySet.java | 24 +++++++- .../sets/DoubleLinkedOpenCustomHashSet.java | 10 ++++ .../doubles/sets/DoubleLinkedOpenHashSet.java | 10 ++++ .../doubles/sets/DoubleOpenCustomHashSet.java | 10 ++++ .../doubles/sets/DoubleOpenHashSet.java | 10 ++++ .../doubles/sets/DoubleRBTreeSet.java | 10 ++++ .../doubles/utils/DoubleAsyncBuilder.java | 21 +++---- .../doubles/utils/DoubleCollections.java | 5 +- .../lists/CopyOnWriteFloatArrayList.java | 1 - .../floats/lists/ImmutableFloatList.java | 7 ++- .../Float2BooleanLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Float2ByteLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Float2CharLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Float2DoubleLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Float2FloatLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Float2IntLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Float2LongLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Float2ObjectLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Float2ShortLinkedOpenCustomHashMap.java | 44 +++++++-------- .../hash/Float2BooleanLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Float2ByteLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Float2CharLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Float2DoubleLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Float2FloatLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Float2IntLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Float2LongLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Float2ObjectLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Float2ShortLinkedOpenHashMap.java | 44 +++++++-------- .../queues/FloatArrayPriorityQueue.java | 1 - .../floats/sets/FloatArraySet.java | 14 ++++- .../floats/utils/FloatAsyncBuilder.java | 21 +++---- .../floats/utils/FloatCollections.java | 5 +- .../ints/lists/CopyOnWriteIntArrayList.java | 9 +++ .../ints/lists/ImmutableIntList.java | 16 +++++- .../collections/ints/lists/IntArrayList.java | 11 ++++ .../collections/ints/lists/IntLinkedList.java | 10 ++++ .../Int2BooleanLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Int2ByteLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Int2CharLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Int2DoubleLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Int2FloatLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Int2IntLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Int2LongLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Int2ObjectLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Int2ShortLinkedOpenCustomHashMap.java | 44 +++++++-------- .../hash/Int2BooleanLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Int2ByteLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Int2CharLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Int2DoubleLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Int2FloatLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Int2IntLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Int2LongLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Int2ObjectLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Int2ShortLinkedOpenHashMap.java | 44 +++++++-------- .../ints/queues/IntArrayFIFOQueue.java | 15 +++++ .../ints/queues/IntArrayPriorityQueue.java | 14 +++++ .../ints/queues/IntHeapPriorityQueue.java | 15 +++++ .../collections/ints/sets/IntAVLTreeSet.java | 10 ++++ .../collections/ints/sets/IntArraySet.java | 24 +++++++- .../ints/sets/IntLinkedOpenCustomHashSet.java | 10 ++++ .../ints/sets/IntLinkedOpenHashSet.java | 10 ++++ .../ints/sets/IntOpenCustomHashSet.java | 10 ++++ .../collections/ints/sets/IntOpenHashSet.java | 10 ++++ .../collections/ints/sets/IntRBTreeSet.java | 10 ++++ .../ints/utils/IntAsyncBuilder.java | 21 +++---- .../ints/utils/IntCollections.java | 5 +- .../longs/lists/CopyOnWriteLongArrayList.java | 9 +++ .../longs/lists/ImmutableLongList.java | 16 +++++- .../longs/lists/LongArrayList.java | 11 ++++ .../longs/lists/LongLinkedList.java | 10 ++++ .../Long2BooleanLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Long2ByteLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Long2CharLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Long2DoubleLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Long2FloatLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Long2IntLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Long2LongLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Long2ObjectLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Long2ShortLinkedOpenCustomHashMap.java | 44 +++++++-------- .../hash/Long2BooleanLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Long2ByteLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Long2CharLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Long2DoubleLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Long2FloatLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Long2IntLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Long2LongLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Long2ObjectLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Long2ShortLinkedOpenHashMap.java | 44 +++++++-------- .../longs/queues/LongArrayFIFOQueue.java | 15 +++++ .../longs/queues/LongArrayPriorityQueue.java | 14 +++++ .../longs/queues/LongHeapPriorityQueue.java | 15 +++++ .../longs/sets/LongAVLTreeSet.java | 10 ++++ .../collections/longs/sets/LongArraySet.java | 24 +++++++- .../sets/LongLinkedOpenCustomHashSet.java | 10 ++++ .../longs/sets/LongLinkedOpenHashSet.java | 10 ++++ .../longs/sets/LongOpenCustomHashSet.java | 10 ++++ .../longs/sets/LongOpenHashSet.java | 10 ++++ .../collections/longs/sets/LongRBTreeSet.java | 10 ++++ .../longs/utils/LongAsyncBuilder.java | 21 +++---- .../longs/utils/LongCollections.java | 5 +- .../lists/CopyOnWriteObjectArrayList.java | 24 ++++++++ .../objects/lists/ImmutableObjectList.java | 27 +++++++++ .../objects/lists/ObjectArrayList.java | 26 +++++++++ .../objects/lists/ObjectLinkedList.java | 25 +++++++++ ...Object2BooleanLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Object2ByteLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Object2CharLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Object2DoubleLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Object2FloatLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Object2IntLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Object2LongLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Object2ObjectLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Object2ShortLinkedOpenCustomHashMap.java | 44 +++++++-------- .../hash/Object2BooleanLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Object2ByteLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Object2CharLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Object2DoubleLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Object2FloatLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Object2IntLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Object2LongLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Object2ObjectLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Object2ShortLinkedOpenHashMap.java | 44 +++++++-------- .../objects/queues/ObjectArrayFIFOQueue.java | 26 +++++++++ .../queues/ObjectArrayPriorityQueue.java | 25 +++++++++ .../queues/ObjectHeapPriorityQueue.java | 26 +++++++++ .../objects/sets/ObjectAVLTreeSet.java | 25 +++++++++ .../objects/sets/ObjectArraySet.java | 39 ++++++++++++- .../sets/ObjectLinkedOpenCustomHashSet.java | 25 +++++++++ .../objects/sets/ObjectLinkedOpenHashSet.java | 25 +++++++++ .../objects/sets/ObjectOpenCustomHashSet.java | 25 +++++++++ .../objects/sets/ObjectOpenHashSet.java | 25 +++++++++ .../objects/sets/ObjectRBTreeSet.java | 25 +++++++++ .../objects/utils/ObjectAsyncBuilder.java | 21 +++---- .../objects/utils/ObjectCollections.java | 5 +- .../lists/CopyOnWriteShortArrayList.java | 1 - .../shorts/lists/ImmutableShortList.java | 7 ++- .../Short2BooleanLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Short2ByteLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Short2CharLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Short2DoubleLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Short2FloatLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Short2IntLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Short2LongLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Short2ObjectLinkedOpenCustomHashMap.java | 44 +++++++-------- .../Short2ShortLinkedOpenCustomHashMap.java | 44 +++++++-------- .../hash/Short2BooleanLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Short2ByteLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Short2CharLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Short2DoubleLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Short2FloatLinkedOpenHashMap.java | 44 +++++++-------- .../impl/hash/Short2IntLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Short2LongLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Short2ObjectLinkedOpenHashMap.java | 44 +++++++-------- .../hash/Short2ShortLinkedOpenHashMap.java | 44 +++++++-------- .../queues/ShortArrayPriorityQueue.java | 1 - .../shorts/sets/ShortArraySet.java | 14 ++++- .../shorts/utils/ShortAsyncBuilder.java | 21 +++---- .../shorts/utils/ShortCollections.java | 5 +- 256 files changed, 4950 insertions(+), 3374 deletions(-) diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template b/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template index bf88d2f..e87e743 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template @@ -9,6 +9,13 @@ import java.util.Iterator; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif +#endif + #endif #if TYPE_OBJECT #if IARRAY_FEATURE || TYPE_OBJECT @@ -225,6 +232,42 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE return list; } +#endif +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a ArrayList + * @Type(T) + * @return a collector + */ + public static Collector, ObjectArrayList> toList() { + return Collector.of(ObjectArrayList::new, ObjectArrayList::add, ObjectArrayList::merge); + } + + /** + * Collects a Stream to a ArrayList + * @Type(T) + * @return a list with the contents of the Stream + */ + public static ARRAY_LIST KEY_GENERIC_TYPE toList(Stream stream) { + return stream.collect(ObjectArrayList::new, ObjectArrayList::add, ObjectArrayList::merge); + } + + private ObjectArrayList merge(ObjectArrayList a) { + addAll(a); + return this; + } + +#else + /** + * Collects a Stream to a ArrayList + * @return a list with the contents of the Stream + */ + public static ARRAY_LIST toList(JAVA_STREAM stream) { + return stream.collect(ARRAY_LIST::new, ARRAY_LIST::add, ARRAY_LIST::addAll); + } + +#endif #endif /** * Appends the specified element to the end of this list. diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/CopyOnWriteList.template b/src/builder/resources/speiger/assets/collections/templates/lists/CopyOnWriteList.template index 8d818ff..7017489 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/CopyOnWriteList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/CopyOnWriteList.template @@ -10,6 +10,12 @@ import java.util.NoSuchElementException; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif +#endif #endif import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; @@ -172,7 +178,42 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER } #endif +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a CopyOnWriteArrayList + * @Type(T) + * @return a collector + */ + public static Collector, CopyOnWriteObjectArrayList> toList() { + return Collector.of(CopyOnWriteObjectArrayList::new, CopyOnWriteObjectArrayList::add, CopyOnWriteObjectArrayList::merge); + } + /** + * Collects a Stream to a CopyOnWriteArrayList + * @Type(T) + * @return a list with the contents of the Stream + */ + public static CopyOnWriteObjectArrayList KEY_GENERIC_TYPE toList(Stream stream) { + return stream.collect(CopyOnWriteObjectArrayList::new, CopyOnWriteObjectArrayList::add, CopyOnWriteObjectArrayList::merge); + } + + private CopyOnWriteObjectArrayList merge(CopyOnWriteObjectArrayList a) { + addAll(a); + return this; + } + +#else + /** + * Collects a Stream to a CopyOnWriteArrayList + * @return a list with the contents of the Stream + */ + public static COPY_ON_WRITE_LIST toList(JAVA_STREAM stream) { + return stream.collect(COPY_ON_WRITE_LIST::new, COPY_ON_WRITE_LIST::add, COPY_ON_WRITE_LIST::addAll); + } + +#endif +#endif private void setArray(KEY_TYPE[] data) { this.data = data; } diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/ImmutableList.template b/src/builder/resources/speiger/assets/collections/templates/lists/ImmutableList.template index a75fcfe..d7a00b1 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/ImmutableList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/ImmutableList.template @@ -3,12 +3,25 @@ package speiger.src.collections.PACKAGE.lists; import java.util.Arrays; #if TYPE_OBJECT import java.util.Comparator; +#else if !TYPE_BOOLEAN +import java.util.stream.JAVA_STREAM; +import java.util.stream.StreamSupport; #endif import java.util.Collection; import java.util.NoSuchElementException; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if PRIMITIVES +import java.util.function.Supplier; +#else +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif + +import speiger.src.collections.PACKAGE.utils.COLLECTIONS; +#endif #endif #if TYPE_OBJECT import java.util.function.BiFunction; @@ -23,6 +36,7 @@ import java.util.function.PREDICATE; #if !JDK_FUNCTION import java.util.function.JAVA_PREDICATE; #endif + import java.util.function.JAVA_UNARY_OPERATOR; #endif @@ -42,10 +56,6 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.objects.utils.ObjectArrays; import speiger.src.collections.PACKAGE.utils.ITERATORS; -#if PRIMITIVES && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE -import java.util.stream.JAVA_STREAM; -import java.util.stream.StreamSupport; -#endif #if SPLIT_ITERATOR_FEATURE import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; @@ -126,6 +136,42 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T data = Arrays.copyOfRange(a, offset, offset+length); } +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a ImmutableList + * @Type(T) + * @return a collector + */ + public static Collector, ImmutableObjectList> toList() { + return Collector.of(COLLECTIONS::wrapper, COLLECTION::add, ImmutableObjectList::merge, E -> new IMMUTABLE_LIST<>(E.toArray((T[])new Object[E.size()]))); + } + + /** + * Collects a Stream to a ImmutableList + * @Type(T) + * @return a list with the contents of the Stream + */ + public static ImmutableObjectList KEY_GENERIC_TYPE toList(Stream stream) { + return stream.collect(toList()); + } + + private static COLLECTION merge(COLLECTION a, COLLECTION b) { + a.addAll(b); + return a; + } + +#else + /** + * Collects a Stream to a ImmutableList + * @return a list with the contents of the Stream + */ + public static IMMUTABLE_LIST toList(JAVA_STREAM stream) { + return new IMMUTABLE_LIST(stream.collect((Supplier)COLLECTIONS::wrapper, COLLECTION::add, COLLECTION::addAll).TO_ARRAY()); + } + +#endif +#endif @Override public boolean add(KEY_TYPE e) { throw new UnsupportedOperationException(); } @Override diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template b/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template index dc1134e..aa749f8 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template @@ -13,6 +13,12 @@ import java.util.Iterator; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif +#endif #endif import java.util.NoSuchElementException; #if SPLIT_ITERATOR_FEATURE @@ -160,6 +166,42 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE for(int i = offset,m=offset+length;i Collector, ObjectLinkedList> toList() { + return Collector.of(ObjectLinkedList::new, ObjectLinkedList::add, ObjectLinkedList::merge); + } + + /** + * Collects a Stream to a LinkedList + * @Type(T) + * @return a list with the contents of the Stream + */ + public static ObjectLinkedList KEY_GENERIC_TYPE toList(Stream stream) { + return stream.collect(ObjectLinkedList::new, ObjectLinkedList::add, ObjectLinkedList::merge); + } + + private ObjectLinkedList merge(ObjectLinkedList a) { + addAll(a); + return this; + } + +#else + /** + * Collects a Stream to a LinkedList + * @return a list with the contents of the Stream + */ + public static LINKED_LIST toList(JAVA_STREAM stream) { + return stream.collect(LINKED_LIST::new, LINKED_LIST::add, LINKED_LIST::addAll); + } + +#endif +#endif @Override public boolean add(KEY_TYPE e) { add(size(), e); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template index 54fdcca..987ccf3 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template @@ -238,13 +238,13 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M if(containsNull) { VALUE_TYPE lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -252,7 +252,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M if(strategy.equals(keys[pos], key)) { VALUE_TYPE lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -260,7 +260,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -272,13 +272,13 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M if(containsNull) { VALUE_TYPE lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -286,7 +286,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M if(strategy.equals(keys[pos], key)) { VALUE_TYPE lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -294,7 +294,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -307,7 +307,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -318,7 +318,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -331,7 +331,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -342,7 +342,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -353,7 +353,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M if(isEmpty() || strategy.equals(FIRST_ENTRY_KEY(), key)) return false; if(strategy.equals(key, EMPTY_KEY_VALUE)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -361,7 +361,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -375,7 +375,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M if(isEmpty() || strategy.equals(LAST_ENTRY_KEY(), key)) return false; if(strategy.equals(key, EMPTY_KEY_VALUE)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -383,7 +383,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -396,7 +396,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -404,7 +404,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -580,8 +580,8 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -598,8 +598,8 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template index 8cec210..bf0681d 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template @@ -215,13 +215,13 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G if(containsNull) { VALUE_TYPE lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask; @@ -229,7 +229,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G if(KEY_EQUALS(keys[pos], key)) { VALUE_TYPE lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -237,7 +237,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -249,13 +249,13 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G if(containsNull) { VALUE_TYPE lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask; @@ -263,7 +263,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G if(KEY_EQUALS(keys[pos], key)) { VALUE_TYPE lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -271,7 +271,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -284,7 +284,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); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask; @@ -295,7 +295,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -308,7 +308,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); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask; @@ -319,7 +319,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -330,7 +330,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G if(isEmpty() || KEY_EQUALS(FIRST_ENTRY_KEY(), key)) return false; if(KEY_EQUALS_NULL(key)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -338,7 +338,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask; while(KEY_EQUALS_NOT_NULL(keys[pos])) { if(KEY_EQUALS(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -352,7 +352,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G if(isEmpty() || KEY_EQUALS(LAST_ENTRY_KEY(), key)) return false; if(KEY_EQUALS_NULL(key)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -360,7 +360,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask; while(KEY_EQUALS_NOT_NULL(keys[pos])) { if(KEY_EQUALS(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -373,7 +373,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -381,7 +381,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -584,8 +584,8 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -602,8 +602,8 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template index b60eed8..970a3cf 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template @@ -9,6 +9,14 @@ import java.util.function.BiFunction; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if !TYPE_OBJECT +import java.util.stream.JAVA_STREAM; +#else +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif +#endif #endif import java.util.NoSuchElementException; #if JDK_FUNCTION @@ -105,6 +113,47 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K this(MIN_CAPACITY); } +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a ArrayFIFOQueue + * @Type(T) + * @return a collector + */ + public static Collector, ARRAY_FIFO_QUEUE> toQueue() { + return Collector.of(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge); + } + + /** + * Collects a Stream to a ArrayFIFOQueue + * @Type(T) + * @return a queue with the contents of the Stream + */ + public static ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE toQueue(Stream stream) { + return stream.collect(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge); + } + + private ARRAY_FIFO_QUEUE merge(ARRAY_FIFO_QUEUE a) { + enqueueAll(a.toArray((T[])new Object[a.size()])); + return this; + } + +#else + /** + * Collects a Stream to a ArrayFIFOQueue + * @return a queue with the contents of the Stream + */ + public static ARRAY_FIFO_QUEUE toQueue(JAVA_STREAM stream) { + return stream.collect(ARRAY_FIFO_QUEUE::new, ARRAY_FIFO_QUEUE::enqueue, ARRAY_FIFO_QUEUE::merge); + } + + private ARRAY_FIFO_QUEUE merge(ARRAY_FIFO_QUEUE a) { + enqueueAll(a.TO_ARRAY()); + return this; + } + +#endif +#endif @Override public ITERATOR KEY_GENERIC_TYPE iterator() { return new Iter(); diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template index 620398b..860024b 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template @@ -10,6 +10,14 @@ import java.util.function.BiFunction; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if !TYPE_OBJECT +import java.util.stream.JAVA_STREAM; +#else +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif +#endif #endif #if JDK_FUNCTION import java.util.function.PREDICATE; @@ -196,7 +204,47 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE queue.size = size; return queue; } +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a ArrayPriorityQueue + * @Type(T) + * @return a collector + */ + public static Collector, ARRAY_PRIORITY_QUEUE> toQueue() { + return Collector.of(ARRAY_PRIORITY_QUEUE::new, ARRAY_PRIORITY_QUEUE::enqueue, ARRAY_PRIORITY_QUEUE::merge); + } + /** + * Collects a Stream to a ArrayPriorityQueue + * @Type(T) + * @return a queue with the contents of the Stream + */ + public static ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE toQueue(Stream stream) { + return stream.collect(ARRAY_PRIORITY_QUEUE::new, ARRAY_PRIORITY_QUEUE::enqueue, ARRAY_PRIORITY_QUEUE::merge); + } + + private ARRAY_PRIORITY_QUEUE merge(ARRAY_PRIORITY_QUEUE a) { + enqueueAll(a.toArray((T[])new Object[a.size()])); + return this; + } + +#else + /** + * Collects a Stream to a ArrayPriorityQueue + * @return a queue with the contents of the Stream + */ + public static ARRAY_PRIORITY_QUEUE toQueue(JAVA_STREAM stream) { + return stream.collect(ARRAY_PRIORITY_QUEUE::new, ARRAY_PRIORITY_QUEUE::enqueue, ARRAY_PRIORITY_QUEUE::merge); + } + + private ARRAY_PRIORITY_QUEUE merge(ARRAY_PRIORITY_QUEUE a) { + enqueueAll(a.TO_ARRAY()); + return this; + } + +#endif +#endif @Override public void enqueue(KEY_TYPE e) { if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (long)(array.length >> 1), (long)SanityChecks.MAX_ARRAY_SIZE), size+1)); diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template index 0dcb8f5..69423c1 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template @@ -10,6 +10,14 @@ import java.util.function.BiFunction; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if !TYPE_OBJECT +import java.util.stream.JAVA_STREAM; +#else +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif +#endif #endif #if JDK_FUNCTION import java.util.function.PREDICATE; @@ -199,6 +207,47 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU return queue; } +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a ArrayFIFOQueue + * @Type(T) + * @return a collector + */ + public static Collector, HEAP_PRIORITY_QUEUE> toQueue() { + return Collector.of(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge); + } + + /** + * Collects a Stream to a ArrayFIFOQueue + * @Type(T) + * @return a queue with the contents of the Stream + */ + public static HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE toQueue(Stream stream) { + return stream.collect(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge); + } + + private HEAP_PRIORITY_QUEUE merge(HEAP_PRIORITY_QUEUE a) { + enqueueAll(a.toArray((T[])new Object[a.size()])); + return this; + } + +#else + /** + * Collects a Stream to a ArrayFIFOQueue + * @return a queue with the contents of the Stream + */ + public static HEAP_PRIORITY_QUEUE toQueue(JAVA_STREAM stream) { + return stream.collect(HEAP_PRIORITY_QUEUE::new, HEAP_PRIORITY_QUEUE::enqueue, HEAP_PRIORITY_QUEUE::merge); + } + + private HEAP_PRIORITY_QUEUE merge(HEAP_PRIORITY_QUEUE a) { + enqueueAll(a.TO_ARRAY()); + return this; + } + +#endif +#endif @Override public int size() { return size; diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template index b83198f..1fbefd8 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template @@ -12,6 +12,12 @@ import java.util.NoSuchElementException; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if !TYPE_OBJECT +import java.util.stream.JAVA_STREAM; +#else +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif #endif #if JDK_FUNCTION import java.util.function.PREDICATE; @@ -214,6 +220,42 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE while(iterator.hasNext()) add(iterator.NEXT()); } +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a AVLTreeSet + * @Type(T) + * @return a collector + */ + public static Collector, AVL_TREE_SET> toSet() { + return Collector.of(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::merge); + } + + /** + * Collects a Stream to a AVLTreeSet + * @Type(T) + * @return a set with the contents of the Stream + */ + public static AVL_TREE_SET KEY_GENERIC_TYPE toSet(Stream stream) { + return stream.collect(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::merge); + } + + private AVL_TREE_SET merge(AVL_TREE_SET a) { + addAll(a); + return this; + } + +#else + /** + * Collects a Stream to a AVLTreeSet + * @return a set with the contents of the Stream + */ + public static AVL_TREE_SET toSet(JAVA_STREAM stream) { + return stream.collect(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::addAll); + } + +#endif +#endif #if !TYPE_OBJECT @Override public void setDefaultMaxValue(KEY_TYPE value) { defaultMaxNotFound = value; } diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template b/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template index 74558f6..9aacaca 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template @@ -10,6 +10,12 @@ import java.util.NoSuchElementException; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if !TYPE_OBJECT +import java.util.stream.JAVA_STREAM; +#else +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif #endif import java.util.Set; #if JDK_FUNCTION @@ -74,7 +80,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im * @param array the array that should be used for set. */ public ARRAY_SET(KEY_TYPE[] array) { - this(array, array.length); + this(array, 0, array.length); } /** @@ -88,6 +94,18 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im addAll(array, length); } + /** + * Constructur using initial Array + * @param array the array that should be used for set. + * @param offset the starting offset of where the array should be copied from + * @param length the amount of elements present within the array + * @throws NegativeArraySizeException if the length is negative + */ + public ARRAY_SET(KEY_TYPE[] array, int offset, int length) { + this(length); + addAll(array, offset, length); + } + /** * A Helper constructor that allows to create a Set with exactly the same values as the provided collection. * @param c the elements that should be added to the set. @@ -131,6 +149,42 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im for(ITERATOR KEY_GENERIC_TYPE iter = s.iterator();iter.hasNext();data[size++] = iter.NEXT()); } +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a ArraySet + * @Type(T) + * @return a collector + */ + public static Collector, ARRAY_SET> toList() { + return Collector.of(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::merge); + } + + /** + * Collects a Stream to a ArraySet + * @Type(T) + * @return a set with the contents of the Stream + */ + public static ARRAY_SET KEY_GENERIC_TYPE toList(Stream stream) { + return stream.collect(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::merge); + } + + private ARRAY_SET merge(ARRAY_SET a) { + addAll(a); + return this; + } + +#else + /** + * Collects a Stream to a ArraySet + * @return a set with the contents of the Stream + */ + public static ARRAY_SET toList(JAVA_STREAM stream) { + return stream.collect(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::addAll); + } + +#endif +#endif @Override public boolean add(KEY_TYPE o) { int index = findIndex(o); diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template index de92850..4f1bbc0 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template @@ -11,6 +11,12 @@ import java.util.Iterator; import java.util.NoSuchElementException; #if JDK_TYPE import java.util.OPTIONAL; +#if !TYPE_OBJECT +import java.util.stream.JAVA_STREAM; +#else +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif #endif #if JDK_FUNCTION import java.util.function.PREDICATE; @@ -240,6 +246,42 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY while(iterator.hasNext()) add(iterator.NEXT()); } +#endif +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a LinkedCustomHashSet + * @Type(T) + * @return a collector + */ + public static Collector, LINKED_CUSTOM_HASH_SET> toLinkedSet(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { + return Collector.of(() -> new LINKED_CUSTOM_HASH_SET<>(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::merge); + } + + /** + * Collects a Stream to a LinkedCustomHashSet + * @Type(T) + * @return a set with the contents of the Stream + */ + public static LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE toLinkedSet(Stream stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { + return stream.collect(() -> new LINKED_CUSTOM_HASH_SET<>(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::merge); + } + + private LINKED_CUSTOM_HASH_SET merge(LINKED_CUSTOM_HASH_SET a) { + addAll(a); + return this; + } + +#else + /** + * Collects a Stream to a LinkedCustomHashSet + * @return a set with the contents of the Stream + */ + public static LINKED_CUSTOM_HASH_SET toList(JAVA_STREAM stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { + return stream.collect(() -> new LINKED_CUSTOM_HASH_SET(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::addAll); + } + +#endif #endif @Override public void addFirst(KEY_TYPE o) { diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template index 81f4244..c63bec4 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template @@ -7,6 +7,12 @@ import java.util.NoSuchElementException; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if !TYPE_OBJECT +import java.util.stream.JAVA_STREAM; +#else +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif #endif #if TYPE_OBJECT import java.util.function.Consumer; @@ -211,6 +217,42 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE while(iterator.hasNext()) add(iterator.NEXT()); } +#endif +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a LinkedHashSet + * @Type(T) + * @return a collector + */ + public static Collector, LINKED_HASH_SET> toLinkedSet() { + return Collector.of(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::merge); + } + + /** + * Collects a Stream to a LinkedHashSet + * @Type(T) + * @return a set with the contents of the Stream + */ + public static LINKED_HASH_SET KEY_GENERIC_TYPE toLinkedSet(Stream stream) { + return stream.collect(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::merge); + } + + private LINKED_HASH_SET merge(LINKED_HASH_SET a) { + addAll(a); + return this; + } + +#else + /** + * Collects a Stream to a LinkedHashSet + * @return a set with the contents of the Stream + */ + public static LINKED_HASH_SET toLinkedSet(JAVA_STREAM stream) { + return stream.collect(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::addAll); + } + +#endif #endif @Override public void addFirst(KEY_TYPE o) { diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template index b9339f3..95c7656 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template @@ -8,6 +8,12 @@ import java.util.NoSuchElementException; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if !TYPE_OBJECT +import java.util.stream.JAVA_STREAM; +#else +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif #endif #if TYPE_OBJECT import java.util.function.Consumer; @@ -257,6 +263,42 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T while(iterator.hasNext()) add(iterator.NEXT()); } +#endif +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a CustomHashSet + * @Type(T) + * @return a collector + */ + public static Collector, CUSTOM_HASH_SET> toSet(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { + return Collector.of(() -> new CUSTOM_HASH_SET<>(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::merge); + } + + /** + * Collects a Stream to a CustomHashSet + * @Type(T) + * @return a set with the contents of the Stream + */ + public static CUSTOM_HASH_SET KEY_GENERIC_TYPE toSet(Stream stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { + return stream.collect(() -> new CUSTOM_HASH_SET<>(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::merge); + } + + private CUSTOM_HASH_SET merge(CUSTOM_HASH_SET a) { + addAll(a); + return this; + } + +#else + /** + * Collects a Stream to a CustomHashSet + * @return a set with the contents of the Stream + */ + public static CUSTOM_HASH_SET toSet(JAVA_STREAM stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { + return stream.collect(() -> new CUSTOM_HASH_SET(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::addAll); + } + +#endif #endif /** * Helper getter function to get the current strategy diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template index 0756904..e83b1cc 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template @@ -8,6 +8,12 @@ import java.util.NoSuchElementException; import java.util.Objects; #if JDK_TYPE import java.util.OPTIONAL; +#if !TYPE_OBJECT +import java.util.stream.JAVA_STREAM; +#else +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif #endif #if TYPE_OBJECT import java.util.function.Consumer; @@ -224,6 +230,42 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp while(iterator.hasNext()) add(iterator.NEXT()); } +#endif +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a HashSet + * @Type(T) + * @return a collector + */ + public static Collector, HASH_SET> toSet() { + return Collector.of(HASH_SET::new, HASH_SET::add, HASH_SET::merge); + } + + /** + * Collects a Stream to a HashSet + * @Type(T) + * @return a set with the contents of the Stream + */ + public static HASH_SET KEY_GENERIC_TYPE toSet(Stream stream) { + return stream.collect(HASH_SET::new, HASH_SET::add, HASH_SET::merge); + } + + private HASH_SET merge(HASH_SET a) { + addAll(a); + return this; + } + +#else + /** + * Collects a Stream to a HashSet + * @return a set with the contents of the Stream + */ + public static HASH_SET toSet(JAVA_STREAM stream) { + return stream.collect(HASH_SET::new, HASH_SET::add, HASH_SET::addAll); + } + +#endif #endif @Override public boolean add(KEY_TYPE o) { diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template index 27b2008..e5651da 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template @@ -4,6 +4,12 @@ import java.util.Collection; import java.util.Collections; #if JDK_TYPE import java.util.OPTIONAL; +#if !TYPE_OBJECT +import java.util.stream.JAVA_STREAM; +#else +import java.util.stream.Stream; +import java.util.stream.Collector; +#endif #endif #if TYPE_OBJECT import java.util.Comparator; @@ -214,6 +220,42 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE while(iterator.hasNext()) add(iterator.NEXT()); } +#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE +#if TYPE_OBJECT + /** + * Creates a Collector for a RBTreeSet + * @Type(T) + * @return a collector + */ + public static Collector, RB_TREE_SET> toSet() { + return Collector.of(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::merge); + } + + /** + * Collects a Stream to a RBTreeSet + * @Type(T) + * @return a set with the contents of the Stream + */ + public static RB_TREE_SET KEY_GENERIC_TYPE toSet(Stream stream) { + return stream.collect(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::merge); + } + + private RB_TREE_SET merge(RB_TREE_SET a) { + addAll(a); + return this; + } + +#else + /** + * Collects a Stream to a RBTreeSet + * @return a set with the contents of the Stream + */ + public static RB_TREE_SET toSet(JAVA_STREAM stream) { + return stream.collect(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::addAll); + } + +#endif +#endif #if !TYPE_OBJECT @Override public void setDefaultMaxValue(KEY_TYPE value) { defaultMaxNotFound = value; } diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/AsyncBuilder.template b/src/builder/resources/speiger/assets/collections/templates/utils/AsyncBuilder.template index d6ab499..de2aa62 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/AsyncBuilder.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/AsyncBuilder.template @@ -7,6 +7,11 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.LockSupport; import java.util.function.Consumer; +#if JDK_TYPE +import java.util.OPTIONAL; +#else +import speiger.src.collections.PACKAGE.functions.OPTIONAL; +#endif #if !TYPE_OBJECT import speiger.src.collections.PACKAGE.functions.CONSUMER; @@ -299,9 +304,8 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE * @param operator that reduces the elements. * @return self with the reduce action applied */ - public ASYNC_BUILDER KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { - task = new SimpleReduceTaskBRACES(iterable.iterator(), operator); - return this; + public ObjectAsyncBuilder reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { + return new ObjectAsyncBuilder<>(new SimpleReduceTaskBRACES(iterable.iterator(), operator)); } #if TYPE_OBJECT @@ -435,9 +439,8 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE * @param filter that decides the desired elements * @return self with the findFirst function applied */ - public ASYNC_BUILDER KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { - task = new FindFirstTaskBRACES(iterable.iterator(), filter); - return this; + public ObjectAsyncBuilder findFirst(PREDICATE KEY_GENERIC_TYPE filter) { + return new ObjectAsyncBuilder<>(new FindFirstTaskBRACES(iterable.iterator(), filter)); } #if INT_ASYNC_MODULE @@ -590,7 +593,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE } #endif - private static class SimpleReduceTask KEY_GENERIC_TYPE extends BASE_TASK KEY_GENERIC_TYPE + private static class SimpleReduceTask KEY_GENERIC_TYPE extends BaseObjectTask { ITERATOR KEY_GENERIC_TYPE iter; UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator; @@ -600,6 +603,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE public SimpleReduceTask(ITERATOR KEY_GENERIC_TYPE iter, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { this.iter = iter; this.operator = operator; + this.setResult(OPTIONAL.empty()); } @Override @@ -614,7 +618,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE } } if(!iter.hasNext()) { - setResult(value); + setResult(OPTIONAL.GET_OPTIONAL(value)); return true; } return false; @@ -689,7 +693,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE } #endif - private static class FindFirstTask KEY_GENERIC_TYPE extends BASE_TASK KEY_GENERIC_TYPE + private static class FindFirstTask KEY_GENERIC_TYPE extends BaseObjectTask { ITERATOR KEY_GENERIC_TYPE iter; PREDICATE KEY_GENERIC_TYPE filter; @@ -697,6 +701,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE public FindFirstTask(ITERATOR KEY_GENERIC_TYPE iter, PREDICATE KEY_GENERIC_TYPE filter) { this.iter = iter; this.filter = filter; + this.setResult(OPTIONAL.empty()); } @Override @@ -704,7 +709,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE while(shouldRun() && iter.hasNext()) { KEY_TYPE entry = iter.NEXT(); if(filter.test(iter.NEXT())) { - setResult(entry); + setResult(OPTIONAL.GET_OPTIONAL(entry)); return true; } } diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template b/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template index b57980a..0c114b7 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template @@ -147,7 +147,10 @@ public class COLLECTIONS return new SingletonCollectionBRACES(element); } - protected static GENERIC_KEY_BRACES CollectionWrapper KEY_GENERIC_TYPE wrapper() { + /** + * Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed. + */ + public static GENERIC_KEY_BRACES CollectionWrapper KEY_GENERIC_TYPE wrapper() { return new CollectionWrapperBRACES(); } diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/maps/OrderedMapTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/maps/OrderedMapTestSuiteBuilder.template index 03cc30b..c63401e 100644 --- a/src/builder/resources/speiger/assets/testers/templates/builder/maps/OrderedMapTestSuiteBuilder.template +++ b/src/builder/resources/speiger/assets/testers/templates/builder/maps/OrderedMapTestSuiteBuilder.template @@ -79,7 +79,7 @@ public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BU features.addAll(parentBuilder.getFeatures()); features.remove(SpecialFeature.COPYING); features.remove(SpecialFeature.CHILDREN_COPY); - return ORDERED_MAP_TEST_BUILDER.using(new DERIVED_MAP_GENERATORS.ReverseTestOrderedMapGenerator(delegate)) + return ORDERED_MAP_TEST_BUILDER.using(new DERIVED_MAP_GENERATORS.ReverseTestOrderedMapGeneratorKV_BRACES(delegate)) .named(parentBuilder.getName() + " reversed").withFeatures(features) .suppressing(parentBuilder.getSuppressedTests()).createTestSuite(); } diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapPutTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapPutTester.template index 4aa0596..f78a68b 100644 --- a/src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapPutTester.template +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapPutTester.template @@ -23,7 +23,6 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester KEY_VALUE_GENERIC_ private ObjectList values; private KEY_TYPE a; private VALUE_TYPE aValue; - private VALUE_TYPE cValue; @Override public void setUp() throws Exception { @@ -33,9 +32,6 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester KEY_VALUE_GENERIC_ if (values.size() >= 1) { a = values.get(0).ENTRY_KEY(); aValue = values.get(0).ENTRY_VALUE(); - if (values.size() >= 3) { - cValue = values.get(2).ENTRY_VALUE(); - } } } @@ -44,10 +40,10 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester KEY_VALUE_GENERIC_ @CollectionSize.Require(absent = ZERO) #endignore public void testPutFirst() { - assertEquals(aValue, orderedMap.putFirst(a, cValue)); - assertNotEquals(cValue, orderedMap.FIRST_ENTRY_VALUE()); + assertEquals(aValue, orderedMap.putFirst(a, v3())); + assertNotEquals(v3(), orderedMap.FIRST_ENTRY_VALUE()); assertEquals(orderedMap.getDefaultReturnValue(), orderedMap.putFirst(k4(), v4())); - assertNotEquals(v4(), orderedMap.FIRST_ENTRY_VALUE()); + assertEquals(v4(), orderedMap.FIRST_ENTRY_VALUE()); assertEquals(e4(), orderedMap.firstEntry()); } @@ -57,10 +53,10 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester KEY_VALUE_GENERIC_ @CollectionSize.Require(absent = ZERO) #endignore public void testPutLast() { - assertEquals(aValue, orderedMap.putLast(a, cValue)); - assertNotEquals(cValue, orderedMap.LAST_ENTRY_VALUE()); + assertEquals(aValue, orderedMap.putLast(a, v3())); + assertNotEquals(v3(), orderedMap.LAST_ENTRY_VALUE()); assertEquals(orderedMap.getDefaultReturnValue(), orderedMap.putLast(k4(), v4())); - assertNotEquals(v4(), orderedMap.LAST_ENTRY_VALUE()); + assertEquals(v4(), orderedMap.LAST_ENTRY_VALUE()); assertEquals(e4(), orderedMap.lastEntry()); } diff --git a/src/main/java/speiger/src/collections/booleans/lists/CopyOnWriteBooleanArrayList.java b/src/main/java/speiger/src/collections/booleans/lists/CopyOnWriteBooleanArrayList.java index ddb83f1..804272c 100644 --- a/src/main/java/speiger/src/collections/booleans/lists/CopyOnWriteBooleanArrayList.java +++ b/src/main/java/speiger/src/collections/booleans/lists/CopyOnWriteBooleanArrayList.java @@ -107,7 +107,6 @@ public class CopyOnWriteBooleanArrayList extends AbstractBooleanList implements System.arraycopy(a, offset, data, 0, length); } - private void setArray(boolean[] data) { this.data = data; } diff --git a/src/main/java/speiger/src/collections/booleans/queues/BooleanArrayPriorityQueue.java b/src/main/java/speiger/src/collections/booleans/queues/BooleanArrayPriorityQueue.java index bd80eb8..7dc2147 100644 --- a/src/main/java/speiger/src/collections/booleans/queues/BooleanArrayPriorityQueue.java +++ b/src/main/java/speiger/src/collections/booleans/queues/BooleanArrayPriorityQueue.java @@ -174,7 +174,6 @@ public class BooleanArrayPriorityQueue extends AbstractBooleanPriorityQueue queue.size = size; return queue; } - @Override public void enqueue(boolean e) { if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (long)(array.length >> 1), (long)SanityChecks.MAX_ARRAY_SIZE), size+1)); diff --git a/src/main/java/speiger/src/collections/booleans/utils/BooleanAsyncBuilder.java b/src/main/java/speiger/src/collections/booleans/utils/BooleanAsyncBuilder.java index 464674d..29ae440 100644 --- a/src/main/java/speiger/src/collections/booleans/utils/BooleanAsyncBuilder.java +++ b/src/main/java/speiger/src/collections/booleans/utils/BooleanAsyncBuilder.java @@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.LockSupport; import java.util.function.Consumer; +import speiger.src.collections.booleans.functions.OptionalBoolean; import speiger.src.collections.booleans.functions.BooleanConsumer; import speiger.src.collections.booleans.functions.BooleanComparator; @@ -207,9 +208,8 @@ public class BooleanAsyncBuilder * @param operator that reduces the elements. * @return self with the reduce action applied */ - public BooleanAsyncBuilder reduce(BooleanBooleanUnaryOperator operator) { - task = new SimpleReduceTask(iterable.iterator(), operator); - return this; + public ObjectAsyncBuilder reduce(BooleanBooleanUnaryOperator operator) { + return new ObjectAsyncBuilder<>(new SimpleReduceTask(iterable.iterator(), operator)); } /** @@ -281,9 +281,8 @@ public class BooleanAsyncBuilder * @param filter that decides the desired elements * @return self with the findFirst function applied */ - public BooleanAsyncBuilder findFirst(BooleanPredicate filter) { - task = new FindFirstTask(iterable.iterator(), filter); - return this; + public ObjectAsyncBuilder findFirst(BooleanPredicate filter) { + return new ObjectAsyncBuilder<>(new FindFirstTask(iterable.iterator(), filter)); } /** @@ -393,7 +392,7 @@ public class BooleanAsyncBuilder } } - private static class SimpleReduceTask extends BaseBooleanTask + private static class SimpleReduceTask extends BaseObjectTask { BooleanIterator iter; BooleanBooleanUnaryOperator operator; @@ -403,6 +402,7 @@ public class BooleanAsyncBuilder public SimpleReduceTask(BooleanIterator iter, BooleanBooleanUnaryOperator operator) { this.iter = iter; this.operator = operator; + this.setResult(OptionalBoolean.empty()); } @Override @@ -417,7 +417,7 @@ public class BooleanAsyncBuilder } } if(!iter.hasNext()) { - setResult(value); + setResult(OptionalBoolean.of(value)); return true; } return false; @@ -487,7 +487,7 @@ public class BooleanAsyncBuilder } } - private static class FindFirstTask extends BaseBooleanTask + private static class FindFirstTask extends BaseObjectTask { BooleanIterator iter; BooleanPredicate filter; @@ -495,6 +495,7 @@ public class BooleanAsyncBuilder public FindFirstTask(BooleanIterator iter, BooleanPredicate filter) { this.iter = iter; this.filter = filter; + this.setResult(OptionalBoolean.empty()); } @Override @@ -502,7 +503,7 @@ public class BooleanAsyncBuilder while(shouldRun() && iter.hasNext()) { boolean entry = iter.nextBoolean(); if(filter.test(iter.nextBoolean())) { - setResult(entry); + setResult(OptionalBoolean.of(entry)); return true; } } diff --git a/src/main/java/speiger/src/collections/booleans/utils/BooleanCollections.java b/src/main/java/speiger/src/collections/booleans/utils/BooleanCollections.java index a3d2323..ed77bc8 100644 --- a/src/main/java/speiger/src/collections/booleans/utils/BooleanCollections.java +++ b/src/main/java/speiger/src/collections/booleans/utils/BooleanCollections.java @@ -106,7 +106,10 @@ public class BooleanCollections return new SingletonCollection(element); } - protected static CollectionWrapper wrapper() { + /** + * Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed. + */ + public static CollectionWrapper wrapper() { return new CollectionWrapper(); } diff --git a/src/main/java/speiger/src/collections/bytes/lists/CopyOnWriteByteArrayList.java b/src/main/java/speiger/src/collections/bytes/lists/CopyOnWriteByteArrayList.java index 035ba62..37dc7b5 100644 --- a/src/main/java/speiger/src/collections/bytes/lists/CopyOnWriteByteArrayList.java +++ b/src/main/java/speiger/src/collections/bytes/lists/CopyOnWriteByteArrayList.java @@ -111,7 +111,6 @@ public class CopyOnWriteByteArrayList extends AbstractByteList implements ITrimm System.arraycopy(a, offset, data, 0, length); } - private void setArray(byte[] data) { this.data = data; } diff --git a/src/main/java/speiger/src/collections/bytes/lists/ImmutableByteList.java b/src/main/java/speiger/src/collections/bytes/lists/ImmutableByteList.java index 69b5f18..d3e0ed7 100644 --- a/src/main/java/speiger/src/collections/bytes/lists/ImmutableByteList.java +++ b/src/main/java/speiger/src/collections/bytes/lists/ImmutableByteList.java @@ -1,12 +1,15 @@ package speiger.src.collections.bytes.lists; import java.util.Arrays; +import java.util.stream.IntStream; +import java.util.stream.StreamSupport; import java.util.Collection; import java.util.NoSuchElementException; import java.util.Objects; import java.util.function.Predicate; import java.util.function.UnaryOperator; -import java.util.function.IntPredicate;import java.util.function.IntUnaryOperator; +import java.util.function.IntPredicate; +import java.util.function.IntUnaryOperator; import speiger.src.collections.bytes.collections.ByteCollection; import speiger.src.collections.bytes.functions.ByteComparator; @@ -18,8 +21,6 @@ import speiger.src.collections.bytes.functions.function.BytePredicate; import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator; import speiger.src.collections.objects.utils.ObjectArrays; import speiger.src.collections.bytes.utils.ByteIterators; -import java.util.stream.IntStream; -import java.util.stream.StreamSupport; import speiger.src.collections.bytes.collections.ByteSplititerator; import speiger.src.collections.bytes.utils.ByteSplititerators; import speiger.src.collections.utils.SanityChecks; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2BooleanLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2BooleanLinkedOpenCustomHashMap.java index 18c6682..4c86c73 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2BooleanLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2BooleanLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH if(isEmpty() || strategy.equals(firstByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH if(isEmpty() || strategy.equals(lastByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH public boolean getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH public boolean getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ByteLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ByteLinkedOpenCustomHashMap.java index 0440238..cd6130c 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ByteLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ByteLinkedOpenCustomHashMap.java @@ -191,13 +191,13 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -205,7 +205,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -213,7 +213,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -225,13 +225,13 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -239,7 +239,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -247,7 +247,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -260,7 +260,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -271,7 +271,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -284,7 +284,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -295,7 +295,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -306,7 +306,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap if(isEmpty() || strategy.equals(firstByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -314,7 +314,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap if(isEmpty() || strategy.equals(lastByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -336,7 +336,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -349,7 +349,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap public byte getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -357,7 +357,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap public byte getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -533,8 +533,8 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -551,8 +551,8 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2CharLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2CharLinkedOpenCustomHashMap.java index 3d84a4e..8638504 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2CharLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2CharLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap if(isEmpty() || strategy.equals(firstByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap if(isEmpty() || strategy.equals(lastByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap public char getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap public char getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2DoubleLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2DoubleLinkedOpenCustomHashMap.java index 6f4754c..5c8bf6c 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2DoubleLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2DoubleLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas if(isEmpty() || strategy.equals(firstByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas if(isEmpty() || strategy.equals(lastByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas public double getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas public double getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2FloatLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2FloatLinkedOpenCustomHashMap.java index a6412c2..c9e2c40 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2FloatLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2FloatLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM if(isEmpty() || strategy.equals(firstByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM if(isEmpty() || strategy.equals(lastByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM public float getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM public float getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2IntLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2IntLinkedOpenCustomHashMap.java index 746b069..2e3b792 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2IntLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2IntLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i if(isEmpty() || strategy.equals(firstByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i if(isEmpty() || strategy.equals(lastByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i public int getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i public int getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2LongLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2LongLinkedOpenCustomHashMap.java index 839b07a..80bac37 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2LongLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2LongLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap if(isEmpty() || strategy.equals(firstByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap if(isEmpty() || strategy.equals(lastByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap public long getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap public long getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ObjectLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ObjectLinkedOpenCustomHashMap.java index 616323e..13f4e0e 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ObjectLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ObjectLinkedOpenCustomHashMap.java @@ -193,13 +193,13 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -207,7 +207,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -215,7 +215,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -227,13 +227,13 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -241,7 +241,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -249,7 +249,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -262,7 +262,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -273,7 +273,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -286,7 +286,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -297,7 +297,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -308,7 +308,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom if(isEmpty() || strategy.equals(firstByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -316,7 +316,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -330,7 +330,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom if(isEmpty() || strategy.equals(lastByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -338,7 +338,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -351,7 +351,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom public V getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -359,7 +359,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom public V getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -535,8 +535,8 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -553,8 +553,8 @@ public class Byte2ObjectLinkedOpenCustomHashMap extends Byte2ObjectOpenCustom firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ShortLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ShortLinkedOpenCustomHashMap.java index 4144439..1025706 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ShortLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ShortLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM if(isEmpty() || strategy.equals(firstByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM if(isEmpty() || strategy.equals(lastByteKey(), key)) return false; if(strategy.equals(key, (byte)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (byte)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM public short getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM public short getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2BooleanLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2BooleanLinkedOpenHashMap.java index 54e359f..4d1962e 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2BooleanLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2BooleanLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple if(keys[pos] == key) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple if(keys[pos] == key) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple if(isEmpty() || firstByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple if(isEmpty() || lastByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple public boolean getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple public boolean getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ByteLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ByteLinkedOpenHashMap.java index 91f6532..1117cc3 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ByteLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ByteLinkedOpenHashMap.java @@ -168,13 +168,13 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -182,7 +182,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements if(keys[pos] == key) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -190,7 +190,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -202,13 +202,13 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -216,7 +216,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements if(keys[pos] == key) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -224,7 +224,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -237,7 +237,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -248,7 +248,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -261,7 +261,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -272,7 +272,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -283,7 +283,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements if(isEmpty() || firstByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -291,7 +291,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -305,7 +305,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements if(isEmpty() || lastByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -313,7 +313,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements public byte getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -334,7 +334,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements public byte getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2CharLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2CharLinkedOpenHashMap.java index 77b72f5..a3f2091 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2CharLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2CharLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements if(keys[pos] == key) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements if(keys[pos] == key) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements if(isEmpty() || firstByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements if(isEmpty() || lastByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements public char getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements public char getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2DoubleLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2DoubleLinkedOpenHashMap.java index 3dcf8d7..d485dfe 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2DoubleLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2DoubleLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme if(keys[pos] == key) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme if(keys[pos] == key) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme if(isEmpty() || firstByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme if(isEmpty() || lastByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme public double getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme public double getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2FloatLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2FloatLinkedOpenHashMap.java index e4ec298..22fd885 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2FloatLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2FloatLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement if(keys[pos] == key) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement if(keys[pos] == key) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement if(isEmpty() || firstByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement if(isEmpty() || lastByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement public float getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement public float getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2IntLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2IntLinkedOpenHashMap.java index e6bbd7e..9a37ddc 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2IntLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2IntLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By if(keys[pos] == key) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By if(keys[pos] == key) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By if(isEmpty() || firstByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By if(isEmpty() || lastByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By public int getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By public int getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2LongLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2LongLinkedOpenHashMap.java index 6ca052e..3cbc4c6 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2LongLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2LongLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements if(keys[pos] == key) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements if(keys[pos] == key) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements if(isEmpty() || firstByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements if(isEmpty() || lastByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements public long getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements public long getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ObjectLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ObjectLinkedOpenHashMap.java index 93bbf36..74d4ef5 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ObjectLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ObjectLinkedOpenHashMap.java @@ -170,13 +170,13 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -184,7 +184,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i if(keys[pos] == key) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -192,7 +192,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -204,13 +204,13 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -218,7 +218,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i if(keys[pos] == key) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -226,7 +226,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -239,7 +239,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -250,7 +250,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -263,7 +263,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -274,7 +274,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -285,7 +285,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i if(isEmpty() || firstByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -293,7 +293,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -307,7 +307,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i if(isEmpty() || lastByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -315,7 +315,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i public V getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -336,7 +336,7 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i public V getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -522,8 +522,8 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -540,8 +540,8 @@ public class Byte2ObjectLinkedOpenHashMap extends Byte2ObjectOpenHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ShortLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ShortLinkedOpenHashMap.java index d1c3fa0..d574a57 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ShortLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ShortLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement if(keys[pos] == key) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement if(keys[pos] == key) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Byte.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement if(isEmpty() || firstByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement if(isEmpty() || lastByteKey() == key) return false; if(key == (byte)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement int pos = HashUtil.mix(Byte.hashCode(key)) & mask; while(keys[pos] != (byte)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement public short getAndMoveToFirst(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement public short getAndMoveToLast(byte key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/bytes/queues/ByteArrayPriorityQueue.java b/src/main/java/speiger/src/collections/bytes/queues/ByteArrayPriorityQueue.java index a590a7c..9f43161 100644 --- a/src/main/java/speiger/src/collections/bytes/queues/ByteArrayPriorityQueue.java +++ b/src/main/java/speiger/src/collections/bytes/queues/ByteArrayPriorityQueue.java @@ -174,7 +174,6 @@ public class ByteArrayPriorityQueue extends AbstractBytePriorityQueue queue.size = size; return queue; } - @Override public void enqueue(byte e) { if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (long)(array.length >> 1), (long)SanityChecks.MAX_ARRAY_SIZE), size+1)); diff --git a/src/main/java/speiger/src/collections/bytes/sets/ByteArraySet.java b/src/main/java/speiger/src/collections/bytes/sets/ByteArraySet.java index 1bf6c39..0c5e53f 100644 --- a/src/main/java/speiger/src/collections/bytes/sets/ByteArraySet.java +++ b/src/main/java/speiger/src/collections/bytes/sets/ByteArraySet.java @@ -55,7 +55,7 @@ public class ByteArraySet extends AbstractByteSet implements ByteOrderedSet * @param array the array that should be used for set. */ public ByteArraySet(byte[] array) { - this(array, array.length); + this(array, 0, array.length); } /** @@ -69,6 +69,18 @@ public class ByteArraySet extends AbstractByteSet implements ByteOrderedSet addAll(array, length); } + /** + * Constructur using initial Array + * @param array the array that should be used for set. + * @param offset the starting offset of where the array should be copied from + * @param length the amount of elements present within the array + * @throws NegativeArraySizeException if the length is negative + */ + public ByteArraySet(byte[] array, int offset, int length) { + this(length); + addAll(array, offset, length); + } + /** * A Helper constructor that allows to create a Set with exactly the same values as the provided collection. * @param c the elements that should be added to the set. diff --git a/src/main/java/speiger/src/collections/bytes/utils/ByteAsyncBuilder.java b/src/main/java/speiger/src/collections/bytes/utils/ByteAsyncBuilder.java index 7c231ee..9e3d2c6 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/ByteAsyncBuilder.java +++ b/src/main/java/speiger/src/collections/bytes/utils/ByteAsyncBuilder.java @@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.LockSupport; import java.util.function.Consumer; +import speiger.src.collections.bytes.functions.OptionalByte; import speiger.src.collections.bytes.functions.ByteConsumer; import speiger.src.collections.bytes.functions.ByteComparator; @@ -210,9 +211,8 @@ public class ByteAsyncBuilder * @param operator that reduces the elements. * @return self with the reduce action applied */ - public ByteAsyncBuilder reduce(ByteByteUnaryOperator operator) { - task = new SimpleReduceTask(iterable.iterator(), operator); - return this; + public ObjectAsyncBuilder reduce(ByteByteUnaryOperator operator) { + return new ObjectAsyncBuilder<>(new SimpleReduceTask(iterable.iterator(), operator)); } /** @@ -292,9 +292,8 @@ public class ByteAsyncBuilder * @param filter that decides the desired elements * @return self with the findFirst function applied */ - public ByteAsyncBuilder findFirst(BytePredicate filter) { - task = new FindFirstTask(iterable.iterator(), filter); - return this; + public ObjectAsyncBuilder findFirst(BytePredicate filter) { + return new ObjectAsyncBuilder<>(new FindFirstTask(iterable.iterator(), filter)); } /** @@ -404,7 +403,7 @@ public class ByteAsyncBuilder } } - private static class SimpleReduceTask extends BaseByteTask + private static class SimpleReduceTask extends BaseObjectTask { ByteIterator iter; ByteByteUnaryOperator operator; @@ -414,6 +413,7 @@ public class ByteAsyncBuilder public SimpleReduceTask(ByteIterator iter, ByteByteUnaryOperator operator) { this.iter = iter; this.operator = operator; + this.setResult(OptionalByte.empty()); } @Override @@ -428,7 +428,7 @@ public class ByteAsyncBuilder } } if(!iter.hasNext()) { - setResult(value); + setResult(OptionalByte.of(value)); return true; } return false; @@ -498,7 +498,7 @@ public class ByteAsyncBuilder } } - private static class FindFirstTask extends BaseByteTask + private static class FindFirstTask extends BaseObjectTask { ByteIterator iter; BytePredicate filter; @@ -506,6 +506,7 @@ public class ByteAsyncBuilder public FindFirstTask(ByteIterator iter, BytePredicate filter) { this.iter = iter; this.filter = filter; + this.setResult(OptionalByte.empty()); } @Override @@ -513,7 +514,7 @@ public class ByteAsyncBuilder while(shouldRun() && iter.hasNext()) { byte entry = iter.nextByte(); if(filter.test(iter.nextByte())) { - setResult(entry); + setResult(OptionalByte.of(entry)); return true; } } diff --git a/src/main/java/speiger/src/collections/bytes/utils/ByteCollections.java b/src/main/java/speiger/src/collections/bytes/utils/ByteCollections.java index a8e5e5c..75793b0 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/ByteCollections.java +++ b/src/main/java/speiger/src/collections/bytes/utils/ByteCollections.java @@ -109,7 +109,10 @@ public class ByteCollections return new SingletonCollection(element); } - protected static CollectionWrapper wrapper() { + /** + * Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed. + */ + public static CollectionWrapper wrapper() { return new CollectionWrapper(); } diff --git a/src/main/java/speiger/src/collections/chars/lists/CopyOnWriteCharArrayList.java b/src/main/java/speiger/src/collections/chars/lists/CopyOnWriteCharArrayList.java index b7862fe..edfdd6c 100644 --- a/src/main/java/speiger/src/collections/chars/lists/CopyOnWriteCharArrayList.java +++ b/src/main/java/speiger/src/collections/chars/lists/CopyOnWriteCharArrayList.java @@ -111,7 +111,6 @@ public class CopyOnWriteCharArrayList extends AbstractCharList implements ITrimm System.arraycopy(a, offset, data, 0, length); } - private void setArray(char[] data) { this.data = data; } diff --git a/src/main/java/speiger/src/collections/chars/lists/ImmutableCharList.java b/src/main/java/speiger/src/collections/chars/lists/ImmutableCharList.java index 8d057dd..2f18fdc 100644 --- a/src/main/java/speiger/src/collections/chars/lists/ImmutableCharList.java +++ b/src/main/java/speiger/src/collections/chars/lists/ImmutableCharList.java @@ -1,12 +1,15 @@ package speiger.src.collections.chars.lists; import java.util.Arrays; +import java.util.stream.IntStream; +import java.util.stream.StreamSupport; import java.util.Collection; import java.util.NoSuchElementException; import java.util.Objects; import java.util.function.Predicate; import java.util.function.UnaryOperator; -import java.util.function.IntPredicate;import java.util.function.IntUnaryOperator; +import java.util.function.IntPredicate; +import java.util.function.IntUnaryOperator; import speiger.src.collections.chars.collections.CharCollection; import speiger.src.collections.chars.functions.CharComparator; @@ -18,8 +21,6 @@ import speiger.src.collections.chars.functions.function.CharPredicate; import speiger.src.collections.chars.functions.function.CharCharUnaryOperator; import speiger.src.collections.objects.utils.ObjectArrays; import speiger.src.collections.chars.utils.CharIterators; -import java.util.stream.IntStream; -import java.util.stream.StreamSupport; import speiger.src.collections.chars.collections.CharSplititerator; import speiger.src.collections.chars.utils.CharSplititerators; import speiger.src.collections.utils.SanityChecks; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2BooleanLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2BooleanLinkedOpenCustomHashMap.java index fa64075..9d24a7d 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2BooleanLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2BooleanLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH if(isEmpty() || strategy.equals(firstCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH if(isEmpty() || strategy.equals(lastCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH public boolean getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH public boolean getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Char2BooleanLinkedOpenCustomHashMap extends Char2BooleanOpenCustomH firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ByteLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ByteLinkedOpenCustomHashMap.java index 79c0324..0f959b8 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ByteLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ByteLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap if(isEmpty() || strategy.equals(firstCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap if(isEmpty() || strategy.equals(lastCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap public byte getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap public byte getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Char2ByteLinkedOpenCustomHashMap extends Char2ByteOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2CharLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2CharLinkedOpenCustomHashMap.java index 6e29c60..9b009cc 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2CharLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2CharLinkedOpenCustomHashMap.java @@ -191,13 +191,13 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -205,7 +205,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -213,7 +213,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -225,13 +225,13 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -239,7 +239,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -247,7 +247,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -260,7 +260,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -271,7 +271,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -284,7 +284,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -295,7 +295,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -306,7 +306,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap if(isEmpty() || strategy.equals(firstCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -314,7 +314,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap if(isEmpty() || strategy.equals(lastCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -336,7 +336,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -349,7 +349,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap public char getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -357,7 +357,7 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap public char getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -533,8 +533,8 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -551,8 +551,8 @@ public class Char2CharLinkedOpenCustomHashMap extends Char2CharOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2DoubleLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2DoubleLinkedOpenCustomHashMap.java index cfbe6f9..4db44f0 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2DoubleLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2DoubleLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas if(isEmpty() || strategy.equals(firstCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas if(isEmpty() || strategy.equals(lastCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas public double getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas public double getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Char2DoubleLinkedOpenCustomHashMap extends Char2DoubleOpenCustomHas firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2FloatLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2FloatLinkedOpenCustomHashMap.java index cca19cc..8dce135 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2FloatLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2FloatLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM if(isEmpty() || strategy.equals(firstCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM if(isEmpty() || strategy.equals(lastCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM public float getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM public float getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Char2FloatLinkedOpenCustomHashMap extends Char2FloatOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2IntLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2IntLinkedOpenCustomHashMap.java index c5e5beb..a9def2c 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2IntLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2IntLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i if(isEmpty() || strategy.equals(firstCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i if(isEmpty() || strategy.equals(lastCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i public int getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i public int getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Char2IntLinkedOpenCustomHashMap extends Char2IntOpenCustomHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2LongLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2LongLinkedOpenCustomHashMap.java index 9578ab1..f40e8e8 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2LongLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2LongLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap if(isEmpty() || strategy.equals(firstCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap if(isEmpty() || strategy.equals(lastCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap public long getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap public long getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Char2LongLinkedOpenCustomHashMap extends Char2LongOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ObjectLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ObjectLinkedOpenCustomHashMap.java index 5a3d8b9..0fc479b 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ObjectLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ObjectLinkedOpenCustomHashMap.java @@ -193,13 +193,13 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -207,7 +207,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -215,7 +215,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -227,13 +227,13 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -241,7 +241,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -249,7 +249,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -262,7 +262,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -273,7 +273,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -286,7 +286,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -297,7 +297,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -308,7 +308,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom if(isEmpty() || strategy.equals(firstCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -316,7 +316,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -330,7 +330,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom if(isEmpty() || strategy.equals(lastCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -338,7 +338,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -351,7 +351,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom public V getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -359,7 +359,7 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom public V getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -535,8 +535,8 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -553,8 +553,8 @@ public class Char2ObjectLinkedOpenCustomHashMap extends Char2ObjectOpenCustom firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ShortLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ShortLinkedOpenCustomHashMap.java index ccf3a24..82a7ac9 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ShortLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ShortLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM if(isEmpty() || strategy.equals(firstCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM if(isEmpty() || strategy.equals(lastCharKey(), key)) return false; if(strategy.equals(key, (char)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (char)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM public short getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM public short getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Char2ShortLinkedOpenCustomHashMap extends Char2ShortOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2BooleanLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2BooleanLinkedOpenHashMap.java index f6ed4b9..d47e746 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2BooleanLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2BooleanLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple if(keys[pos] == key) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple if(keys[pos] == key) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple if(isEmpty() || firstCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple if(isEmpty() || lastCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple public boolean getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple public boolean getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Char2BooleanLinkedOpenHashMap extends Char2BooleanOpenHashMap imple firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ByteLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ByteLinkedOpenHashMap.java index 002dce4..e6bfb4e 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ByteLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ByteLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements if(keys[pos] == key) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements if(keys[pos] == key) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements if(isEmpty() || firstCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements if(isEmpty() || lastCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements public byte getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements public byte getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Char2ByteLinkedOpenHashMap extends Char2ByteOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2CharLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2CharLinkedOpenHashMap.java index fb84e4a..22b4c97 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2CharLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2CharLinkedOpenHashMap.java @@ -168,13 +168,13 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -182,7 +182,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements if(keys[pos] == key) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -190,7 +190,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -202,13 +202,13 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -216,7 +216,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements if(keys[pos] == key) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -224,7 +224,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -237,7 +237,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -248,7 +248,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -261,7 +261,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -272,7 +272,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -283,7 +283,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements if(isEmpty() || firstCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -291,7 +291,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -305,7 +305,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements if(isEmpty() || lastCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -313,7 +313,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements public char getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -334,7 +334,7 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements public char getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Char2CharLinkedOpenHashMap extends Char2CharOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2DoubleLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2DoubleLinkedOpenHashMap.java index 0619c44..18bc032 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2DoubleLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2DoubleLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme if(keys[pos] == key) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme if(keys[pos] == key) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme if(isEmpty() || firstCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme if(isEmpty() || lastCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme public double getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme public double getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Char2DoubleLinkedOpenHashMap extends Char2DoubleOpenHashMap impleme firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2FloatLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2FloatLinkedOpenHashMap.java index 97cc475..7c338d1 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2FloatLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2FloatLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement if(keys[pos] == key) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement if(keys[pos] == key) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement if(isEmpty() || firstCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement if(isEmpty() || lastCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement public float getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement public float getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Char2FloatLinkedOpenHashMap extends Char2FloatOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2IntLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2IntLinkedOpenHashMap.java index 1938d3d..263b54d 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2IntLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2IntLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch if(keys[pos] == key) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch if(keys[pos] == key) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch if(isEmpty() || firstCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch if(isEmpty() || lastCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch public int getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch public int getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Char2IntLinkedOpenHashMap extends Char2IntOpenHashMap implements Ch firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2LongLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2LongLinkedOpenHashMap.java index a842c96..63d42f2 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2LongLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2LongLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements if(keys[pos] == key) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements if(keys[pos] == key) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements if(isEmpty() || firstCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements if(isEmpty() || lastCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements public long getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements public long getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Char2LongLinkedOpenHashMap extends Char2LongOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ObjectLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ObjectLinkedOpenHashMap.java index 050286d..5d6d286 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ObjectLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ObjectLinkedOpenHashMap.java @@ -170,13 +170,13 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -184,7 +184,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i if(keys[pos] == key) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -192,7 +192,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -204,13 +204,13 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -218,7 +218,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i if(keys[pos] == key) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -226,7 +226,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -239,7 +239,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -250,7 +250,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -263,7 +263,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -274,7 +274,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -285,7 +285,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i if(isEmpty() || firstCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -293,7 +293,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -307,7 +307,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i if(isEmpty() || lastCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -315,7 +315,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i public V getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -336,7 +336,7 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i public V getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -522,8 +522,8 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -540,8 +540,8 @@ public class Char2ObjectLinkedOpenHashMap extends Char2ObjectOpenHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ShortLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ShortLinkedOpenHashMap.java index bd3dfa2..962ba93 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ShortLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ShortLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement if(keys[pos] == key) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement if(keys[pos] == key) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Character.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement if(isEmpty() || firstCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement if(isEmpty() || lastCharKey() == key) return false; if(key == (char)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement int pos = HashUtil.mix(Character.hashCode(key)) & mask; while(keys[pos] != (char)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement public short getAndMoveToFirst(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement public short getAndMoveToLast(char key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Char2ShortLinkedOpenHashMap extends Char2ShortOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/chars/queues/CharArrayPriorityQueue.java b/src/main/java/speiger/src/collections/chars/queues/CharArrayPriorityQueue.java index 7c664e6..e23eb82 100644 --- a/src/main/java/speiger/src/collections/chars/queues/CharArrayPriorityQueue.java +++ b/src/main/java/speiger/src/collections/chars/queues/CharArrayPriorityQueue.java @@ -174,7 +174,6 @@ public class CharArrayPriorityQueue extends AbstractCharPriorityQueue queue.size = size; return queue; } - @Override public void enqueue(char e) { if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (long)(array.length >> 1), (long)SanityChecks.MAX_ARRAY_SIZE), size+1)); diff --git a/src/main/java/speiger/src/collections/chars/sets/CharArraySet.java b/src/main/java/speiger/src/collections/chars/sets/CharArraySet.java index 64e6e0c..01206c8 100644 --- a/src/main/java/speiger/src/collections/chars/sets/CharArraySet.java +++ b/src/main/java/speiger/src/collections/chars/sets/CharArraySet.java @@ -55,7 +55,7 @@ public class CharArraySet extends AbstractCharSet implements CharOrderedSet * @param array the array that should be used for set. */ public CharArraySet(char[] array) { - this(array, array.length); + this(array, 0, array.length); } /** @@ -69,6 +69,18 @@ public class CharArraySet extends AbstractCharSet implements CharOrderedSet addAll(array, length); } + /** + * Constructur using initial Array + * @param array the array that should be used for set. + * @param offset the starting offset of where the array should be copied from + * @param length the amount of elements present within the array + * @throws NegativeArraySizeException if the length is negative + */ + public CharArraySet(char[] array, int offset, int length) { + this(length); + addAll(array, offset, length); + } + /** * A Helper constructor that allows to create a Set with exactly the same values as the provided collection. * @param c the elements that should be added to the set. diff --git a/src/main/java/speiger/src/collections/chars/utils/CharAsyncBuilder.java b/src/main/java/speiger/src/collections/chars/utils/CharAsyncBuilder.java index 5cb6649..e40b2c9 100644 --- a/src/main/java/speiger/src/collections/chars/utils/CharAsyncBuilder.java +++ b/src/main/java/speiger/src/collections/chars/utils/CharAsyncBuilder.java @@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.LockSupport; import java.util.function.Consumer; +import speiger.src.collections.chars.functions.OptionalChar; import speiger.src.collections.chars.functions.CharConsumer; import speiger.src.collections.chars.functions.CharComparator; @@ -210,9 +211,8 @@ public class CharAsyncBuilder * @param operator that reduces the elements. * @return self with the reduce action applied */ - public CharAsyncBuilder reduce(CharCharUnaryOperator operator) { - task = new SimpleReduceTask(iterable.iterator(), operator); - return this; + public ObjectAsyncBuilder reduce(CharCharUnaryOperator operator) { + return new ObjectAsyncBuilder<>(new SimpleReduceTask(iterable.iterator(), operator)); } /** @@ -292,9 +292,8 @@ public class CharAsyncBuilder * @param filter that decides the desired elements * @return self with the findFirst function applied */ - public CharAsyncBuilder findFirst(CharPredicate filter) { - task = new FindFirstTask(iterable.iterator(), filter); - return this; + public ObjectAsyncBuilder findFirst(CharPredicate filter) { + return new ObjectAsyncBuilder<>(new FindFirstTask(iterable.iterator(), filter)); } /** @@ -404,7 +403,7 @@ public class CharAsyncBuilder } } - private static class SimpleReduceTask extends BaseCharTask + private static class SimpleReduceTask extends BaseObjectTask { CharIterator iter; CharCharUnaryOperator operator; @@ -414,6 +413,7 @@ public class CharAsyncBuilder public SimpleReduceTask(CharIterator iter, CharCharUnaryOperator operator) { this.iter = iter; this.operator = operator; + this.setResult(OptionalChar.empty()); } @Override @@ -428,7 +428,7 @@ public class CharAsyncBuilder } } if(!iter.hasNext()) { - setResult(value); + setResult(OptionalChar.of(value)); return true; } return false; @@ -498,7 +498,7 @@ public class CharAsyncBuilder } } - private static class FindFirstTask extends BaseCharTask + private static class FindFirstTask extends BaseObjectTask { CharIterator iter; CharPredicate filter; @@ -506,6 +506,7 @@ public class CharAsyncBuilder public FindFirstTask(CharIterator iter, CharPredicate filter) { this.iter = iter; this.filter = filter; + this.setResult(OptionalChar.empty()); } @Override @@ -513,7 +514,7 @@ public class CharAsyncBuilder while(shouldRun() && iter.hasNext()) { char entry = iter.nextChar(); if(filter.test(iter.nextChar())) { - setResult(entry); + setResult(OptionalChar.of(entry)); return true; } } diff --git a/src/main/java/speiger/src/collections/chars/utils/CharCollections.java b/src/main/java/speiger/src/collections/chars/utils/CharCollections.java index 4f9158f..a5adcf1 100644 --- a/src/main/java/speiger/src/collections/chars/utils/CharCollections.java +++ b/src/main/java/speiger/src/collections/chars/utils/CharCollections.java @@ -109,7 +109,10 @@ public class CharCollections return new SingletonCollection(element); } - protected static CollectionWrapper wrapper() { + /** + * Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed. + */ + public static CollectionWrapper wrapper() { return new CollectionWrapper(); } diff --git a/src/main/java/speiger/src/collections/doubles/lists/CopyOnWriteDoubleArrayList.java b/src/main/java/speiger/src/collections/doubles/lists/CopyOnWriteDoubleArrayList.java index d218470..a834a4d 100644 --- a/src/main/java/speiger/src/collections/doubles/lists/CopyOnWriteDoubleArrayList.java +++ b/src/main/java/speiger/src/collections/doubles/lists/CopyOnWriteDoubleArrayList.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalDouble; + import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; import java.util.function.Supplier; @@ -111,6 +112,14 @@ public class CopyOnWriteDoubleArrayList extends AbstractDoubleList implements IT System.arraycopy(a, offset, data, 0, length); } + + /** + * Collects a Stream to a CopyOnWriteArrayList + * @return a list with the contents of the Stream + */ + public static CopyOnWriteDoubleArrayList toList(DoubleStream stream) { + return stream.collect(CopyOnWriteDoubleArrayList::new, CopyOnWriteDoubleArrayList::add, CopyOnWriteDoubleArrayList::addAll); + } private void setArray(double[] data) { this.data = data; diff --git a/src/main/java/speiger/src/collections/doubles/lists/DoubleArrayList.java b/src/main/java/speiger/src/collections/doubles/lists/DoubleArrayList.java index 755a5d3..f7792b2 100644 --- a/src/main/java/speiger/src/collections/doubles/lists/DoubleArrayList.java +++ b/src/main/java/speiger/src/collections/doubles/lists/DoubleArrayList.java @@ -5,6 +5,8 @@ import java.util.Collection; import java.util.Iterator; import java.util.Objects; import java.util.OptionalDouble; + + import java.util.function.DoublePredicate; import java.util.function.Predicate; import java.util.function.UnaryOperator; @@ -144,6 +146,15 @@ public class DoubleArrayList extends AbstractDoubleList implements IDoubleArray, return list; } + + /** + * Collects a Stream to a ArrayList + * @return a list with the contents of the Stream + */ + public static DoubleArrayList toList(DoubleStream stream) { + return stream.collect(DoubleArrayList::new, DoubleArrayList::add, DoubleArrayList::addAll); + } + /** * Appends the specified element to the end of this list. * diff --git a/src/main/java/speiger/src/collections/doubles/lists/DoubleLinkedList.java b/src/main/java/speiger/src/collections/doubles/lists/DoubleLinkedList.java index 4654a60..5c6a2b5 100644 --- a/src/main/java/speiger/src/collections/doubles/lists/DoubleLinkedList.java +++ b/src/main/java/speiger/src/collections/doubles/lists/DoubleLinkedList.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.Objects; import java.util.OptionalDouble; + import java.util.NoSuchElementException; import java.util.Spliterator; import java.util.Spliterator.OfDouble; @@ -103,6 +104,15 @@ public class DoubleLinkedList extends AbstractDoubleList implements DoublePriori for(int i = offset,m=offset+length;i)DoubleCollections::wrapper, DoubleCollection::add, DoubleCollection::addAll).toDoubleArray()); + } + @Override public boolean add(double e) { throw new UnsupportedOperationException(); } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2BooleanLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2BooleanLinkedOpenCustomHashMap.java index 5d5e8a3..a864588 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2BooleanLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2BooleanLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus if(isEmpty() || strategy.equals(firstDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus if(isEmpty() || strategy.equals(lastDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus public boolean getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus public boolean getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Double2BooleanLinkedOpenCustomHashMap extends Double2BooleanOpenCus firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ByteLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ByteLinkedOpenCustomHashMap.java index 0665f15..a741d07 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ByteLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ByteLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas if(isEmpty() || strategy.equals(firstDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas if(isEmpty() || strategy.equals(lastDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas public byte getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas public byte getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Double2ByteLinkedOpenCustomHashMap extends Double2ByteOpenCustomHas firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2CharLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2CharLinkedOpenCustomHashMap.java index 5c958da..4f84e16 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2CharLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2CharLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas if(isEmpty() || strategy.equals(firstDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas if(isEmpty() || strategy.equals(lastDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas public char getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas public char getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Double2CharLinkedOpenCustomHashMap extends Double2CharOpenCustomHas firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2DoubleLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2DoubleLinkedOpenCustomHashMap.java index 3372a3b..0bd5cd0 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2DoubleLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2DoubleLinkedOpenCustomHashMap.java @@ -191,13 +191,13 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -205,7 +205,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -213,7 +213,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -225,13 +225,13 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -239,7 +239,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -247,7 +247,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -260,7 +260,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -271,7 +271,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -284,7 +284,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -295,7 +295,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -306,7 +306,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto if(isEmpty() || strategy.equals(firstDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -314,7 +314,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto if(isEmpty() || strategy.equals(lastDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -336,7 +336,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -349,7 +349,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto public double getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -357,7 +357,7 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto public double getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -533,8 +533,8 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -551,8 +551,8 @@ public class Double2DoubleLinkedOpenCustomHashMap extends Double2DoubleOpenCusto firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2FloatLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2FloatLinkedOpenCustomHashMap.java index 403af42..3c43210 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2FloatLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2FloatLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH if(isEmpty() || strategy.equals(firstDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH if(isEmpty() || strategy.equals(lastDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH public float getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH public float getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Double2FloatLinkedOpenCustomHashMap extends Double2FloatOpenCustomH firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2IntLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2IntLinkedOpenCustomHashMap.java index c6505d2..0c323b4 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2IntLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2IntLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM if(isEmpty() || strategy.equals(firstDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM if(isEmpty() || strategy.equals(lastDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM public int getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM public int getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Double2IntLinkedOpenCustomHashMap extends Double2IntOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2LongLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2LongLinkedOpenCustomHashMap.java index ee8e523..96c60a5 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2LongLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2LongLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas if(isEmpty() || strategy.equals(firstDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas if(isEmpty() || strategy.equals(lastDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas public long getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas public long getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Double2LongLinkedOpenCustomHashMap extends Double2LongOpenCustomHas firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ObjectLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ObjectLinkedOpenCustomHashMap.java index 349de59..bac418d 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ObjectLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ObjectLinkedOpenCustomHashMap.java @@ -193,13 +193,13 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -207,7 +207,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -215,7 +215,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -227,13 +227,13 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -241,7 +241,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -249,7 +249,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -262,7 +262,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -273,7 +273,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -286,7 +286,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -297,7 +297,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -308,7 +308,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu if(isEmpty() || strategy.equals(firstDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -316,7 +316,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -330,7 +330,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu if(isEmpty() || strategy.equals(lastDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -338,7 +338,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -351,7 +351,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu public V getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -359,7 +359,7 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu public V getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -535,8 +535,8 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -553,8 +553,8 @@ public class Double2ObjectLinkedOpenCustomHashMap extends Double2ObjectOpenCu firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ShortLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ShortLinkedOpenCustomHashMap.java index 9c7f1aa..d202803 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ShortLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ShortLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH if(isEmpty() || strategy.equals(firstDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH if(isEmpty() || strategy.equals(lastDoubleKey(), key)) return false; if(strategy.equals(key, 0D)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0D)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH public short getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH public short getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Double2ShortLinkedOpenCustomHashMap extends Double2ShortOpenCustomH firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2BooleanLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2BooleanLinkedOpenHashMap.java index 51a98c7..9a85a4f 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2BooleanLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2BooleanLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i if(isEmpty() || Double.doubleToLongBits(firstDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i if(isEmpty() || Double.doubleToLongBits(lastDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i public boolean getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i public boolean getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Double2BooleanLinkedOpenHashMap extends Double2BooleanOpenHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ByteLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ByteLinkedOpenHashMap.java index 4fe85b3..e4cbf52 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ByteLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ByteLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme if(isEmpty() || Double.doubleToLongBits(firstDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme if(isEmpty() || Double.doubleToLongBits(lastDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme public byte getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme public byte getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Double2ByteLinkedOpenHashMap extends Double2ByteOpenHashMap impleme firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2CharLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2CharLinkedOpenHashMap.java index 808b786..73c7b9a 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2CharLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2CharLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme if(isEmpty() || Double.doubleToLongBits(firstDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme if(isEmpty() || Double.doubleToLongBits(lastDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme public char getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme public char getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Double2CharLinkedOpenHashMap extends Double2CharOpenHashMap impleme firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2DoubleLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2DoubleLinkedOpenHashMap.java index e7b4de4..131be58 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2DoubleLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2DoubleLinkedOpenHashMap.java @@ -168,13 +168,13 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -182,7 +182,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -190,7 +190,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -202,13 +202,13 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -216,7 +216,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -224,7 +224,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -237,7 +237,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -248,7 +248,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -261,7 +261,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -272,7 +272,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -283,7 +283,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp if(isEmpty() || Double.doubleToLongBits(firstDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -291,7 +291,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -305,7 +305,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp if(isEmpty() || Double.doubleToLongBits(lastDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -313,7 +313,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp public double getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -334,7 +334,7 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp public double getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Double2DoubleLinkedOpenHashMap extends Double2DoubleOpenHashMap imp firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2FloatLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2FloatLinkedOpenHashMap.java index 8eea882..4fa6138 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2FloatLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2FloatLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple if(isEmpty() || Double.doubleToLongBits(firstDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple if(isEmpty() || Double.doubleToLongBits(lastDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple public float getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple public float getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Double2FloatLinkedOpenHashMap extends Double2FloatOpenHashMap imple firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2IntLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2IntLinkedOpenHashMap.java index a9020a6..01e5e3e 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2IntLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2IntLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement if(isEmpty() || Double.doubleToLongBits(firstDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement if(isEmpty() || Double.doubleToLongBits(lastDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement public int getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement public int getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Double2IntLinkedOpenHashMap extends Double2IntOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2LongLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2LongLinkedOpenHashMap.java index a789d89..25dfaf5 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2LongLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2LongLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme if(isEmpty() || Double.doubleToLongBits(firstDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme if(isEmpty() || Double.doubleToLongBits(lastDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme public long getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme public long getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Double2LongLinkedOpenHashMap extends Double2LongOpenHashMap impleme firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ObjectLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ObjectLinkedOpenHashMap.java index 074d734..06b6fc7 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ObjectLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ObjectLinkedOpenHashMap.java @@ -170,13 +170,13 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -184,7 +184,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -192,7 +192,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -204,13 +204,13 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -218,7 +218,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -226,7 +226,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -239,7 +239,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -250,7 +250,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -263,7 +263,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -274,7 +274,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -285,7 +285,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< if(isEmpty() || Double.doubleToLongBits(firstDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -293,7 +293,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -307,7 +307,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< if(isEmpty() || Double.doubleToLongBits(lastDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -315,7 +315,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< public V getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -336,7 +336,7 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< public V getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -522,8 +522,8 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -540,8 +540,8 @@ public class Double2ObjectLinkedOpenHashMap extends Double2ObjectOpenHashMap< firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ShortLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ShortLinkedOpenHashMap.java index 7584844..a636a66 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ShortLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ShortLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Double.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple if(isEmpty() || Double.doubleToLongBits(firstDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple if(isEmpty() || Double.doubleToLongBits(lastDoubleKey()) == Double.doubleToLongBits(key)) return false; if(Double.doubleToLongBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple int pos = HashUtil.mix(Double.hashCode(key)) & mask; while(Double.doubleToLongBits(keys[pos]) != 0) { if(Double.doubleToLongBits(keys[pos]) == Double.doubleToLongBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple public short getAndMoveToFirst(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple public short getAndMoveToLast(double key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Double2ShortLinkedOpenHashMap extends Double2ShortOpenHashMap imple firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayFIFOQueue.java b/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayFIFOQueue.java index 97d82a6..d67fda2 100644 --- a/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayFIFOQueue.java @@ -3,6 +3,7 @@ package speiger.src.collections.doubles.queues; import java.util.Arrays; import java.util.Objects; import java.util.OptionalDouble; +import java.util.stream.DoubleStream; import java.util.NoSuchElementException; import java.util.function.DoublePredicate; @@ -87,6 +88,20 @@ public class DoubleArrayFIFOQueue extends AbstractDoublePriorityQueue implements this(MIN_CAPACITY); } + + /** + * Collects a Stream to a ArrayFIFOQueue + * @return a queue with the contents of the Stream + */ + public static DoubleArrayFIFOQueue toQueue(DoubleStream stream) { + return stream.collect(DoubleArrayFIFOQueue::new, DoubleArrayFIFOQueue::enqueue, DoubleArrayFIFOQueue::merge); + } + + private DoubleArrayFIFOQueue merge(DoubleArrayFIFOQueue a) { + enqueueAll(a.toDoubleArray()); + return this; + } + @Override public DoubleIterator iterator() { return new Iter(); diff --git a/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayPriorityQueue.java b/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayPriorityQueue.java index 38ace79..300ecac 100644 --- a/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayPriorityQueue.java +++ b/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayPriorityQueue.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalDouble; +import java.util.stream.DoubleStream; import java.util.function.DoublePredicate; import speiger.src.collections.doubles.collections.DoubleCollection; @@ -174,6 +175,19 @@ public class DoubleArrayPriorityQueue extends AbstractDoublePriorityQueue queue.size = size; return queue; } + + /** + * Collects a Stream to a ArrayPriorityQueue + * @return a queue with the contents of the Stream + */ + public static DoubleArrayPriorityQueue toQueue(DoubleStream stream) { + return stream.collect(DoubleArrayPriorityQueue::new, DoubleArrayPriorityQueue::enqueue, DoubleArrayPriorityQueue::merge); + } + + private DoubleArrayPriorityQueue merge(DoubleArrayPriorityQueue a) { + enqueueAll(a.toDoubleArray()); + return this; + } @Override public void enqueue(double e) { diff --git a/src/main/java/speiger/src/collections/doubles/queues/DoubleHeapPriorityQueue.java b/src/main/java/speiger/src/collections/doubles/queues/DoubleHeapPriorityQueue.java index b0f2c8b..8b7584d 100644 --- a/src/main/java/speiger/src/collections/doubles/queues/DoubleHeapPriorityQueue.java +++ b/src/main/java/speiger/src/collections/doubles/queues/DoubleHeapPriorityQueue.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalDouble; +import java.util.stream.DoubleStream; import java.util.function.DoublePredicate; import speiger.src.collections.doubles.collections.DoubleCollection; @@ -177,6 +178,20 @@ public class DoubleHeapPriorityQueue extends AbstractDoublePriorityQueue return queue; } + + /** + * Collects a Stream to a ArrayFIFOQueue + * @return a queue with the contents of the Stream + */ + public static DoubleHeapPriorityQueue toQueue(DoubleStream stream) { + return stream.collect(DoubleHeapPriorityQueue::new, DoubleHeapPriorityQueue::enqueue, DoubleHeapPriorityQueue::merge); + } + + private DoubleHeapPriorityQueue merge(DoubleHeapPriorityQueue a) { + enqueueAll(a.toDoubleArray()); + return this; + } + @Override public int size() { return size; diff --git a/src/main/java/speiger/src/collections/doubles/sets/DoubleAVLTreeSet.java b/src/main/java/speiger/src/collections/doubles/sets/DoubleAVLTreeSet.java index 55c55f6..155d38a 100644 --- a/src/main/java/speiger/src/collections/doubles/sets/DoubleAVLTreeSet.java +++ b/src/main/java/speiger/src/collections/doubles/sets/DoubleAVLTreeSet.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalDouble; +import java.util.stream.DoubleStream; import java.util.function.DoublePredicate; import speiger.src.collections.doubles.collections.DoubleBidirectionalIterator; @@ -183,6 +184,15 @@ public class DoubleAVLTreeSet extends AbstractDoubleSet implements DoubleNavigab while(iterator.hasNext()) add(iterator.nextDouble()); } + + /** + * Collects a Stream to a AVLTreeSet + * @return a set with the contents of the Stream + */ + public static DoubleAVLTreeSet toSet(DoubleStream stream) { + return stream.collect(DoubleAVLTreeSet::new, DoubleAVLTreeSet::add, DoubleAVLTreeSet::addAll); + } + @Override public void setDefaultMaxValue(double value) { defaultMaxNotFound = value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/sets/DoubleArraySet.java b/src/main/java/speiger/src/collections/doubles/sets/DoubleArraySet.java index dee52d8..acd806d 100644 --- a/src/main/java/speiger/src/collections/doubles/sets/DoubleArraySet.java +++ b/src/main/java/speiger/src/collections/doubles/sets/DoubleArraySet.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalDouble; +import java.util.stream.DoubleStream; import java.util.Set; import java.util.function.DoublePredicate; import speiger.src.collections.doubles.collections.DoubleBidirectionalIterator; @@ -54,7 +55,7 @@ public class DoubleArraySet extends AbstractDoubleSet implements DoubleOrderedSe * @param array the array that should be used for set. */ public DoubleArraySet(double[] array) { - this(array, array.length); + this(array, 0, array.length); } /** @@ -68,6 +69,18 @@ public class DoubleArraySet extends AbstractDoubleSet implements DoubleOrderedSe addAll(array, length); } + /** + * Constructur using initial Array + * @param array the array that should be used for set. + * @param offset the starting offset of where the array should be copied from + * @param length the amount of elements present within the array + * @throws NegativeArraySizeException if the length is negative + */ + public DoubleArraySet(double[] array, int offset, int length) { + this(length); + addAll(array, offset, length); + } + /** * A Helper constructor that allows to create a Set with exactly the same values as the provided collection. * @param c the elements that should be added to the set. @@ -111,6 +124,15 @@ public class DoubleArraySet extends AbstractDoubleSet implements DoubleOrderedSe for(DoubleIterator iter = s.iterator();iter.hasNext();data[size++] = iter.nextDouble()); } + + /** + * Collects a Stream to a ArraySet + * @return a set with the contents of the Stream + */ + public static DoubleArraySet toList(DoubleStream stream) { + return stream.collect(DoubleArraySet::new, DoubleArraySet::add, DoubleArraySet::addAll); + } + @Override public boolean add(double o) { int index = findIndex(o); diff --git a/src/main/java/speiger/src/collections/doubles/sets/DoubleLinkedOpenCustomHashSet.java b/src/main/java/speiger/src/collections/doubles/sets/DoubleLinkedOpenCustomHashSet.java index fb094ea..3e2e601 100644 --- a/src/main/java/speiger/src/collections/doubles/sets/DoubleLinkedOpenCustomHashSet.java +++ b/src/main/java/speiger/src/collections/doubles/sets/DoubleLinkedOpenCustomHashSet.java @@ -6,6 +6,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.OptionalDouble; +import java.util.stream.DoubleStream; import java.util.function.DoublePredicate; import speiger.src.collections.doubles.collections.DoubleCollection; @@ -215,6 +216,15 @@ public class DoubleLinkedOpenCustomHashSet extends DoubleOpenCustomHashSet imple while(iterator.hasNext()) add(iterator.nextDouble()); } + + /** + * Collects a Stream to a LinkedCustomHashSet + * @return a set with the contents of the Stream + */ + public static DoubleLinkedOpenCustomHashSet toList(DoubleStream stream, DoubleStrategy strategy) { + return stream.collect(() -> new DoubleLinkedOpenCustomHashSet(strategy), DoubleLinkedOpenCustomHashSet::add, DoubleLinkedOpenCustomHashSet::addAll); + } + @Override public void addFirst(double o) { if(strategy.equals(o, 0D)) { diff --git a/src/main/java/speiger/src/collections/doubles/sets/DoubleLinkedOpenHashSet.java b/src/main/java/speiger/src/collections/doubles/sets/DoubleLinkedOpenHashSet.java index 93fa1b1..9938ec8 100644 --- a/src/main/java/speiger/src/collections/doubles/sets/DoubleLinkedOpenHashSet.java +++ b/src/main/java/speiger/src/collections/doubles/sets/DoubleLinkedOpenHashSet.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalDouble; +import java.util.stream.DoubleStream; import java.util.function.DoublePredicate; import speiger.src.collections.doubles.collections.DoubleCollection; @@ -184,6 +185,15 @@ public class DoubleLinkedOpenHashSet extends DoubleOpenHashSet implements Double while(iterator.hasNext()) add(iterator.nextDouble()); } + + /** + * Collects a Stream to a LinkedHashSet + * @return a set with the contents of the Stream + */ + public static DoubleLinkedOpenHashSet toLinkedSet(DoubleStream stream) { + return stream.collect(DoubleLinkedOpenHashSet::new, DoubleLinkedOpenHashSet::add, DoubleLinkedOpenHashSet::addAll); + } + @Override public void addFirst(double o) { if(Double.doubleToLongBits(o) == 0) { diff --git a/src/main/java/speiger/src/collections/doubles/sets/DoubleOpenCustomHashSet.java b/src/main/java/speiger/src/collections/doubles/sets/DoubleOpenCustomHashSet.java index b49fa4a..38af72e 100644 --- a/src/main/java/speiger/src/collections/doubles/sets/DoubleOpenCustomHashSet.java +++ b/src/main/java/speiger/src/collections/doubles/sets/DoubleOpenCustomHashSet.java @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalDouble; +import java.util.stream.DoubleStream; import java.util.function.DoublePredicate; import speiger.src.collections.doubles.collections.DoubleCollection; @@ -234,6 +235,15 @@ public class DoubleOpenCustomHashSet extends AbstractDoubleSet implements ITrimm while(iterator.hasNext()) add(iterator.nextDouble()); } + + /** + * Collects a Stream to a CustomHashSet + * @return a set with the contents of the Stream + */ + public static DoubleOpenCustomHashSet toSet(DoubleStream stream, DoubleStrategy strategy) { + return stream.collect(() -> new DoubleOpenCustomHashSet(strategy), DoubleOpenCustomHashSet::add, DoubleOpenCustomHashSet::addAll); + } + /** * Helper getter function to get the current strategy * @return the current strategy diff --git a/src/main/java/speiger/src/collections/doubles/sets/DoubleOpenHashSet.java b/src/main/java/speiger/src/collections/doubles/sets/DoubleOpenHashSet.java index 838551f..a263192 100644 --- a/src/main/java/speiger/src/collections/doubles/sets/DoubleOpenHashSet.java +++ b/src/main/java/speiger/src/collections/doubles/sets/DoubleOpenHashSet.java @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalDouble; +import java.util.stream.DoubleStream; import java.util.function.DoublePredicate; import speiger.src.collections.doubles.collections.DoubleCollection; @@ -201,6 +202,15 @@ public class DoubleOpenHashSet extends AbstractDoubleSet implements ITrimmable while(iterator.hasNext()) add(iterator.nextDouble()); } + + /** + * Collects a Stream to a HashSet + * @return a set with the contents of the Stream + */ + public static DoubleOpenHashSet toSet(DoubleStream stream) { + return stream.collect(DoubleOpenHashSet::new, DoubleOpenHashSet::add, DoubleOpenHashSet::addAll); + } + @Override public boolean add(double o) { if(Double.doubleToLongBits(o) == 0) { diff --git a/src/main/java/speiger/src/collections/doubles/sets/DoubleRBTreeSet.java b/src/main/java/speiger/src/collections/doubles/sets/DoubleRBTreeSet.java index 4d2f642..47cde1d 100644 --- a/src/main/java/speiger/src/collections/doubles/sets/DoubleRBTreeSet.java +++ b/src/main/java/speiger/src/collections/doubles/sets/DoubleRBTreeSet.java @@ -3,6 +3,7 @@ package speiger.src.collections.doubles.sets; import java.util.Collection; import java.util.Collections; import java.util.OptionalDouble; +import java.util.stream.DoubleStream; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; @@ -183,6 +184,15 @@ public class DoubleRBTreeSet extends AbstractDoubleSet implements DoubleNavigabl while(iterator.hasNext()) add(iterator.nextDouble()); } + + /** + * Collects a Stream to a RBTreeSet + * @return a set with the contents of the Stream + */ + public static DoubleRBTreeSet toSet(DoubleStream stream) { + return stream.collect(DoubleRBTreeSet::new, DoubleRBTreeSet::add, DoubleRBTreeSet::addAll); + } + @Override public void setDefaultMaxValue(double value) { defaultMaxNotFound = value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/utils/DoubleAsyncBuilder.java b/src/main/java/speiger/src/collections/doubles/utils/DoubleAsyncBuilder.java index 74a57d9..844bd1d 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/DoubleAsyncBuilder.java +++ b/src/main/java/speiger/src/collections/doubles/utils/DoubleAsyncBuilder.java @@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.LockSupport; import java.util.function.Consumer; +import java.util.OptionalDouble; import speiger.src.collections.doubles.functions.DoubleConsumer; import speiger.src.collections.doubles.functions.DoubleComparator; @@ -210,9 +211,8 @@ public class DoubleAsyncBuilder * @param operator that reduces the elements. * @return self with the reduce action applied */ - public DoubleAsyncBuilder reduce(DoubleDoubleUnaryOperator operator) { - task = new SimpleReduceTask(iterable.iterator(), operator); - return this; + public ObjectAsyncBuilder reduce(DoubleDoubleUnaryOperator operator) { + return new ObjectAsyncBuilder<>(new SimpleReduceTask(iterable.iterator(), operator)); } /** @@ -292,9 +292,8 @@ public class DoubleAsyncBuilder * @param filter that decides the desired elements * @return self with the findFirst function applied */ - public DoubleAsyncBuilder findFirst(DoublePredicate filter) { - task = new FindFirstTask(iterable.iterator(), filter); - return this; + public ObjectAsyncBuilder findFirst(DoublePredicate filter) { + return new ObjectAsyncBuilder<>(new FindFirstTask(iterable.iterator(), filter)); } /** @@ -404,7 +403,7 @@ public class DoubleAsyncBuilder } } - private static class SimpleReduceTask extends BaseDoubleTask + private static class SimpleReduceTask extends BaseObjectTask { DoubleIterator iter; DoubleDoubleUnaryOperator operator; @@ -414,6 +413,7 @@ public class DoubleAsyncBuilder public SimpleReduceTask(DoubleIterator iter, DoubleDoubleUnaryOperator operator) { this.iter = iter; this.operator = operator; + this.setResult(OptionalDouble.empty()); } @Override @@ -428,7 +428,7 @@ public class DoubleAsyncBuilder } } if(!iter.hasNext()) { - setResult(value); + setResult(OptionalDouble.of(value)); return true; } return false; @@ -498,7 +498,7 @@ public class DoubleAsyncBuilder } } - private static class FindFirstTask extends BaseDoubleTask + private static class FindFirstTask extends BaseObjectTask { DoubleIterator iter; DoublePredicate filter; @@ -506,6 +506,7 @@ public class DoubleAsyncBuilder public FindFirstTask(DoubleIterator iter, DoublePredicate filter) { this.iter = iter; this.filter = filter; + this.setResult(OptionalDouble.empty()); } @Override @@ -513,7 +514,7 @@ public class DoubleAsyncBuilder while(shouldRun() && iter.hasNext()) { double entry = iter.nextDouble(); if(filter.test(iter.nextDouble())) { - setResult(entry); + setResult(OptionalDouble.of(entry)); return true; } } diff --git a/src/main/java/speiger/src/collections/doubles/utils/DoubleCollections.java b/src/main/java/speiger/src/collections/doubles/utils/DoubleCollections.java index 5b1185a..6719ef4 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/DoubleCollections.java +++ b/src/main/java/speiger/src/collections/doubles/utils/DoubleCollections.java @@ -108,7 +108,10 @@ public class DoubleCollections return new SingletonCollection(element); } - protected static CollectionWrapper wrapper() { + /** + * Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed. + */ + public static CollectionWrapper wrapper() { return new CollectionWrapper(); } diff --git a/src/main/java/speiger/src/collections/floats/lists/CopyOnWriteFloatArrayList.java b/src/main/java/speiger/src/collections/floats/lists/CopyOnWriteFloatArrayList.java index 4f9ea5c..b0e2ba2 100644 --- a/src/main/java/speiger/src/collections/floats/lists/CopyOnWriteFloatArrayList.java +++ b/src/main/java/speiger/src/collections/floats/lists/CopyOnWriteFloatArrayList.java @@ -111,7 +111,6 @@ public class CopyOnWriteFloatArrayList extends AbstractFloatList implements ITri System.arraycopy(a, offset, data, 0, length); } - private void setArray(float[] data) { this.data = data; } diff --git a/src/main/java/speiger/src/collections/floats/lists/ImmutableFloatList.java b/src/main/java/speiger/src/collections/floats/lists/ImmutableFloatList.java index 7b2e70a..ec0613d 100644 --- a/src/main/java/speiger/src/collections/floats/lists/ImmutableFloatList.java +++ b/src/main/java/speiger/src/collections/floats/lists/ImmutableFloatList.java @@ -1,12 +1,15 @@ package speiger.src.collections.floats.lists; import java.util.Arrays; +import java.util.stream.DoubleStream; +import java.util.stream.StreamSupport; import java.util.Collection; import java.util.NoSuchElementException; import java.util.Objects; import java.util.function.Predicate; import java.util.function.UnaryOperator; -import java.util.function.DoublePredicate;import java.util.function.DoubleUnaryOperator; +import java.util.function.DoublePredicate; +import java.util.function.DoubleUnaryOperator; import speiger.src.collections.floats.collections.FloatCollection; import speiger.src.collections.floats.functions.FloatComparator; @@ -18,8 +21,6 @@ import speiger.src.collections.floats.functions.function.FloatPredicate; import speiger.src.collections.floats.functions.function.FloatFloatUnaryOperator; import speiger.src.collections.objects.utils.ObjectArrays; import speiger.src.collections.floats.utils.FloatIterators; -import java.util.stream.DoubleStream; -import java.util.stream.StreamSupport; import speiger.src.collections.floats.collections.FloatSplititerator; import speiger.src.collections.floats.utils.FloatSplititerators; import speiger.src.collections.utils.SanityChecks; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2BooleanLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2BooleanLinkedOpenCustomHashMap.java index 2a75b46..87d57b5 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2BooleanLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2BooleanLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto if(isEmpty() || strategy.equals(firstFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto if(isEmpty() || strategy.equals(lastFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto public boolean getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto public boolean getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Float2BooleanLinkedOpenCustomHashMap extends Float2BooleanOpenCusto firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ByteLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ByteLinkedOpenCustomHashMap.java index 311deea..b54d428 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ByteLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ByteLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM if(isEmpty() || strategy.equals(firstFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM if(isEmpty() || strategy.equals(lastFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM public byte getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM public byte getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Float2ByteLinkedOpenCustomHashMap extends Float2ByteOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2CharLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2CharLinkedOpenCustomHashMap.java index 37e629f..5bf60ae 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2CharLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2CharLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM if(isEmpty() || strategy.equals(firstFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM if(isEmpty() || strategy.equals(lastFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM public char getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM public char getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Float2CharLinkedOpenCustomHashMap extends Float2CharOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2DoubleLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2DoubleLinkedOpenCustomHashMap.java index 5ce21e8..7c1efda 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2DoubleLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2DoubleLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH if(isEmpty() || strategy.equals(firstFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH if(isEmpty() || strategy.equals(lastFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH public double getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH public double getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Float2DoubleLinkedOpenCustomHashMap extends Float2DoubleOpenCustomH firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2FloatLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2FloatLinkedOpenCustomHashMap.java index 17ac779..148fc56 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2FloatLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2FloatLinkedOpenCustomHashMap.java @@ -191,13 +191,13 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -205,7 +205,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -213,7 +213,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -225,13 +225,13 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -239,7 +239,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -247,7 +247,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -260,7 +260,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -271,7 +271,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -284,7 +284,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -295,7 +295,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -306,7 +306,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas if(isEmpty() || strategy.equals(firstFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -314,7 +314,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas if(isEmpty() || strategy.equals(lastFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -336,7 +336,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -349,7 +349,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas public float getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -357,7 +357,7 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas public float getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -533,8 +533,8 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -551,8 +551,8 @@ public class Float2FloatLinkedOpenCustomHashMap extends Float2FloatOpenCustomHas firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2IntLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2IntLinkedOpenCustomHashMap.java index 6788e1d..79b4466 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2IntLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2IntLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap if(isEmpty() || strategy.equals(firstFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap if(isEmpty() || strategy.equals(lastFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap public int getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap public int getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Float2IntLinkedOpenCustomHashMap extends Float2IntOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2LongLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2LongLinkedOpenCustomHashMap.java index f722798..3e36cf0 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2LongLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2LongLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM if(isEmpty() || strategy.equals(firstFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM if(isEmpty() || strategy.equals(lastFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM public long getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM public long getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Float2LongLinkedOpenCustomHashMap extends Float2LongOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ObjectLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ObjectLinkedOpenCustomHashMap.java index fc480b5..09710f7 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ObjectLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ObjectLinkedOpenCustomHashMap.java @@ -193,13 +193,13 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -207,7 +207,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -215,7 +215,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -227,13 +227,13 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -241,7 +241,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -249,7 +249,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -262,7 +262,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -273,7 +273,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -286,7 +286,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -297,7 +297,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -308,7 +308,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust if(isEmpty() || strategy.equals(firstFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -316,7 +316,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -330,7 +330,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust if(isEmpty() || strategy.equals(lastFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -338,7 +338,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -351,7 +351,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust public V getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -359,7 +359,7 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust public V getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -535,8 +535,8 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -553,8 +553,8 @@ public class Float2ObjectLinkedOpenCustomHashMap extends Float2ObjectOpenCust firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ShortLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ShortLinkedOpenCustomHashMap.java index edc2daa..6bd0878 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ShortLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ShortLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas if(isEmpty() || strategy.equals(firstFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas if(isEmpty() || strategy.equals(lastFloatKey(), key)) return false; if(strategy.equals(key, 0F)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0F)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas public short getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas public short getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Float2ShortLinkedOpenCustomHashMap extends Float2ShortOpenCustomHas firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2BooleanLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2BooleanLinkedOpenHashMap.java index 60240a7..e506012 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2BooleanLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2BooleanLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp if(isEmpty() || Float.floatToIntBits(firstFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp if(isEmpty() || Float.floatToIntBits(lastFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp public boolean getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp public boolean getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Float2BooleanLinkedOpenHashMap extends Float2BooleanOpenHashMap imp firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ByteLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ByteLinkedOpenHashMap.java index 4c48c90..86022f9 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ByteLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ByteLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement if(isEmpty() || Float.floatToIntBits(firstFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement if(isEmpty() || Float.floatToIntBits(lastFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement public byte getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement public byte getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Float2ByteLinkedOpenHashMap extends Float2ByteOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2CharLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2CharLinkedOpenHashMap.java index e097e61..93c06da 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2CharLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2CharLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement if(isEmpty() || Float.floatToIntBits(firstFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement if(isEmpty() || Float.floatToIntBits(lastFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement public char getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement public char getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Float2CharLinkedOpenHashMap extends Float2CharOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2DoubleLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2DoubleLinkedOpenHashMap.java index d672c95..b8d81e7 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2DoubleLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2DoubleLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple if(isEmpty() || Float.floatToIntBits(firstFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple if(isEmpty() || Float.floatToIntBits(lastFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple public double getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple public double getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Float2DoubleLinkedOpenHashMap extends Float2DoubleOpenHashMap imple firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2FloatLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2FloatLinkedOpenHashMap.java index a8d9423..6271004 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2FloatLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2FloatLinkedOpenHashMap.java @@ -168,13 +168,13 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -182,7 +182,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -190,7 +190,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -202,13 +202,13 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -216,7 +216,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -224,7 +224,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -237,7 +237,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -248,7 +248,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -261,7 +261,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -272,7 +272,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -283,7 +283,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme if(isEmpty() || Float.floatToIntBits(firstFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -291,7 +291,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -305,7 +305,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme if(isEmpty() || Float.floatToIntBits(lastFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -313,7 +313,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme public float getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -334,7 +334,7 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme public float getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Float2FloatLinkedOpenHashMap extends Float2FloatOpenHashMap impleme firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2IntLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2IntLinkedOpenHashMap.java index 9a6a3d9..f796185 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2IntLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2IntLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements if(isEmpty() || Float.floatToIntBits(firstFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements if(isEmpty() || Float.floatToIntBits(lastFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements public int getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements public int getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Float2IntLinkedOpenHashMap extends Float2IntOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2LongLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2LongLinkedOpenHashMap.java index daaad8e..a7e0ac5 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2LongLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2LongLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement if(isEmpty() || Float.floatToIntBits(firstFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement if(isEmpty() || Float.floatToIntBits(lastFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement public long getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement public long getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Float2LongLinkedOpenHashMap extends Float2LongOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ObjectLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ObjectLinkedOpenHashMap.java index 28340bc..353d912 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ObjectLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ObjectLinkedOpenHashMap.java @@ -170,13 +170,13 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -184,7 +184,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -192,7 +192,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -204,13 +204,13 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -218,7 +218,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -226,7 +226,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -239,7 +239,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -250,7 +250,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -263,7 +263,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -274,7 +274,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -285,7 +285,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap if(isEmpty() || Float.floatToIntBits(firstFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -293,7 +293,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -307,7 +307,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap if(isEmpty() || Float.floatToIntBits(lastFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -315,7 +315,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap public V getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -336,7 +336,7 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap public V getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -522,8 +522,8 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -540,8 +540,8 @@ public class Float2ObjectLinkedOpenHashMap extends Float2ObjectOpenHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ShortLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ShortLinkedOpenHashMap.java index 203f861..1f52c73 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ShortLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ShortLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Float.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme if(isEmpty() || Float.floatToIntBits(firstFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme if(isEmpty() || Float.floatToIntBits(lastFloatKey()) == Float.floatToIntBits(key)) return false; if(Float.floatToIntBits(key) == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme int pos = HashUtil.mix(Float.hashCode(key)) & mask; while(Float.floatToIntBits(keys[pos]) != 0) { if(Float.floatToIntBits(keys[pos]) == Float.floatToIntBits(key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme public short getAndMoveToFirst(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme public short getAndMoveToLast(float key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Float2ShortLinkedOpenHashMap extends Float2ShortOpenHashMap impleme firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/floats/queues/FloatArrayPriorityQueue.java b/src/main/java/speiger/src/collections/floats/queues/FloatArrayPriorityQueue.java index 6a317f3..e006d9d 100644 --- a/src/main/java/speiger/src/collections/floats/queues/FloatArrayPriorityQueue.java +++ b/src/main/java/speiger/src/collections/floats/queues/FloatArrayPriorityQueue.java @@ -174,7 +174,6 @@ public class FloatArrayPriorityQueue extends AbstractFloatPriorityQueue queue.size = size; return queue; } - @Override public void enqueue(float e) { if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (long)(array.length >> 1), (long)SanityChecks.MAX_ARRAY_SIZE), size+1)); diff --git a/src/main/java/speiger/src/collections/floats/sets/FloatArraySet.java b/src/main/java/speiger/src/collections/floats/sets/FloatArraySet.java index 2781500..a5b4022 100644 --- a/src/main/java/speiger/src/collections/floats/sets/FloatArraySet.java +++ b/src/main/java/speiger/src/collections/floats/sets/FloatArraySet.java @@ -55,7 +55,7 @@ public class FloatArraySet extends AbstractFloatSet implements FloatOrderedSet * @param array the array that should be used for set. */ public FloatArraySet(float[] array) { - this(array, array.length); + this(array, 0, array.length); } /** @@ -69,6 +69,18 @@ public class FloatArraySet extends AbstractFloatSet implements FloatOrderedSet addAll(array, length); } + /** + * Constructur using initial Array + * @param array the array that should be used for set. + * @param offset the starting offset of where the array should be copied from + * @param length the amount of elements present within the array + * @throws NegativeArraySizeException if the length is negative + */ + public FloatArraySet(float[] array, int offset, int length) { + this(length); + addAll(array, offset, length); + } + /** * A Helper constructor that allows to create a Set with exactly the same values as the provided collection. * @param c the elements that should be added to the set. diff --git a/src/main/java/speiger/src/collections/floats/utils/FloatAsyncBuilder.java b/src/main/java/speiger/src/collections/floats/utils/FloatAsyncBuilder.java index 82a4e20..30d7b3a 100644 --- a/src/main/java/speiger/src/collections/floats/utils/FloatAsyncBuilder.java +++ b/src/main/java/speiger/src/collections/floats/utils/FloatAsyncBuilder.java @@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.LockSupport; import java.util.function.Consumer; +import speiger.src.collections.floats.functions.OptionalFloat; import speiger.src.collections.floats.functions.FloatConsumer; import speiger.src.collections.floats.functions.FloatComparator; @@ -210,9 +211,8 @@ public class FloatAsyncBuilder * @param operator that reduces the elements. * @return self with the reduce action applied */ - public FloatAsyncBuilder reduce(FloatFloatUnaryOperator operator) { - task = new SimpleReduceTask(iterable.iterator(), operator); - return this; + public ObjectAsyncBuilder reduce(FloatFloatUnaryOperator operator) { + return new ObjectAsyncBuilder<>(new SimpleReduceTask(iterable.iterator(), operator)); } /** @@ -292,9 +292,8 @@ public class FloatAsyncBuilder * @param filter that decides the desired elements * @return self with the findFirst function applied */ - public FloatAsyncBuilder findFirst(FloatPredicate filter) { - task = new FindFirstTask(iterable.iterator(), filter); - return this; + public ObjectAsyncBuilder findFirst(FloatPredicate filter) { + return new ObjectAsyncBuilder<>(new FindFirstTask(iterable.iterator(), filter)); } /** @@ -404,7 +403,7 @@ public class FloatAsyncBuilder } } - private static class SimpleReduceTask extends BaseFloatTask + private static class SimpleReduceTask extends BaseObjectTask { FloatIterator iter; FloatFloatUnaryOperator operator; @@ -414,6 +413,7 @@ public class FloatAsyncBuilder public SimpleReduceTask(FloatIterator iter, FloatFloatUnaryOperator operator) { this.iter = iter; this.operator = operator; + this.setResult(OptionalFloat.empty()); } @Override @@ -428,7 +428,7 @@ public class FloatAsyncBuilder } } if(!iter.hasNext()) { - setResult(value); + setResult(OptionalFloat.of(value)); return true; } return false; @@ -498,7 +498,7 @@ public class FloatAsyncBuilder } } - private static class FindFirstTask extends BaseFloatTask + private static class FindFirstTask extends BaseObjectTask { FloatIterator iter; FloatPredicate filter; @@ -506,6 +506,7 @@ public class FloatAsyncBuilder public FindFirstTask(FloatIterator iter, FloatPredicate filter) { this.iter = iter; this.filter = filter; + this.setResult(OptionalFloat.empty()); } @Override @@ -513,7 +514,7 @@ public class FloatAsyncBuilder while(shouldRun() && iter.hasNext()) { float entry = iter.nextFloat(); if(filter.test(iter.nextFloat())) { - setResult(entry); + setResult(OptionalFloat.of(entry)); return true; } } diff --git a/src/main/java/speiger/src/collections/floats/utils/FloatCollections.java b/src/main/java/speiger/src/collections/floats/utils/FloatCollections.java index f6ee3db..b6316ac 100644 --- a/src/main/java/speiger/src/collections/floats/utils/FloatCollections.java +++ b/src/main/java/speiger/src/collections/floats/utils/FloatCollections.java @@ -109,7 +109,10 @@ public class FloatCollections return new SingletonCollection(element); } - protected static CollectionWrapper wrapper() { + /** + * Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed. + */ + public static CollectionWrapper wrapper() { return new CollectionWrapper(); } diff --git a/src/main/java/speiger/src/collections/ints/lists/CopyOnWriteIntArrayList.java b/src/main/java/speiger/src/collections/ints/lists/CopyOnWriteIntArrayList.java index 29138fe..bca646e 100644 --- a/src/main/java/speiger/src/collections/ints/lists/CopyOnWriteIntArrayList.java +++ b/src/main/java/speiger/src/collections/ints/lists/CopyOnWriteIntArrayList.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalInt; + import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; import java.util.function.Supplier; @@ -111,6 +112,14 @@ public class CopyOnWriteIntArrayList extends AbstractIntList implements ITrimmab System.arraycopy(a, offset, data, 0, length); } + + /** + * Collects a Stream to a CopyOnWriteArrayList + * @return a list with the contents of the Stream + */ + public static CopyOnWriteIntArrayList toList(IntStream stream) { + return stream.collect(CopyOnWriteIntArrayList::new, CopyOnWriteIntArrayList::add, CopyOnWriteIntArrayList::addAll); + } private void setArray(int[] data) { this.data = data; diff --git a/src/main/java/speiger/src/collections/ints/lists/ImmutableIntList.java b/src/main/java/speiger/src/collections/ints/lists/ImmutableIntList.java index 5ff6032..37e22b6 100644 --- a/src/main/java/speiger/src/collections/ints/lists/ImmutableIntList.java +++ b/src/main/java/speiger/src/collections/ints/lists/ImmutableIntList.java @@ -1,13 +1,18 @@ package speiger.src.collections.ints.lists; import java.util.Arrays; +import java.util.stream.IntStream; +import java.util.stream.StreamSupport; import java.util.Collection; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalInt; +import java.util.function.Supplier; +import speiger.src.collections.ints.utils.IntCollections; import java.util.function.Predicate; import java.util.function.UnaryOperator; import java.util.function.IntPredicate; + import java.util.function.IntUnaryOperator; import speiger.src.collections.ints.collections.IntCollection; @@ -18,8 +23,6 @@ import speiger.src.collections.objects.functions.consumer.ObjectIntConsumer; import speiger.src.collections.ints.functions.function.IntIntUnaryOperator; import speiger.src.collections.objects.utils.ObjectArrays; import speiger.src.collections.ints.utils.IntIterators; -import java.util.stream.IntStream; -import java.util.stream.StreamSupport; import speiger.src.collections.ints.collections.IntSplititerator; import speiger.src.collections.ints.utils.IntSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -89,6 +92,15 @@ public class ImmutableIntList extends AbstractIntList data = Arrays.copyOfRange(a, offset, offset+length); } + + /** + * Collects a Stream to a ImmutableList + * @return a list with the contents of the Stream + */ + public static ImmutableIntList toList(IntStream stream) { + return new ImmutableIntList(stream.collect((Supplier)IntCollections::wrapper, IntCollection::add, IntCollection::addAll).toIntArray()); + } + @Override public boolean add(int e) { throw new UnsupportedOperationException(); } @Override diff --git a/src/main/java/speiger/src/collections/ints/lists/IntArrayList.java b/src/main/java/speiger/src/collections/ints/lists/IntArrayList.java index 3492d8d..f6497dd 100644 --- a/src/main/java/speiger/src/collections/ints/lists/IntArrayList.java +++ b/src/main/java/speiger/src/collections/ints/lists/IntArrayList.java @@ -5,6 +5,8 @@ import java.util.Collection; import java.util.Iterator; import java.util.Objects; import java.util.OptionalInt; + + import java.util.function.IntPredicate; import java.util.function.Predicate; import java.util.function.UnaryOperator; @@ -144,6 +146,15 @@ public class IntArrayList extends AbstractIntList implements IIntArray, IntStack return list; } + + /** + * Collects a Stream to a ArrayList + * @return a list with the contents of the Stream + */ + public static IntArrayList toList(IntStream stream) { + return stream.collect(IntArrayList::new, IntArrayList::add, IntArrayList::addAll); + } + /** * Appends the specified element to the end of this list. * diff --git a/src/main/java/speiger/src/collections/ints/lists/IntLinkedList.java b/src/main/java/speiger/src/collections/ints/lists/IntLinkedList.java index 0ad5faa..977a4eb 100644 --- a/src/main/java/speiger/src/collections/ints/lists/IntLinkedList.java +++ b/src/main/java/speiger/src/collections/ints/lists/IntLinkedList.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.Objects; import java.util.OptionalInt; + import java.util.NoSuchElementException; import java.util.Spliterator; import java.util.Spliterator.OfInt; @@ -103,6 +104,15 @@ public class IntLinkedList extends AbstractIntList implements IntPriorityDequeue for(int i = offset,m=offset+length;i= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -232,13 +232,13 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -254,7 +254,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -267,7 +267,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -278,7 +278,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -302,7 +302,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -313,7 +313,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas if(isEmpty() || strategy.equals(firstIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -335,7 +335,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas if(isEmpty() || strategy.equals(lastIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -343,7 +343,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -356,7 +356,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas public boolean getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -364,7 +364,7 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas public boolean getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -540,8 +540,8 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -558,8 +558,8 @@ public class Int2BooleanLinkedOpenCustomHashMap extends Int2BooleanOpenCustomHas firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ByteLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ByteLinkedOpenCustomHashMap.java index 69ebfcd..0a256a8 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ByteLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ByteLinkedOpenCustomHashMap.java @@ -198,13 +198,13 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -212,7 +212,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -220,7 +220,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -232,13 +232,13 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -254,7 +254,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -267,7 +267,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -278,7 +278,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -302,7 +302,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -313,7 +313,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i if(isEmpty() || strategy.equals(firstIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -335,7 +335,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i if(isEmpty() || strategy.equals(lastIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -343,7 +343,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -356,7 +356,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i public byte getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -364,7 +364,7 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i public byte getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -540,8 +540,8 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -558,8 +558,8 @@ public class Int2ByteLinkedOpenCustomHashMap extends Int2ByteOpenCustomHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2CharLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2CharLinkedOpenCustomHashMap.java index 01e2af5..1bcdee8 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2CharLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2CharLinkedOpenCustomHashMap.java @@ -198,13 +198,13 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -212,7 +212,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -220,7 +220,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -232,13 +232,13 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -254,7 +254,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -267,7 +267,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -278,7 +278,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -302,7 +302,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -313,7 +313,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i if(isEmpty() || strategy.equals(firstIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -335,7 +335,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i if(isEmpty() || strategy.equals(lastIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -343,7 +343,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -356,7 +356,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i public char getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -364,7 +364,7 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i public char getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -540,8 +540,8 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -558,8 +558,8 @@ public class Int2CharLinkedOpenCustomHashMap extends Int2CharOpenCustomHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2DoubleLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2DoubleLinkedOpenCustomHashMap.java index fb0e16d..dc450eb 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2DoubleLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2DoubleLinkedOpenCustomHashMap.java @@ -198,13 +198,13 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -212,7 +212,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -220,7 +220,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -232,13 +232,13 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -254,7 +254,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -267,7 +267,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -278,7 +278,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -302,7 +302,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -313,7 +313,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM if(isEmpty() || strategy.equals(firstIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -335,7 +335,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM if(isEmpty() || strategy.equals(lastIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -343,7 +343,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -356,7 +356,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM public double getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -364,7 +364,7 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM public double getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -540,8 +540,8 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -558,8 +558,8 @@ public class Int2DoubleLinkedOpenCustomHashMap extends Int2DoubleOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2FloatLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2FloatLinkedOpenCustomHashMap.java index 105654f..754fafa 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2FloatLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2FloatLinkedOpenCustomHashMap.java @@ -198,13 +198,13 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -212,7 +212,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -220,7 +220,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -232,13 +232,13 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -254,7 +254,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -267,7 +267,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -278,7 +278,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -302,7 +302,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -313,7 +313,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap if(isEmpty() || strategy.equals(firstIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -335,7 +335,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap if(isEmpty() || strategy.equals(lastIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -343,7 +343,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -356,7 +356,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap public float getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -364,7 +364,7 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap public float getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -540,8 +540,8 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -558,8 +558,8 @@ public class Int2FloatLinkedOpenCustomHashMap extends Int2FloatOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2IntLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2IntLinkedOpenCustomHashMap.java index 0573228..5bc39b4 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2IntLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2IntLinkedOpenCustomHashMap.java @@ -190,13 +190,13 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -204,7 +204,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -212,7 +212,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -224,13 +224,13 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -238,7 +238,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -246,7 +246,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -259,7 +259,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -270,7 +270,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -283,7 +283,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -294,7 +294,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -305,7 +305,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp if(isEmpty() || strategy.equals(firstIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -313,7 +313,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -327,7 +327,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp if(isEmpty() || strategy.equals(lastIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -335,7 +335,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -348,7 +348,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp public int getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -356,7 +356,7 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp public int getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -532,8 +532,8 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -550,8 +550,8 @@ public class Int2IntLinkedOpenCustomHashMap extends Int2IntOpenCustomHashMap imp firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2LongLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2LongLinkedOpenCustomHashMap.java index 71cfaa0..2b0da1a 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2LongLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2LongLinkedOpenCustomHashMap.java @@ -198,13 +198,13 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -212,7 +212,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -220,7 +220,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -232,13 +232,13 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -254,7 +254,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -267,7 +267,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -278,7 +278,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -302,7 +302,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -313,7 +313,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i if(isEmpty() || strategy.equals(firstIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -335,7 +335,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i if(isEmpty() || strategy.equals(lastIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -343,7 +343,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -356,7 +356,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i public long getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -364,7 +364,7 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i public long getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -540,8 +540,8 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -558,8 +558,8 @@ public class Int2LongLinkedOpenCustomHashMap extends Int2LongOpenCustomHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ObjectLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ObjectLinkedOpenCustomHashMap.java index f3c34bd..605a9fc 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ObjectLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ObjectLinkedOpenCustomHashMap.java @@ -192,13 +192,13 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -206,7 +206,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -214,7 +214,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -226,13 +226,13 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -240,7 +240,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -248,7 +248,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -261,7 +261,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -272,7 +272,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -285,7 +285,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -296,7 +296,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -307,7 +307,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa if(isEmpty() || strategy.equals(firstIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -315,7 +315,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -329,7 +329,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa if(isEmpty() || strategy.equals(lastIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -337,7 +337,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -350,7 +350,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa public V getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -358,7 +358,7 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa public V getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -534,8 +534,8 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -552,8 +552,8 @@ public class Int2ObjectLinkedOpenCustomHashMap extends Int2ObjectOpenCustomHa firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ShortLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ShortLinkedOpenCustomHashMap.java index 035c8b8..ecdc5c3 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ShortLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ShortLinkedOpenCustomHashMap.java @@ -198,13 +198,13 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -212,7 +212,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -220,7 +220,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -232,13 +232,13 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -254,7 +254,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -267,7 +267,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -278,7 +278,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -302,7 +302,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -313,7 +313,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap if(isEmpty() || strategy.equals(firstIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -335,7 +335,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap if(isEmpty() || strategy.equals(lastIntKey(), key)) return false; if(strategy.equals(key, 0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -343,7 +343,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -356,7 +356,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap public short getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -364,7 +364,7 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap public short getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -540,8 +540,8 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -558,8 +558,8 @@ public class Int2ShortLinkedOpenCustomHashMap extends Int2ShortOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2BooleanLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2BooleanLinkedOpenHashMap.java index aca93b9..fe01f95 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2BooleanLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2BooleanLinkedOpenHashMap.java @@ -175,13 +175,13 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -189,7 +189,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme if(keys[pos] == key) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -197,7 +197,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -209,13 +209,13 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -223,7 +223,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme if(keys[pos] == key) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -231,7 +231,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -244,7 +244,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -255,7 +255,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -290,7 +290,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme if(isEmpty() || firstIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -298,7 +298,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -312,7 +312,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme if(isEmpty() || lastIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -320,7 +320,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -333,7 +333,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme public boolean getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -341,7 +341,7 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme public boolean getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -538,8 +538,8 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -556,8 +556,8 @@ public class Int2BooleanLinkedOpenHashMap extends Int2BooleanOpenHashMap impleme firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ByteLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ByteLinkedOpenHashMap.java index 2fb2a52..ff242f9 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ByteLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ByteLinkedOpenHashMap.java @@ -175,13 +175,13 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -189,7 +189,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In if(keys[pos] == key) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -197,7 +197,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -209,13 +209,13 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -223,7 +223,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In if(keys[pos] == key) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -231,7 +231,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -244,7 +244,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -255,7 +255,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -290,7 +290,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In if(isEmpty() || firstIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -298,7 +298,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -312,7 +312,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In if(isEmpty() || lastIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -320,7 +320,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -333,7 +333,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In public byte getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -341,7 +341,7 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In public byte getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -538,8 +538,8 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -556,8 +556,8 @@ public class Int2ByteLinkedOpenHashMap extends Int2ByteOpenHashMap implements In firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2CharLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2CharLinkedOpenHashMap.java index 2c73ca7..96fdf0e 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2CharLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2CharLinkedOpenHashMap.java @@ -175,13 +175,13 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -189,7 +189,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In if(keys[pos] == key) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -197,7 +197,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -209,13 +209,13 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -223,7 +223,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In if(keys[pos] == key) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -231,7 +231,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -244,7 +244,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -255,7 +255,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -290,7 +290,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In if(isEmpty() || firstIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -298,7 +298,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -312,7 +312,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In if(isEmpty() || lastIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -320,7 +320,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -333,7 +333,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In public char getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -341,7 +341,7 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In public char getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -538,8 +538,8 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -556,8 +556,8 @@ public class Int2CharLinkedOpenHashMap extends Int2CharOpenHashMap implements In firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2DoubleLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2DoubleLinkedOpenHashMap.java index 69469a7..26cd007 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2DoubleLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2DoubleLinkedOpenHashMap.java @@ -175,13 +175,13 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -189,7 +189,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement if(keys[pos] == key) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -197,7 +197,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -209,13 +209,13 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -223,7 +223,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement if(keys[pos] == key) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -231,7 +231,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -244,7 +244,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -255,7 +255,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -290,7 +290,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement if(isEmpty() || firstIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -298,7 +298,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -312,7 +312,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement if(isEmpty() || lastIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -320,7 +320,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -333,7 +333,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement public double getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -341,7 +341,7 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement public double getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -538,8 +538,8 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -556,8 +556,8 @@ public class Int2DoubleLinkedOpenHashMap extends Int2DoubleOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2FloatLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2FloatLinkedOpenHashMap.java index 6b4026c..4b254a3 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2FloatLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2FloatLinkedOpenHashMap.java @@ -175,13 +175,13 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -189,7 +189,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements if(keys[pos] == key) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -197,7 +197,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -209,13 +209,13 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -223,7 +223,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements if(keys[pos] == key) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -231,7 +231,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -244,7 +244,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -255,7 +255,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -290,7 +290,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements if(isEmpty() || firstIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -298,7 +298,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -312,7 +312,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements if(isEmpty() || lastIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -320,7 +320,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -333,7 +333,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements public float getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -341,7 +341,7 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements public float getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -538,8 +538,8 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -556,8 +556,8 @@ public class Int2FloatLinkedOpenHashMap extends Int2FloatOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2IntLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2IntLinkedOpenHashMap.java index 23355b9..b3bbd10 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2IntLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2IntLinkedOpenHashMap.java @@ -167,13 +167,13 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -181,7 +181,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 if(keys[pos] == key) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -189,7 +189,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -201,13 +201,13 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -215,7 +215,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 if(keys[pos] == key) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -223,7 +223,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -236,7 +236,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -260,7 +260,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -271,7 +271,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -282,7 +282,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 if(isEmpty() || firstIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -290,7 +290,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -304,7 +304,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 if(isEmpty() || lastIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -312,7 +312,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -325,7 +325,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 public int getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -333,7 +333,7 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 public int getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -530,8 +530,8 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -548,8 +548,8 @@ public class Int2IntLinkedOpenHashMap extends Int2IntOpenHashMap implements Int2 firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2LongLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2LongLinkedOpenHashMap.java index fccc010..b966e9f 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2LongLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2LongLinkedOpenHashMap.java @@ -175,13 +175,13 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -189,7 +189,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In if(keys[pos] == key) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -197,7 +197,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -209,13 +209,13 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -223,7 +223,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In if(keys[pos] == key) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -231,7 +231,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -244,7 +244,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -255,7 +255,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -290,7 +290,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In if(isEmpty() || firstIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -298,7 +298,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -312,7 +312,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In if(isEmpty() || lastIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -320,7 +320,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -333,7 +333,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In public long getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -341,7 +341,7 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In public long getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -538,8 +538,8 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -556,8 +556,8 @@ public class Int2LongLinkedOpenHashMap extends Int2LongOpenHashMap implements In firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ObjectLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ObjectLinkedOpenHashMap.java index 7361d81..23f77d1 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ObjectLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ObjectLinkedOpenHashMap.java @@ -169,13 +169,13 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -183,7 +183,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp if(keys[pos] == key) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -191,7 +191,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -203,13 +203,13 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -217,7 +217,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp if(keys[pos] == key) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -225,7 +225,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -238,7 +238,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -249,7 +249,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -262,7 +262,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -273,7 +273,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -284,7 +284,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp if(isEmpty() || firstIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -292,7 +292,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -306,7 +306,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp if(isEmpty() || lastIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -314,7 +314,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -327,7 +327,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp public V getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -335,7 +335,7 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp public V getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -521,8 +521,8 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -539,8 +539,8 @@ public class Int2ObjectLinkedOpenHashMap extends Int2ObjectOpenHashMap imp firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ShortLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ShortLinkedOpenHashMap.java index b0b6e53..9bbd306 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ShortLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ShortLinkedOpenHashMap.java @@ -175,13 +175,13 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -189,7 +189,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements if(keys[pos] == key) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -197,7 +197,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -209,13 +209,13 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -223,7 +223,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements if(keys[pos] == key) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -231,7 +231,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -244,7 +244,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -255,7 +255,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Integer.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -290,7 +290,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements if(isEmpty() || firstIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -298,7 +298,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -312,7 +312,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements if(isEmpty() || lastIntKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -320,7 +320,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements int pos = HashUtil.mix(Integer.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -333,7 +333,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements public short getAndMoveToFirst(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -341,7 +341,7 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements public short getAndMoveToLast(int key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -538,8 +538,8 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -556,8 +556,8 @@ public class Int2ShortLinkedOpenHashMap extends Int2ShortOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/ints/queues/IntArrayFIFOQueue.java b/src/main/java/speiger/src/collections/ints/queues/IntArrayFIFOQueue.java index 1345973..5e3f972 100644 --- a/src/main/java/speiger/src/collections/ints/queues/IntArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/ints/queues/IntArrayFIFOQueue.java @@ -3,6 +3,7 @@ package speiger.src.collections.ints.queues; import java.util.Arrays; import java.util.Objects; import java.util.OptionalInt; +import java.util.stream.IntStream; import java.util.NoSuchElementException; import java.util.function.IntPredicate; @@ -87,6 +88,20 @@ public class IntArrayFIFOQueue extends AbstractIntPriorityQueue implements IntPr this(MIN_CAPACITY); } + + /** + * Collects a Stream to a ArrayFIFOQueue + * @return a queue with the contents of the Stream + */ + public static IntArrayFIFOQueue toQueue(IntStream stream) { + return stream.collect(IntArrayFIFOQueue::new, IntArrayFIFOQueue::enqueue, IntArrayFIFOQueue::merge); + } + + private IntArrayFIFOQueue merge(IntArrayFIFOQueue a) { + enqueueAll(a.toIntArray()); + return this; + } + @Override public IntIterator iterator() { return new Iter(); diff --git a/src/main/java/speiger/src/collections/ints/queues/IntArrayPriorityQueue.java b/src/main/java/speiger/src/collections/ints/queues/IntArrayPriorityQueue.java index f8ad216..01b1cd5 100644 --- a/src/main/java/speiger/src/collections/ints/queues/IntArrayPriorityQueue.java +++ b/src/main/java/speiger/src/collections/ints/queues/IntArrayPriorityQueue.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalInt; +import java.util.stream.IntStream; import java.util.function.IntPredicate; import speiger.src.collections.ints.collections.IntCollection; @@ -174,6 +175,19 @@ public class IntArrayPriorityQueue extends AbstractIntPriorityQueue queue.size = size; return queue; } + + /** + * Collects a Stream to a ArrayPriorityQueue + * @return a queue with the contents of the Stream + */ + public static IntArrayPriorityQueue toQueue(IntStream stream) { + return stream.collect(IntArrayPriorityQueue::new, IntArrayPriorityQueue::enqueue, IntArrayPriorityQueue::merge); + } + + private IntArrayPriorityQueue merge(IntArrayPriorityQueue a) { + enqueueAll(a.toIntArray()); + return this; + } @Override public void enqueue(int e) { diff --git a/src/main/java/speiger/src/collections/ints/queues/IntHeapPriorityQueue.java b/src/main/java/speiger/src/collections/ints/queues/IntHeapPriorityQueue.java index 9a00fb4..4918f0c 100644 --- a/src/main/java/speiger/src/collections/ints/queues/IntHeapPriorityQueue.java +++ b/src/main/java/speiger/src/collections/ints/queues/IntHeapPriorityQueue.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalInt; +import java.util.stream.IntStream; import java.util.function.IntPredicate; import speiger.src.collections.ints.collections.IntCollection; @@ -177,6 +178,20 @@ public class IntHeapPriorityQueue extends AbstractIntPriorityQueue return queue; } + + /** + * Collects a Stream to a ArrayFIFOQueue + * @return a queue with the contents of the Stream + */ + public static IntHeapPriorityQueue toQueue(IntStream stream) { + return stream.collect(IntHeapPriorityQueue::new, IntHeapPriorityQueue::enqueue, IntHeapPriorityQueue::merge); + } + + private IntHeapPriorityQueue merge(IntHeapPriorityQueue a) { + enqueueAll(a.toIntArray()); + return this; + } + @Override public int size() { return size; diff --git a/src/main/java/speiger/src/collections/ints/sets/IntAVLTreeSet.java b/src/main/java/speiger/src/collections/ints/sets/IntAVLTreeSet.java index 1165de0..5418b1a 100644 --- a/src/main/java/speiger/src/collections/ints/sets/IntAVLTreeSet.java +++ b/src/main/java/speiger/src/collections/ints/sets/IntAVLTreeSet.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalInt; +import java.util.stream.IntStream; import java.util.function.IntPredicate; import speiger.src.collections.ints.collections.IntBidirectionalIterator; @@ -183,6 +184,15 @@ public class IntAVLTreeSet extends AbstractIntSet implements IntNavigableSet while(iterator.hasNext()) add(iterator.nextInt()); } + + /** + * Collects a Stream to a AVLTreeSet + * @return a set with the contents of the Stream + */ + public static IntAVLTreeSet toSet(IntStream stream) { + return stream.collect(IntAVLTreeSet::new, IntAVLTreeSet::add, IntAVLTreeSet::addAll); + } + @Override public void setDefaultMaxValue(int value) { defaultMaxNotFound = value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/sets/IntArraySet.java b/src/main/java/speiger/src/collections/ints/sets/IntArraySet.java index 4db28c0..bbb6add 100644 --- a/src/main/java/speiger/src/collections/ints/sets/IntArraySet.java +++ b/src/main/java/speiger/src/collections/ints/sets/IntArraySet.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalInt; +import java.util.stream.IntStream; import java.util.Set; import java.util.function.IntPredicate; import speiger.src.collections.ints.collections.IntBidirectionalIterator; @@ -54,7 +55,7 @@ public class IntArraySet extends AbstractIntSet implements IntOrderedSet * @param array the array that should be used for set. */ public IntArraySet(int[] array) { - this(array, array.length); + this(array, 0, array.length); } /** @@ -68,6 +69,18 @@ public class IntArraySet extends AbstractIntSet implements IntOrderedSet addAll(array, length); } + /** + * Constructur using initial Array + * @param array the array that should be used for set. + * @param offset the starting offset of where the array should be copied from + * @param length the amount of elements present within the array + * @throws NegativeArraySizeException if the length is negative + */ + public IntArraySet(int[] array, int offset, int length) { + this(length); + addAll(array, offset, length); + } + /** * A Helper constructor that allows to create a Set with exactly the same values as the provided collection. * @param c the elements that should be added to the set. @@ -111,6 +124,15 @@ public class IntArraySet extends AbstractIntSet implements IntOrderedSet for(IntIterator iter = s.iterator();iter.hasNext();data[size++] = iter.nextInt()); } + + /** + * Collects a Stream to a ArraySet + * @return a set with the contents of the Stream + */ + public static IntArraySet toList(IntStream stream) { + return stream.collect(IntArraySet::new, IntArraySet::add, IntArraySet::addAll); + } + @Override public boolean add(int o) { int index = findIndex(o); diff --git a/src/main/java/speiger/src/collections/ints/sets/IntLinkedOpenCustomHashSet.java b/src/main/java/speiger/src/collections/ints/sets/IntLinkedOpenCustomHashSet.java index 11c7c1b..ddeb725 100644 --- a/src/main/java/speiger/src/collections/ints/sets/IntLinkedOpenCustomHashSet.java +++ b/src/main/java/speiger/src/collections/ints/sets/IntLinkedOpenCustomHashSet.java @@ -6,6 +6,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.OptionalInt; +import java.util.stream.IntStream; import java.util.function.IntPredicate; import speiger.src.collections.ints.collections.IntCollection; @@ -215,6 +216,15 @@ public class IntLinkedOpenCustomHashSet extends IntOpenCustomHashSet implements while(iterator.hasNext()) add(iterator.nextInt()); } + + /** + * Collects a Stream to a LinkedCustomHashSet + * @return a set with the contents of the Stream + */ + public static IntLinkedOpenCustomHashSet toList(IntStream stream, IntStrategy strategy) { + return stream.collect(() -> new IntLinkedOpenCustomHashSet(strategy), IntLinkedOpenCustomHashSet::add, IntLinkedOpenCustomHashSet::addAll); + } + @Override public void addFirst(int o) { if(strategy.equals(o, 0)) { diff --git a/src/main/java/speiger/src/collections/ints/sets/IntLinkedOpenHashSet.java b/src/main/java/speiger/src/collections/ints/sets/IntLinkedOpenHashSet.java index 544d7f0..a8d1e33 100644 --- a/src/main/java/speiger/src/collections/ints/sets/IntLinkedOpenHashSet.java +++ b/src/main/java/speiger/src/collections/ints/sets/IntLinkedOpenHashSet.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalInt; +import java.util.stream.IntStream; import java.util.function.IntPredicate; import speiger.src.collections.ints.collections.IntCollection; @@ -184,6 +185,15 @@ public class IntLinkedOpenHashSet extends IntOpenHashSet implements IntOrderedSe while(iterator.hasNext()) add(iterator.nextInt()); } + + /** + * Collects a Stream to a LinkedHashSet + * @return a set with the contents of the Stream + */ + public static IntLinkedOpenHashSet toLinkedSet(IntStream stream) { + return stream.collect(IntLinkedOpenHashSet::new, IntLinkedOpenHashSet::add, IntLinkedOpenHashSet::addAll); + } + @Override public void addFirst(int o) { if(o == 0) { diff --git a/src/main/java/speiger/src/collections/ints/sets/IntOpenCustomHashSet.java b/src/main/java/speiger/src/collections/ints/sets/IntOpenCustomHashSet.java index c6a3191..23b4eb1 100644 --- a/src/main/java/speiger/src/collections/ints/sets/IntOpenCustomHashSet.java +++ b/src/main/java/speiger/src/collections/ints/sets/IntOpenCustomHashSet.java @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalInt; +import java.util.stream.IntStream; import java.util.function.IntPredicate; import speiger.src.collections.ints.collections.IntCollection; @@ -234,6 +235,15 @@ public class IntOpenCustomHashSet extends AbstractIntSet implements ITrimmable while(iterator.hasNext()) add(iterator.nextInt()); } + + /** + * Collects a Stream to a CustomHashSet + * @return a set with the contents of the Stream + */ + public static IntOpenCustomHashSet toSet(IntStream stream, IntStrategy strategy) { + return stream.collect(() -> new IntOpenCustomHashSet(strategy), IntOpenCustomHashSet::add, IntOpenCustomHashSet::addAll); + } + /** * Helper getter function to get the current strategy * @return the current strategy diff --git a/src/main/java/speiger/src/collections/ints/sets/IntOpenHashSet.java b/src/main/java/speiger/src/collections/ints/sets/IntOpenHashSet.java index 57f8e29..c2bbd41 100644 --- a/src/main/java/speiger/src/collections/ints/sets/IntOpenHashSet.java +++ b/src/main/java/speiger/src/collections/ints/sets/IntOpenHashSet.java @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalInt; +import java.util.stream.IntStream; import java.util.function.IntPredicate; import speiger.src.collections.ints.collections.IntCollection; @@ -201,6 +202,15 @@ public class IntOpenHashSet extends AbstractIntSet implements ITrimmable while(iterator.hasNext()) add(iterator.nextInt()); } + + /** + * Collects a Stream to a HashSet + * @return a set with the contents of the Stream + */ + public static IntOpenHashSet toSet(IntStream stream) { + return stream.collect(IntOpenHashSet::new, IntOpenHashSet::add, IntOpenHashSet::addAll); + } + @Override public boolean add(int o) { if(o == 0) { diff --git a/src/main/java/speiger/src/collections/ints/sets/IntRBTreeSet.java b/src/main/java/speiger/src/collections/ints/sets/IntRBTreeSet.java index 8fdc764..524c2af 100644 --- a/src/main/java/speiger/src/collections/ints/sets/IntRBTreeSet.java +++ b/src/main/java/speiger/src/collections/ints/sets/IntRBTreeSet.java @@ -3,6 +3,7 @@ package speiger.src.collections.ints.sets; import java.util.Collection; import java.util.Collections; import java.util.OptionalInt; +import java.util.stream.IntStream; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; @@ -183,6 +184,15 @@ public class IntRBTreeSet extends AbstractIntSet implements IntNavigableSet while(iterator.hasNext()) add(iterator.nextInt()); } + + /** + * Collects a Stream to a RBTreeSet + * @return a set with the contents of the Stream + */ + public static IntRBTreeSet toSet(IntStream stream) { + return stream.collect(IntRBTreeSet::new, IntRBTreeSet::add, IntRBTreeSet::addAll); + } + @Override public void setDefaultMaxValue(int value) { defaultMaxNotFound = value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/utils/IntAsyncBuilder.java b/src/main/java/speiger/src/collections/ints/utils/IntAsyncBuilder.java index e3b65b9..a399ad0 100644 --- a/src/main/java/speiger/src/collections/ints/utils/IntAsyncBuilder.java +++ b/src/main/java/speiger/src/collections/ints/utils/IntAsyncBuilder.java @@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.LockSupport; import java.util.function.Consumer; +import java.util.OptionalInt; import speiger.src.collections.ints.functions.IntConsumer; import speiger.src.collections.ints.functions.IntComparator; @@ -209,9 +210,8 @@ public class IntAsyncBuilder * @param operator that reduces the elements. * @return self with the reduce action applied */ - public IntAsyncBuilder reduce(IntIntUnaryOperator operator) { - task = new SimpleReduceTask(iterable.iterator(), operator); - return this; + public ObjectAsyncBuilder reduce(IntIntUnaryOperator operator) { + return new ObjectAsyncBuilder<>(new SimpleReduceTask(iterable.iterator(), operator)); } /** @@ -291,9 +291,8 @@ public class IntAsyncBuilder * @param filter that decides the desired elements * @return self with the findFirst function applied */ - public IntAsyncBuilder findFirst(IntPredicate filter) { - task = new FindFirstTask(iterable.iterator(), filter); - return this; + public ObjectAsyncBuilder findFirst(IntPredicate filter) { + return new ObjectAsyncBuilder<>(new FindFirstTask(iterable.iterator(), filter)); } /** @@ -403,7 +402,7 @@ public class IntAsyncBuilder } } - private static class SimpleReduceTask extends BaseIntTask + private static class SimpleReduceTask extends BaseObjectTask { IntIterator iter; IntIntUnaryOperator operator; @@ -413,6 +412,7 @@ public class IntAsyncBuilder public SimpleReduceTask(IntIterator iter, IntIntUnaryOperator operator) { this.iter = iter; this.operator = operator; + this.setResult(OptionalInt.empty()); } @Override @@ -427,7 +427,7 @@ public class IntAsyncBuilder } } if(!iter.hasNext()) { - setResult(value); + setResult(OptionalInt.of(value)); return true; } return false; @@ -497,7 +497,7 @@ public class IntAsyncBuilder } } - private static class FindFirstTask extends BaseIntTask + private static class FindFirstTask extends BaseObjectTask { IntIterator iter; IntPredicate filter; @@ -505,6 +505,7 @@ public class IntAsyncBuilder public FindFirstTask(IntIterator iter, IntPredicate filter) { this.iter = iter; this.filter = filter; + this.setResult(OptionalInt.empty()); } @Override @@ -512,7 +513,7 @@ public class IntAsyncBuilder while(shouldRun() && iter.hasNext()) { int entry = iter.nextInt(); if(filter.test(iter.nextInt())) { - setResult(entry); + setResult(OptionalInt.of(entry)); return true; } } diff --git a/src/main/java/speiger/src/collections/ints/utils/IntCollections.java b/src/main/java/speiger/src/collections/ints/utils/IntCollections.java index 1b09dcd..e8cc1d0 100644 --- a/src/main/java/speiger/src/collections/ints/utils/IntCollections.java +++ b/src/main/java/speiger/src/collections/ints/utils/IntCollections.java @@ -108,7 +108,10 @@ public class IntCollections return new SingletonCollection(element); } - protected static CollectionWrapper wrapper() { + /** + * Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed. + */ + public static CollectionWrapper wrapper() { return new CollectionWrapper(); } diff --git a/src/main/java/speiger/src/collections/longs/lists/CopyOnWriteLongArrayList.java b/src/main/java/speiger/src/collections/longs/lists/CopyOnWriteLongArrayList.java index ed11cbb..52ec58d 100644 --- a/src/main/java/speiger/src/collections/longs/lists/CopyOnWriteLongArrayList.java +++ b/src/main/java/speiger/src/collections/longs/lists/CopyOnWriteLongArrayList.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalLong; + import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; import java.util.function.Supplier; @@ -111,6 +112,14 @@ public class CopyOnWriteLongArrayList extends AbstractLongList implements ITrimm System.arraycopy(a, offset, data, 0, length); } + + /** + * Collects a Stream to a CopyOnWriteArrayList + * @return a list with the contents of the Stream + */ + public static CopyOnWriteLongArrayList toList(LongStream stream) { + return stream.collect(CopyOnWriteLongArrayList::new, CopyOnWriteLongArrayList::add, CopyOnWriteLongArrayList::addAll); + } private void setArray(long[] data) { this.data = data; diff --git a/src/main/java/speiger/src/collections/longs/lists/ImmutableLongList.java b/src/main/java/speiger/src/collections/longs/lists/ImmutableLongList.java index 4b04597..a72bada 100644 --- a/src/main/java/speiger/src/collections/longs/lists/ImmutableLongList.java +++ b/src/main/java/speiger/src/collections/longs/lists/ImmutableLongList.java @@ -1,13 +1,18 @@ package speiger.src.collections.longs.lists; import java.util.Arrays; +import java.util.stream.LongStream; +import java.util.stream.StreamSupport; import java.util.Collection; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalLong; +import java.util.function.Supplier; +import speiger.src.collections.longs.utils.LongCollections; import java.util.function.Predicate; import java.util.function.UnaryOperator; import java.util.function.LongPredicate; + import java.util.function.LongUnaryOperator; import speiger.src.collections.longs.collections.LongCollection; @@ -18,8 +23,6 @@ import speiger.src.collections.objects.functions.consumer.ObjectLongConsumer; import speiger.src.collections.longs.functions.function.LongLongUnaryOperator; import speiger.src.collections.objects.utils.ObjectArrays; import speiger.src.collections.longs.utils.LongIterators; -import java.util.stream.LongStream; -import java.util.stream.StreamSupport; import speiger.src.collections.longs.collections.LongSplititerator; import speiger.src.collections.longs.utils.LongSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -89,6 +92,15 @@ public class ImmutableLongList extends AbstractLongList data = Arrays.copyOfRange(a, offset, offset+length); } + + /** + * Collects a Stream to a ImmutableList + * @return a list with the contents of the Stream + */ + public static ImmutableLongList toList(LongStream stream) { + return new ImmutableLongList(stream.collect((Supplier)LongCollections::wrapper, LongCollection::add, LongCollection::addAll).toLongArray()); + } + @Override public boolean add(long e) { throw new UnsupportedOperationException(); } @Override diff --git a/src/main/java/speiger/src/collections/longs/lists/LongArrayList.java b/src/main/java/speiger/src/collections/longs/lists/LongArrayList.java index 09a8e23..ec56f3e 100644 --- a/src/main/java/speiger/src/collections/longs/lists/LongArrayList.java +++ b/src/main/java/speiger/src/collections/longs/lists/LongArrayList.java @@ -5,6 +5,8 @@ import java.util.Collection; import java.util.Iterator; import java.util.Objects; import java.util.OptionalLong; + + import java.util.function.LongPredicate; import java.util.function.Predicate; import java.util.function.UnaryOperator; @@ -144,6 +146,15 @@ public class LongArrayList extends AbstractLongList implements ILongArray, LongS return list; } + + /** + * Collects a Stream to a ArrayList + * @return a list with the contents of the Stream + */ + public static LongArrayList toList(LongStream stream) { + return stream.collect(LongArrayList::new, LongArrayList::add, LongArrayList::addAll); + } + /** * Appends the specified element to the end of this list. * diff --git a/src/main/java/speiger/src/collections/longs/lists/LongLinkedList.java b/src/main/java/speiger/src/collections/longs/lists/LongLinkedList.java index 0e0440a..4cc0748 100644 --- a/src/main/java/speiger/src/collections/longs/lists/LongLinkedList.java +++ b/src/main/java/speiger/src/collections/longs/lists/LongLinkedList.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.Objects; import java.util.OptionalLong; + import java.util.NoSuchElementException; import java.util.Spliterator; import java.util.Spliterator.OfLong; @@ -103,6 +104,15 @@ public class LongLinkedList extends AbstractLongList implements LongPriorityDequ for(int i = offset,m=offset+length;i= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH if(isEmpty() || strategy.equals(firstLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH if(isEmpty() || strategy.equals(lastLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH public boolean getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH public boolean getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Long2BooleanLinkedOpenCustomHashMap extends Long2BooleanOpenCustomH firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ByteLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ByteLinkedOpenCustomHashMap.java index cfdf90c..f702cc7 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ByteLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ByteLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap if(isEmpty() || strategy.equals(firstLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap if(isEmpty() || strategy.equals(lastLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap public byte getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap public byte getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Long2ByteLinkedOpenCustomHashMap extends Long2ByteOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2CharLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2CharLinkedOpenCustomHashMap.java index dee8e0c..024d814 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2CharLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2CharLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap if(isEmpty() || strategy.equals(firstLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap if(isEmpty() || strategy.equals(lastLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap public char getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap public char getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Long2CharLinkedOpenCustomHashMap extends Long2CharOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2DoubleLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2DoubleLinkedOpenCustomHashMap.java index c250292..aefd88d 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2DoubleLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2DoubleLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas if(isEmpty() || strategy.equals(firstLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas if(isEmpty() || strategy.equals(lastLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas public double getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas public double getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Long2DoubleLinkedOpenCustomHashMap extends Long2DoubleOpenCustomHas firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2FloatLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2FloatLinkedOpenCustomHashMap.java index d96b63b..562ef34 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2FloatLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2FloatLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM if(isEmpty() || strategy.equals(firstLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM if(isEmpty() || strategy.equals(lastLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM public float getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM public float getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Long2FloatLinkedOpenCustomHashMap extends Long2FloatOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2IntLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2IntLinkedOpenCustomHashMap.java index 8ca0a07..6e664ce 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2IntLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2IntLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i if(isEmpty() || strategy.equals(firstLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i if(isEmpty() || strategy.equals(lastLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i public int getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i public int getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Long2IntLinkedOpenCustomHashMap extends Long2IntOpenCustomHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2LongLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2LongLinkedOpenCustomHashMap.java index 445972b..98be095 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2LongLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2LongLinkedOpenCustomHashMap.java @@ -191,13 +191,13 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -205,7 +205,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -213,7 +213,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -225,13 +225,13 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -239,7 +239,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -247,7 +247,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -260,7 +260,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -271,7 +271,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -284,7 +284,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -295,7 +295,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -306,7 +306,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap if(isEmpty() || strategy.equals(firstLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -314,7 +314,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap if(isEmpty() || strategy.equals(lastLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -336,7 +336,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -349,7 +349,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap public long getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -357,7 +357,7 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap public long getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -533,8 +533,8 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -551,8 +551,8 @@ public class Long2LongLinkedOpenCustomHashMap extends Long2LongOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ObjectLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ObjectLinkedOpenCustomHashMap.java index 54f8c16..4431843 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ObjectLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ObjectLinkedOpenCustomHashMap.java @@ -193,13 +193,13 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -207,7 +207,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -215,7 +215,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -227,13 +227,13 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -241,7 +241,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -249,7 +249,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -262,7 +262,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -273,7 +273,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -286,7 +286,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -297,7 +297,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -308,7 +308,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom if(isEmpty() || strategy.equals(firstLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -316,7 +316,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -330,7 +330,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom if(isEmpty() || strategy.equals(lastLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -338,7 +338,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -351,7 +351,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom public V getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -359,7 +359,7 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom public V getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -535,8 +535,8 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -553,8 +553,8 @@ public class Long2ObjectLinkedOpenCustomHashMap extends Long2ObjectOpenCustom firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ShortLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ShortLinkedOpenCustomHashMap.java index 79b2870..04caecd 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ShortLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ShortLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM if(isEmpty() || strategy.equals(firstLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM if(isEmpty() || strategy.equals(lastLongKey(), key)) return false; if(strategy.equals(key, 0L)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], 0L)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM public short getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM public short getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Long2ShortLinkedOpenCustomHashMap extends Long2ShortOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2BooleanLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2BooleanLinkedOpenHashMap.java index 0e04647..7e47e1e 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2BooleanLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2BooleanLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple if(keys[pos] == key) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple if(keys[pos] == key) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple if(isEmpty() || firstLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple if(isEmpty() || lastLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple public boolean getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple public boolean getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Long2BooleanLinkedOpenHashMap extends Long2BooleanOpenHashMap imple firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ByteLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ByteLinkedOpenHashMap.java index 894196b..3850561 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ByteLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ByteLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements if(keys[pos] == key) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements if(keys[pos] == key) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements if(isEmpty() || firstLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements if(isEmpty() || lastLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements public byte getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements public byte getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Long2ByteLinkedOpenHashMap extends Long2ByteOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2CharLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2CharLinkedOpenHashMap.java index de71fca..7c8dfbd 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2CharLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2CharLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements if(keys[pos] == key) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements if(keys[pos] == key) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements if(isEmpty() || firstLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements if(isEmpty() || lastLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements public char getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements public char getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Long2CharLinkedOpenHashMap extends Long2CharOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2DoubleLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2DoubleLinkedOpenHashMap.java index 30e5b7d..af77db6 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2DoubleLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2DoubleLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme if(keys[pos] == key) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme if(keys[pos] == key) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme if(isEmpty() || firstLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme if(isEmpty() || lastLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme public double getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme public double getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Long2DoubleLinkedOpenHashMap extends Long2DoubleOpenHashMap impleme firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2FloatLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2FloatLinkedOpenHashMap.java index 7189f59..7640bf0 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2FloatLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2FloatLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement if(keys[pos] == key) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement if(keys[pos] == key) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement if(isEmpty() || firstLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement if(isEmpty() || lastLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement public float getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement public float getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Long2FloatLinkedOpenHashMap extends Long2FloatOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2IntLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2IntLinkedOpenHashMap.java index b50809a..73c72c3 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2IntLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2IntLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo if(keys[pos] == key) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo if(keys[pos] == key) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo if(isEmpty() || firstLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo if(isEmpty() || lastLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo public int getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo public int getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Long2IntLinkedOpenHashMap extends Long2IntOpenHashMap implements Lo firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2LongLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2LongLinkedOpenHashMap.java index 6055f47..2304f9b 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2LongLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2LongLinkedOpenHashMap.java @@ -168,13 +168,13 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -182,7 +182,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements if(keys[pos] == key) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -190,7 +190,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -202,13 +202,13 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -216,7 +216,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements if(keys[pos] == key) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -224,7 +224,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -237,7 +237,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -248,7 +248,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -261,7 +261,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -272,7 +272,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -283,7 +283,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements if(isEmpty() || firstLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -291,7 +291,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -305,7 +305,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements if(isEmpty() || lastLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -313,7 +313,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements public long getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -334,7 +334,7 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements public long getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Long2LongLinkedOpenHashMap extends Long2LongOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ObjectLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ObjectLinkedOpenHashMap.java index e55166c..4fbbc12 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ObjectLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ObjectLinkedOpenHashMap.java @@ -170,13 +170,13 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -184,7 +184,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i if(keys[pos] == key) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -192,7 +192,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -204,13 +204,13 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -218,7 +218,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i if(keys[pos] == key) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -226,7 +226,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -239,7 +239,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -250,7 +250,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -263,7 +263,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -274,7 +274,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -285,7 +285,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i if(isEmpty() || firstLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -293,7 +293,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -307,7 +307,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i if(isEmpty() || lastLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -315,7 +315,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i public V getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -336,7 +336,7 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i public V getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -522,8 +522,8 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -540,8 +540,8 @@ public class Long2ObjectLinkedOpenHashMap extends Long2ObjectOpenHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ShortLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ShortLinkedOpenHashMap.java index 4cfd346..94d39e1 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ShortLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ShortLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement if(keys[pos] == key) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement if(keys[pos] == key) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Long.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement if(isEmpty() || firstLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement if(isEmpty() || lastLongKey() == key) return false; if(key == 0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement int pos = HashUtil.mix(Long.hashCode(key)) & mask; while(keys[pos] != 0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement public short getAndMoveToFirst(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement public short getAndMoveToLast(long key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Long2ShortLinkedOpenHashMap extends Long2ShortOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/longs/queues/LongArrayFIFOQueue.java b/src/main/java/speiger/src/collections/longs/queues/LongArrayFIFOQueue.java index bfa3f20..43fc607 100644 --- a/src/main/java/speiger/src/collections/longs/queues/LongArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/longs/queues/LongArrayFIFOQueue.java @@ -3,6 +3,7 @@ package speiger.src.collections.longs.queues; import java.util.Arrays; import java.util.Objects; import java.util.OptionalLong; +import java.util.stream.LongStream; import java.util.NoSuchElementException; import java.util.function.LongPredicate; @@ -87,6 +88,20 @@ public class LongArrayFIFOQueue extends AbstractLongPriorityQueue implements Lon this(MIN_CAPACITY); } + + /** + * Collects a Stream to a ArrayFIFOQueue + * @return a queue with the contents of the Stream + */ + public static LongArrayFIFOQueue toQueue(LongStream stream) { + return stream.collect(LongArrayFIFOQueue::new, LongArrayFIFOQueue::enqueue, LongArrayFIFOQueue::merge); + } + + private LongArrayFIFOQueue merge(LongArrayFIFOQueue a) { + enqueueAll(a.toLongArray()); + return this; + } + @Override public LongIterator iterator() { return new Iter(); diff --git a/src/main/java/speiger/src/collections/longs/queues/LongArrayPriorityQueue.java b/src/main/java/speiger/src/collections/longs/queues/LongArrayPriorityQueue.java index 9a3b768..4e35b41 100644 --- a/src/main/java/speiger/src/collections/longs/queues/LongArrayPriorityQueue.java +++ b/src/main/java/speiger/src/collections/longs/queues/LongArrayPriorityQueue.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalLong; +import java.util.stream.LongStream; import java.util.function.LongPredicate; import speiger.src.collections.longs.collections.LongCollection; @@ -174,6 +175,19 @@ public class LongArrayPriorityQueue extends AbstractLongPriorityQueue queue.size = size; return queue; } + + /** + * Collects a Stream to a ArrayPriorityQueue + * @return a queue with the contents of the Stream + */ + public static LongArrayPriorityQueue toQueue(LongStream stream) { + return stream.collect(LongArrayPriorityQueue::new, LongArrayPriorityQueue::enqueue, LongArrayPriorityQueue::merge); + } + + private LongArrayPriorityQueue merge(LongArrayPriorityQueue a) { + enqueueAll(a.toLongArray()); + return this; + } @Override public void enqueue(long e) { diff --git a/src/main/java/speiger/src/collections/longs/queues/LongHeapPriorityQueue.java b/src/main/java/speiger/src/collections/longs/queues/LongHeapPriorityQueue.java index e37482e..592a967 100644 --- a/src/main/java/speiger/src/collections/longs/queues/LongHeapPriorityQueue.java +++ b/src/main/java/speiger/src/collections/longs/queues/LongHeapPriorityQueue.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalLong; +import java.util.stream.LongStream; import java.util.function.LongPredicate; import speiger.src.collections.longs.collections.LongCollection; @@ -177,6 +178,20 @@ public class LongHeapPriorityQueue extends AbstractLongPriorityQueue return queue; } + + /** + * Collects a Stream to a ArrayFIFOQueue + * @return a queue with the contents of the Stream + */ + public static LongHeapPriorityQueue toQueue(LongStream stream) { + return stream.collect(LongHeapPriorityQueue::new, LongHeapPriorityQueue::enqueue, LongHeapPriorityQueue::merge); + } + + private LongHeapPriorityQueue merge(LongHeapPriorityQueue a) { + enqueueAll(a.toLongArray()); + return this; + } + @Override public int size() { return size; diff --git a/src/main/java/speiger/src/collections/longs/sets/LongAVLTreeSet.java b/src/main/java/speiger/src/collections/longs/sets/LongAVLTreeSet.java index 8bfe5e5..e22d73f 100644 --- a/src/main/java/speiger/src/collections/longs/sets/LongAVLTreeSet.java +++ b/src/main/java/speiger/src/collections/longs/sets/LongAVLTreeSet.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalLong; +import java.util.stream.LongStream; import java.util.function.LongPredicate; import speiger.src.collections.longs.collections.LongBidirectionalIterator; @@ -183,6 +184,15 @@ public class LongAVLTreeSet extends AbstractLongSet implements LongNavigableSet while(iterator.hasNext()) add(iterator.nextLong()); } + + /** + * Collects a Stream to a AVLTreeSet + * @return a set with the contents of the Stream + */ + public static LongAVLTreeSet toSet(LongStream stream) { + return stream.collect(LongAVLTreeSet::new, LongAVLTreeSet::add, LongAVLTreeSet::addAll); + } + @Override public void setDefaultMaxValue(long value) { defaultMaxNotFound = value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/sets/LongArraySet.java b/src/main/java/speiger/src/collections/longs/sets/LongArraySet.java index f8b142a..73d30ea 100644 --- a/src/main/java/speiger/src/collections/longs/sets/LongArraySet.java +++ b/src/main/java/speiger/src/collections/longs/sets/LongArraySet.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalLong; +import java.util.stream.LongStream; import java.util.Set; import java.util.function.LongPredicate; import speiger.src.collections.longs.collections.LongBidirectionalIterator; @@ -54,7 +55,7 @@ public class LongArraySet extends AbstractLongSet implements LongOrderedSet * @param array the array that should be used for set. */ public LongArraySet(long[] array) { - this(array, array.length); + this(array, 0, array.length); } /** @@ -68,6 +69,18 @@ public class LongArraySet extends AbstractLongSet implements LongOrderedSet addAll(array, length); } + /** + * Constructur using initial Array + * @param array the array that should be used for set. + * @param offset the starting offset of where the array should be copied from + * @param length the amount of elements present within the array + * @throws NegativeArraySizeException if the length is negative + */ + public LongArraySet(long[] array, int offset, int length) { + this(length); + addAll(array, offset, length); + } + /** * A Helper constructor that allows to create a Set with exactly the same values as the provided collection. * @param c the elements that should be added to the set. @@ -111,6 +124,15 @@ public class LongArraySet extends AbstractLongSet implements LongOrderedSet for(LongIterator iter = s.iterator();iter.hasNext();data[size++] = iter.nextLong()); } + + /** + * Collects a Stream to a ArraySet + * @return a set with the contents of the Stream + */ + public static LongArraySet toList(LongStream stream) { + return stream.collect(LongArraySet::new, LongArraySet::add, LongArraySet::addAll); + } + @Override public boolean add(long o) { int index = findIndex(o); diff --git a/src/main/java/speiger/src/collections/longs/sets/LongLinkedOpenCustomHashSet.java b/src/main/java/speiger/src/collections/longs/sets/LongLinkedOpenCustomHashSet.java index 949b7cd..0d5cdf1 100644 --- a/src/main/java/speiger/src/collections/longs/sets/LongLinkedOpenCustomHashSet.java +++ b/src/main/java/speiger/src/collections/longs/sets/LongLinkedOpenCustomHashSet.java @@ -6,6 +6,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.OptionalLong; +import java.util.stream.LongStream; import java.util.function.LongPredicate; import speiger.src.collections.longs.collections.LongCollection; @@ -215,6 +216,15 @@ public class LongLinkedOpenCustomHashSet extends LongOpenCustomHashSet implement while(iterator.hasNext()) add(iterator.nextLong()); } + + /** + * Collects a Stream to a LinkedCustomHashSet + * @return a set with the contents of the Stream + */ + public static LongLinkedOpenCustomHashSet toList(LongStream stream, LongStrategy strategy) { + return stream.collect(() -> new LongLinkedOpenCustomHashSet(strategy), LongLinkedOpenCustomHashSet::add, LongLinkedOpenCustomHashSet::addAll); + } + @Override public void addFirst(long o) { if(strategy.equals(o, 0L)) { diff --git a/src/main/java/speiger/src/collections/longs/sets/LongLinkedOpenHashSet.java b/src/main/java/speiger/src/collections/longs/sets/LongLinkedOpenHashSet.java index 109ed7d..ef519cc 100644 --- a/src/main/java/speiger/src/collections/longs/sets/LongLinkedOpenHashSet.java +++ b/src/main/java/speiger/src/collections/longs/sets/LongLinkedOpenHashSet.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalLong; +import java.util.stream.LongStream; import java.util.function.LongPredicate; import speiger.src.collections.longs.collections.LongCollection; @@ -184,6 +185,15 @@ public class LongLinkedOpenHashSet extends LongOpenHashSet implements LongOrdere while(iterator.hasNext()) add(iterator.nextLong()); } + + /** + * Collects a Stream to a LinkedHashSet + * @return a set with the contents of the Stream + */ + public static LongLinkedOpenHashSet toLinkedSet(LongStream stream) { + return stream.collect(LongLinkedOpenHashSet::new, LongLinkedOpenHashSet::add, LongLinkedOpenHashSet::addAll); + } + @Override public void addFirst(long o) { if(o == 0) { diff --git a/src/main/java/speiger/src/collections/longs/sets/LongOpenCustomHashSet.java b/src/main/java/speiger/src/collections/longs/sets/LongOpenCustomHashSet.java index bfbd7bc..01d4583 100644 --- a/src/main/java/speiger/src/collections/longs/sets/LongOpenCustomHashSet.java +++ b/src/main/java/speiger/src/collections/longs/sets/LongOpenCustomHashSet.java @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalLong; +import java.util.stream.LongStream; import java.util.function.LongPredicate; import speiger.src.collections.longs.collections.LongCollection; @@ -234,6 +235,15 @@ public class LongOpenCustomHashSet extends AbstractLongSet implements ITrimmable while(iterator.hasNext()) add(iterator.nextLong()); } + + /** + * Collects a Stream to a CustomHashSet + * @return a set with the contents of the Stream + */ + public static LongOpenCustomHashSet toSet(LongStream stream, LongStrategy strategy) { + return stream.collect(() -> new LongOpenCustomHashSet(strategy), LongOpenCustomHashSet::add, LongOpenCustomHashSet::addAll); + } + /** * Helper getter function to get the current strategy * @return the current strategy diff --git a/src/main/java/speiger/src/collections/longs/sets/LongOpenHashSet.java b/src/main/java/speiger/src/collections/longs/sets/LongOpenHashSet.java index 37df91b..ced4511 100644 --- a/src/main/java/speiger/src/collections/longs/sets/LongOpenHashSet.java +++ b/src/main/java/speiger/src/collections/longs/sets/LongOpenHashSet.java @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.OptionalLong; +import java.util.stream.LongStream; import java.util.function.LongPredicate; import speiger.src.collections.longs.collections.LongCollection; @@ -201,6 +202,15 @@ public class LongOpenHashSet extends AbstractLongSet implements ITrimmable while(iterator.hasNext()) add(iterator.nextLong()); } + + /** + * Collects a Stream to a HashSet + * @return a set with the contents of the Stream + */ + public static LongOpenHashSet toSet(LongStream stream) { + return stream.collect(LongOpenHashSet::new, LongOpenHashSet::add, LongOpenHashSet::addAll); + } + @Override public boolean add(long o) { if(o == 0) { diff --git a/src/main/java/speiger/src/collections/longs/sets/LongRBTreeSet.java b/src/main/java/speiger/src/collections/longs/sets/LongRBTreeSet.java index 60268f8..8c3bd57 100644 --- a/src/main/java/speiger/src/collections/longs/sets/LongRBTreeSet.java +++ b/src/main/java/speiger/src/collections/longs/sets/LongRBTreeSet.java @@ -3,6 +3,7 @@ package speiger.src.collections.longs.sets; import java.util.Collection; import java.util.Collections; import java.util.OptionalLong; +import java.util.stream.LongStream; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; @@ -183,6 +184,15 @@ public class LongRBTreeSet extends AbstractLongSet implements LongNavigableSet while(iterator.hasNext()) add(iterator.nextLong()); } + + /** + * Collects a Stream to a RBTreeSet + * @return a set with the contents of the Stream + */ + public static LongRBTreeSet toSet(LongStream stream) { + return stream.collect(LongRBTreeSet::new, LongRBTreeSet::add, LongRBTreeSet::addAll); + } + @Override public void setDefaultMaxValue(long value) { defaultMaxNotFound = value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/utils/LongAsyncBuilder.java b/src/main/java/speiger/src/collections/longs/utils/LongAsyncBuilder.java index 64046e2..61975f7 100644 --- a/src/main/java/speiger/src/collections/longs/utils/LongAsyncBuilder.java +++ b/src/main/java/speiger/src/collections/longs/utils/LongAsyncBuilder.java @@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.LockSupport; import java.util.function.Consumer; +import java.util.OptionalLong; import speiger.src.collections.longs.functions.LongConsumer; import speiger.src.collections.longs.functions.LongComparator; @@ -210,9 +211,8 @@ public class LongAsyncBuilder * @param operator that reduces the elements. * @return self with the reduce action applied */ - public LongAsyncBuilder reduce(LongLongUnaryOperator operator) { - task = new SimpleReduceTask(iterable.iterator(), operator); - return this; + public ObjectAsyncBuilder reduce(LongLongUnaryOperator operator) { + return new ObjectAsyncBuilder<>(new SimpleReduceTask(iterable.iterator(), operator)); } /** @@ -292,9 +292,8 @@ public class LongAsyncBuilder * @param filter that decides the desired elements * @return self with the findFirst function applied */ - public LongAsyncBuilder findFirst(LongPredicate filter) { - task = new FindFirstTask(iterable.iterator(), filter); - return this; + public ObjectAsyncBuilder findFirst(LongPredicate filter) { + return new ObjectAsyncBuilder<>(new FindFirstTask(iterable.iterator(), filter)); } /** @@ -404,7 +403,7 @@ public class LongAsyncBuilder } } - private static class SimpleReduceTask extends BaseLongTask + private static class SimpleReduceTask extends BaseObjectTask { LongIterator iter; LongLongUnaryOperator operator; @@ -414,6 +413,7 @@ public class LongAsyncBuilder public SimpleReduceTask(LongIterator iter, LongLongUnaryOperator operator) { this.iter = iter; this.operator = operator; + this.setResult(OptionalLong.empty()); } @Override @@ -428,7 +428,7 @@ public class LongAsyncBuilder } } if(!iter.hasNext()) { - setResult(value); + setResult(OptionalLong.of(value)); return true; } return false; @@ -498,7 +498,7 @@ public class LongAsyncBuilder } } - private static class FindFirstTask extends BaseLongTask + private static class FindFirstTask extends BaseObjectTask { LongIterator iter; LongPredicate filter; @@ -506,6 +506,7 @@ public class LongAsyncBuilder public FindFirstTask(LongIterator iter, LongPredicate filter) { this.iter = iter; this.filter = filter; + this.setResult(OptionalLong.empty()); } @Override @@ -513,7 +514,7 @@ public class LongAsyncBuilder while(shouldRun() && iter.hasNext()) { long entry = iter.nextLong(); if(filter.test(iter.nextLong())) { - setResult(entry); + setResult(OptionalLong.of(entry)); return true; } } diff --git a/src/main/java/speiger/src/collections/longs/utils/LongCollections.java b/src/main/java/speiger/src/collections/longs/utils/LongCollections.java index 50b97c9..463f118 100644 --- a/src/main/java/speiger/src/collections/longs/utils/LongCollections.java +++ b/src/main/java/speiger/src/collections/longs/utils/LongCollections.java @@ -108,7 +108,10 @@ public class LongCollections return new SingletonCollection(element); } - protected static CollectionWrapper wrapper() { + /** + * Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed. + */ + public static CollectionWrapper wrapper() { return new CollectionWrapper(); } diff --git a/src/main/java/speiger/src/collections/objects/lists/CopyOnWriteObjectArrayList.java b/src/main/java/speiger/src/collections/objects/lists/CopyOnWriteObjectArrayList.java index 43f5d5a..1121dfe 100644 --- a/src/main/java/speiger/src/collections/objects/lists/CopyOnWriteObjectArrayList.java +++ b/src/main/java/speiger/src/collections/objects/lists/CopyOnWriteObjectArrayList.java @@ -7,6 +7,8 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; import java.util.function.Supplier; @@ -120,6 +122,28 @@ public class CopyOnWriteObjectArrayList extends AbstractObjectList impleme return list; } + /** + * Creates a Collector for a CopyOnWriteArrayList + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, CopyOnWriteObjectArrayList> toList() { + return Collector.of(CopyOnWriteObjectArrayList::new, CopyOnWriteObjectArrayList::add, CopyOnWriteObjectArrayList::merge); + } + + /** + * Collects a Stream to a CopyOnWriteArrayList + * @param the keyType of elements maintained by this Collection + * @return a list with the contents of the Stream + */ + public static CopyOnWriteObjectArrayList toList(Stream stream) { + return stream.collect(CopyOnWriteObjectArrayList::new, CopyOnWriteObjectArrayList::add, CopyOnWriteObjectArrayList::merge); + } + + private CopyOnWriteObjectArrayList merge(CopyOnWriteObjectArrayList a) { + addAll(a); + return this; + } private void setArray(T[] data) { this.data = data; diff --git a/src/main/java/speiger/src/collections/objects/lists/ImmutableObjectList.java b/src/main/java/speiger/src/collections/objects/lists/ImmutableObjectList.java index 7177004..04c815c 100644 --- a/src/main/java/speiger/src/collections/objects/lists/ImmutableObjectList.java +++ b/src/main/java/speiger/src/collections/objects/lists/ImmutableObjectList.java @@ -6,6 +6,10 @@ import java.util.Collection; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; + +import java.util.stream.Stream; +import java.util.stream.Collector; +import speiger.src.collections.objects.utils.ObjectCollections; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Predicate; @@ -86,6 +90,29 @@ public class ImmutableObjectList extends AbstractObjectList data = Arrays.copyOfRange(a, offset, offset+length); } + /** + * Creates a Collector for a ImmutableList + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ImmutableObjectList> toList() { + return Collector.of(ObjectCollections::wrapper, ObjectCollection::add, ImmutableObjectList::merge, E -> new ImmutableObjectList<>(E.toArray((T[])new Object[E.size()]))); + } + + /** + * Collects a Stream to a ImmutableList + * @param the keyType of elements maintained by this Collection + * @return a list with the contents of the Stream + */ + public static ImmutableObjectList toList(Stream stream) { + return stream.collect(toList()); + } + + private static ObjectCollection merge(ObjectCollection a, ObjectCollection b) { + a.addAll(b); + return a; + } + @Override public boolean add(T e) { throw new UnsupportedOperationException(); } @Override diff --git a/src/main/java/speiger/src/collections/objects/lists/ObjectArrayList.java b/src/main/java/speiger/src/collections/objects/lists/ObjectArrayList.java index 837a37b..dd8bcc2 100644 --- a/src/main/java/speiger/src/collections/objects/lists/ObjectArrayList.java +++ b/src/main/java/speiger/src/collections/objects/lists/ObjectArrayList.java @@ -6,6 +6,9 @@ import java.util.Collection; import java.util.Iterator; import java.util.Objects; import java.util.Optional; +import java.util.stream.Stream; +import java.util.stream.Collector; + import java.util.function.Consumer; import java.util.function.BiFunction; import java.util.function.IntFunction; @@ -167,6 +170,29 @@ public class ObjectArrayList extends AbstractObjectList implements IObject return list; } + /** + * Creates a Collector for a ArrayList + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectArrayList> toList() { + return Collector.of(ObjectArrayList::new, ObjectArrayList::add, ObjectArrayList::merge); + } + + /** + * Collects a Stream to a ArrayList + * @param the keyType of elements maintained by this Collection + * @return a list with the contents of the Stream + */ + public static ObjectArrayList toList(Stream stream) { + return stream.collect(ObjectArrayList::new, ObjectArrayList::add, ObjectArrayList::merge); + } + + private ObjectArrayList merge(ObjectArrayList a) { + addAll(a); + return this; + } + /** * Appends the specified element to the end of this list. * diff --git a/src/main/java/speiger/src/collections/objects/lists/ObjectLinkedList.java b/src/main/java/speiger/src/collections/objects/lists/ObjectLinkedList.java index 67792fa..c8cbe76 100644 --- a/src/main/java/speiger/src/collections/objects/lists/ObjectLinkedList.java +++ b/src/main/java/speiger/src/collections/objects/lists/ObjectLinkedList.java @@ -5,6 +5,8 @@ import java.util.Collection; import java.util.Iterator; import java.util.Objects; import java.util.Optional; +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.NoSuchElementException; import java.util.Spliterator; import java.util.function.Consumer; @@ -98,6 +100,29 @@ public class ObjectLinkedList extends AbstractObjectList implements Object for(int i = offset,m=offset+length;i the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectLinkedList> toList() { + return Collector.of(ObjectLinkedList::new, ObjectLinkedList::add, ObjectLinkedList::merge); + } + + /** + * Collects a Stream to a LinkedList + * @param the keyType of elements maintained by this Collection + * @return a list with the contents of the Stream + */ + public static ObjectLinkedList toList(Stream stream) { + return stream.collect(ObjectLinkedList::new, ObjectLinkedList::add, ObjectLinkedList::merge); + } + + private ObjectLinkedList merge(ObjectLinkedList a) { + addAll(a); + return this; + } + @Override public boolean add(T e) { add(size(), e); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2BooleanLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2BooleanLinkedOpenCustomHashMap.java index 455bfe5..ccb510d 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2BooleanLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2BooleanLinkedOpenCustomHashMap.java @@ -189,13 +189,13 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -203,7 +203,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -211,7 +211,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -223,13 +223,13 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -237,7 +237,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -245,7 +245,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -258,7 +258,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -269,7 +269,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -282,7 +282,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -293,7 +293,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -304,7 +304,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen if(isEmpty() || strategy.equals(firstKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -312,7 +312,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen if(isEmpty() || strategy.equals(lastKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -334,7 +334,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -347,7 +347,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen public boolean getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -355,7 +355,7 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen public boolean getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Object2BooleanLinkedOpenCustomHashMap extends Object2BooleanOpen firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ByteLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ByteLinkedOpenCustomHashMap.java index ad9fab6..f1c59cb 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ByteLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ByteLinkedOpenCustomHashMap.java @@ -189,13 +189,13 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -203,7 +203,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -211,7 +211,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -223,13 +223,13 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -237,7 +237,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -245,7 +245,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -258,7 +258,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -269,7 +269,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -282,7 +282,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -293,7 +293,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -304,7 +304,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom if(isEmpty() || strategy.equals(firstKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -312,7 +312,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom if(isEmpty() || strategy.equals(lastKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -334,7 +334,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -347,7 +347,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom public byte getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -355,7 +355,7 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom public byte getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Object2ByteLinkedOpenCustomHashMap extends Object2ByteOpenCustom firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2CharLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2CharLinkedOpenCustomHashMap.java index 01f55c4..5545916 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2CharLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2CharLinkedOpenCustomHashMap.java @@ -189,13 +189,13 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -203,7 +203,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -211,7 +211,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -223,13 +223,13 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -237,7 +237,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -245,7 +245,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -258,7 +258,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -269,7 +269,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -282,7 +282,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -293,7 +293,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -304,7 +304,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom if(isEmpty() || strategy.equals(firstKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -312,7 +312,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom if(isEmpty() || strategy.equals(lastKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -334,7 +334,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -347,7 +347,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom public char getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -355,7 +355,7 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom public char getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Object2CharLinkedOpenCustomHashMap extends Object2CharOpenCustom firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2DoubleLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2DoubleLinkedOpenCustomHashMap.java index 6a30af0..2797ff4 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2DoubleLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2DoubleLinkedOpenCustomHashMap.java @@ -189,13 +189,13 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -203,7 +203,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -211,7 +211,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -223,13 +223,13 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -237,7 +237,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -245,7 +245,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -258,7 +258,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -269,7 +269,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -282,7 +282,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -293,7 +293,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -304,7 +304,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu if(isEmpty() || strategy.equals(firstKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -312,7 +312,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu if(isEmpty() || strategy.equals(lastKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -334,7 +334,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -347,7 +347,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu public double getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -355,7 +355,7 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu public double getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Object2DoubleLinkedOpenCustomHashMap extends Object2DoubleOpenCu firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2FloatLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2FloatLinkedOpenCustomHashMap.java index 1f0f637..181e0ea 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2FloatLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2FloatLinkedOpenCustomHashMap.java @@ -189,13 +189,13 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -203,7 +203,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -211,7 +211,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -223,13 +223,13 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -237,7 +237,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -245,7 +245,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -258,7 +258,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -269,7 +269,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -282,7 +282,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -293,7 +293,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -304,7 +304,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust if(isEmpty() || strategy.equals(firstKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -312,7 +312,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust if(isEmpty() || strategy.equals(lastKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -334,7 +334,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -347,7 +347,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust public float getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -355,7 +355,7 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust public float getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Object2FloatLinkedOpenCustomHashMap extends Object2FloatOpenCust firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2IntLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2IntLinkedOpenCustomHashMap.java index 3910662..595e0af 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2IntLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2IntLinkedOpenCustomHashMap.java @@ -189,13 +189,13 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -203,7 +203,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -211,7 +211,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -223,13 +223,13 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -237,7 +237,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -245,7 +245,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -258,7 +258,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -269,7 +269,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -282,7 +282,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -293,7 +293,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -304,7 +304,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa if(isEmpty() || strategy.equals(firstKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -312,7 +312,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa if(isEmpty() || strategy.equals(lastKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -334,7 +334,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -347,7 +347,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa public int getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -355,7 +355,7 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa public int getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Object2IntLinkedOpenCustomHashMap extends Object2IntOpenCustomHa firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2LongLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2LongLinkedOpenCustomHashMap.java index 5ff4ffa..21b5221 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2LongLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2LongLinkedOpenCustomHashMap.java @@ -189,13 +189,13 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -203,7 +203,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -211,7 +211,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -223,13 +223,13 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -237,7 +237,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -245,7 +245,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -258,7 +258,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -269,7 +269,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -282,7 +282,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -293,7 +293,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -304,7 +304,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom if(isEmpty() || strategy.equals(firstKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -312,7 +312,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom if(isEmpty() || strategy.equals(lastKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -334,7 +334,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -347,7 +347,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom public long getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -355,7 +355,7 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom public long getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Object2LongLinkedOpenCustomHashMap extends Object2LongOpenCustom firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ObjectLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ObjectLinkedOpenCustomHashMap.java index 239872d..d309c5f 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ObjectLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ObjectLinkedOpenCustomHashMap.java @@ -154,13 +154,13 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -168,7 +168,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -176,7 +176,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -188,13 +188,13 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -202,7 +202,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -210,7 +210,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -223,7 +223,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -234,7 +234,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -247,7 +247,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -258,7 +258,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe if(isEmpty() || strategy.equals(firstKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -277,7 +277,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -291,7 +291,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe if(isEmpty() || strategy.equals(lastKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -312,7 +312,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe public V getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -320,7 +320,7 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe public V getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -496,8 +496,8 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -514,8 +514,8 @@ public class Object2ObjectLinkedOpenCustomHashMap extends Object2ObjectOpe firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ShortLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ShortLinkedOpenCustomHashMap.java index ff6cd48..6e40b10 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ShortLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ShortLinkedOpenCustomHashMap.java @@ -189,13 +189,13 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -203,7 +203,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -211,7 +211,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -223,13 +223,13 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -237,7 +237,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -245,7 +245,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -258,7 +258,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -269,7 +269,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -282,7 +282,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -293,7 +293,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -304,7 +304,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust if(isEmpty() || strategy.equals(firstKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -312,7 +312,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust if(isEmpty() || strategy.equals(lastKey(), key)) return false; if(strategy.equals(key, null)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -334,7 +334,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], null)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -347,7 +347,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust public short getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -355,7 +355,7 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust public short getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Object2ShortLinkedOpenCustomHashMap extends Object2ShortOpenCust firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2BooleanLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2BooleanLinkedOpenHashMap.java index bfc10d7..22774db 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2BooleanLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2BooleanLinkedOpenHashMap.java @@ -166,13 +166,13 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -180,7 +180,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa if(Objects.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -188,7 +188,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -200,13 +200,13 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -214,7 +214,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa if(Objects.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -222,7 +222,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -235,7 +235,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -259,7 +259,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -270,7 +270,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -281,7 +281,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa if(isEmpty() || Objects.equals(firstKey(), key)) return false; if(key == null) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -289,7 +289,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -303,7 +303,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa if(isEmpty() || Objects.equals(lastKey(), key)) return false; if(key == null) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -311,7 +311,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -324,7 +324,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa public boolean getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -332,7 +332,7 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa public boolean getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -529,8 +529,8 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -547,8 +547,8 @@ public class Object2BooleanLinkedOpenHashMap extends Object2BooleanOpenHashMa firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ByteLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ByteLinkedOpenHashMap.java index 66dd2c0..fc82a5f 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ByteLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ByteLinkedOpenHashMap.java @@ -166,13 +166,13 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -180,7 +180,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i if(Objects.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -188,7 +188,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -200,13 +200,13 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -214,7 +214,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i if(Objects.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -222,7 +222,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -235,7 +235,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -259,7 +259,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -270,7 +270,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -281,7 +281,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i if(isEmpty() || Objects.equals(firstKey(), key)) return false; if(key == null) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -289,7 +289,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -303,7 +303,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i if(isEmpty() || Objects.equals(lastKey(), key)) return false; if(key == null) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -311,7 +311,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -324,7 +324,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i public byte getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -332,7 +332,7 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i public byte getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -529,8 +529,8 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -547,8 +547,8 @@ public class Object2ByteLinkedOpenHashMap extends Object2ByteOpenHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2CharLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2CharLinkedOpenHashMap.java index e1fd37c..1e48337 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2CharLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2CharLinkedOpenHashMap.java @@ -166,13 +166,13 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -180,7 +180,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i if(Objects.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -188,7 +188,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -200,13 +200,13 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -214,7 +214,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i if(Objects.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -222,7 +222,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -235,7 +235,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -259,7 +259,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -270,7 +270,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -281,7 +281,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i if(isEmpty() || Objects.equals(firstKey(), key)) return false; if(key == null) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -289,7 +289,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -303,7 +303,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i if(isEmpty() || Objects.equals(lastKey(), key)) return false; if(key == null) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -311,7 +311,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -324,7 +324,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i public char getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -332,7 +332,7 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i public char getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -529,8 +529,8 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -547,8 +547,8 @@ public class Object2CharLinkedOpenHashMap extends Object2CharOpenHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2DoubleLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2DoubleLinkedOpenHashMap.java index a6bae9a..31d2e71 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2DoubleLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2DoubleLinkedOpenHashMap.java @@ -166,13 +166,13 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -180,7 +180,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< if(Objects.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -188,7 +188,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -200,13 +200,13 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -214,7 +214,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< if(Objects.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -222,7 +222,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -235,7 +235,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -259,7 +259,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -270,7 +270,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -281,7 +281,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< if(isEmpty() || Objects.equals(firstKey(), key)) return false; if(key == null) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -289,7 +289,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -303,7 +303,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< if(isEmpty() || Objects.equals(lastKey(), key)) return false; if(key == null) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -311,7 +311,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -324,7 +324,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< public double getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -332,7 +332,7 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< public double getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -529,8 +529,8 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -547,8 +547,8 @@ public class Object2DoubleLinkedOpenHashMap extends Object2DoubleOpenHashMap< firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2FloatLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2FloatLinkedOpenHashMap.java index 7cca887..ff5f220 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2FloatLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2FloatLinkedOpenHashMap.java @@ -166,13 +166,13 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -180,7 +180,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap if(Objects.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -188,7 +188,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -200,13 +200,13 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -214,7 +214,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap if(Objects.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -222,7 +222,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -235,7 +235,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -259,7 +259,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -270,7 +270,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -281,7 +281,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap if(isEmpty() || Objects.equals(firstKey(), key)) return false; if(key == null) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -289,7 +289,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -303,7 +303,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap if(isEmpty() || Objects.equals(lastKey(), key)) return false; if(key == null) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -311,7 +311,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -324,7 +324,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap public float getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -332,7 +332,7 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap public float getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -529,8 +529,8 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -547,8 +547,8 @@ public class Object2FloatLinkedOpenHashMap extends Object2FloatOpenHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2IntLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2IntLinkedOpenHashMap.java index 0eebf38..776fa16 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2IntLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2IntLinkedOpenHashMap.java @@ -166,13 +166,13 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -180,7 +180,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp if(Objects.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -188,7 +188,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -200,13 +200,13 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -214,7 +214,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp if(Objects.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -222,7 +222,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -235,7 +235,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -259,7 +259,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -270,7 +270,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -281,7 +281,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp if(isEmpty() || Objects.equals(firstKey(), key)) return false; if(key == null) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -289,7 +289,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -303,7 +303,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp if(isEmpty() || Objects.equals(lastKey(), key)) return false; if(key == null) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -311,7 +311,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -324,7 +324,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp public int getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -332,7 +332,7 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp public int getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -529,8 +529,8 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -547,8 +547,8 @@ public class Object2IntLinkedOpenHashMap extends Object2IntOpenHashMap imp firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2LongLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2LongLinkedOpenHashMap.java index 47e3db3..2f357df 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2LongLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2LongLinkedOpenHashMap.java @@ -166,13 +166,13 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -180,7 +180,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i if(Objects.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -188,7 +188,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -200,13 +200,13 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -214,7 +214,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i if(Objects.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -222,7 +222,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -235,7 +235,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -259,7 +259,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -270,7 +270,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -281,7 +281,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i if(isEmpty() || Objects.equals(firstKey(), key)) return false; if(key == null) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -289,7 +289,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -303,7 +303,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i if(isEmpty() || Objects.equals(lastKey(), key)) return false; if(key == null) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -311,7 +311,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -324,7 +324,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i public long getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -332,7 +332,7 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i public long getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -529,8 +529,8 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -547,8 +547,8 @@ public class Object2LongLinkedOpenHashMap extends Object2LongOpenHashMap i firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ObjectLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ObjectLinkedOpenHashMap.java index 5324ca9..cf35067 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ObjectLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ObjectLinkedOpenHashMap.java @@ -135,13 +135,13 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -149,7 +149,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM if(Objects.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -157,7 +157,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -169,13 +169,13 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -183,7 +183,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM if(Objects.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -191,7 +191,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -204,7 +204,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -215,7 +215,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -228,7 +228,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -239,7 +239,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -250,7 +250,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM if(isEmpty() || Objects.equals(firstKey(), key)) return false; if(key == null) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -258,7 +258,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -272,7 +272,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM if(isEmpty() || Objects.equals(lastKey(), key)) return false; if(key == null) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -280,7 +280,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -293,7 +293,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM public V getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -301,7 +301,7 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM public V getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -487,8 +487,8 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -505,8 +505,8 @@ public class Object2ObjectLinkedOpenHashMap extends Object2ObjectOpenHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ShortLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ShortLinkedOpenHashMap.java index 8a6ac42..9e4dff1 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ShortLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ShortLinkedOpenHashMap.java @@ -166,13 +166,13 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -180,7 +180,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap if(Objects.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -188,7 +188,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -200,13 +200,13 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -214,7 +214,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap if(Objects.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -222,7 +222,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -235,7 +235,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -246,7 +246,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -259,7 +259,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Objects.hashCode(key)) & mask; @@ -270,7 +270,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -281,7 +281,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap if(isEmpty() || Objects.equals(firstKey(), key)) return false; if(key == null) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -289,7 +289,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -303,7 +303,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap if(isEmpty() || Objects.equals(lastKey(), key)) return false; if(key == null) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -311,7 +311,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap int pos = HashUtil.mix(Objects.hashCode(key)) & mask; while(keys[pos] != null) { if(Objects.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -324,7 +324,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap public short getAndMoveToFirst(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -332,7 +332,7 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap public short getAndMoveToLast(T key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -529,8 +529,8 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -547,8 +547,8 @@ public class Object2ShortLinkedOpenHashMap extends Object2ShortOpenHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/objects/queues/ObjectArrayFIFOQueue.java b/src/main/java/speiger/src/collections/objects/queues/ObjectArrayFIFOQueue.java index b52aff2..1fb5dae 100644 --- a/src/main/java/speiger/src/collections/objects/queues/ObjectArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/objects/queues/ObjectArrayFIFOQueue.java @@ -6,6 +6,9 @@ import java.util.function.Consumer; import java.util.function.BiFunction; import java.util.Objects; import java.util.Optional; + +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.NoSuchElementException; import java.util.function.Predicate; @@ -89,6 +92,29 @@ public class ObjectArrayFIFOQueue extends AbstractObjectPriorityQueue impl this(MIN_CAPACITY); } + /** + * Creates a Collector for a ArrayFIFOQueue + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectArrayFIFOQueue> toQueue() { + return Collector.of(ObjectArrayFIFOQueue::new, ObjectArrayFIFOQueue::enqueue, ObjectArrayFIFOQueue::merge); + } + + /** + * Collects a Stream to a ArrayFIFOQueue + * @param the keyType of elements maintained by this Collection + * @return a queue with the contents of the Stream + */ + public static ObjectArrayFIFOQueue toQueue(Stream stream) { + return stream.collect(ObjectArrayFIFOQueue::new, ObjectArrayFIFOQueue::enqueue, ObjectArrayFIFOQueue::merge); + } + + private ObjectArrayFIFOQueue merge(ObjectArrayFIFOQueue a) { + enqueueAll(a.toArray((T[])new Object[a.size()])); + return this; + } + @Override public ObjectIterator iterator() { return new Iter(); diff --git a/src/main/java/speiger/src/collections/objects/queues/ObjectArrayPriorityQueue.java b/src/main/java/speiger/src/collections/objects/queues/ObjectArrayPriorityQueue.java index f2d17bb..4106389 100644 --- a/src/main/java/speiger/src/collections/objects/queues/ObjectArrayPriorityQueue.java +++ b/src/main/java/speiger/src/collections/objects/queues/ObjectArrayPriorityQueue.java @@ -7,6 +7,9 @@ import java.util.function.Consumer; import java.util.function.BiFunction; import java.util.Objects; import java.util.Optional; + +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.function.Predicate; import speiger.src.collections.objects.collections.ObjectCollection; @@ -180,6 +183,28 @@ public class ObjectArrayPriorityQueue extends AbstractObjectPriorityQueue queue.size = size; return queue; } + /** + * Creates a Collector for a ArrayPriorityQueue + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectArrayPriorityQueue> toQueue() { + return Collector.of(ObjectArrayPriorityQueue::new, ObjectArrayPriorityQueue::enqueue, ObjectArrayPriorityQueue::merge); + } + + /** + * Collects a Stream to a ArrayPriorityQueue + * @param the keyType of elements maintained by this Collection + * @return a queue with the contents of the Stream + */ + public static ObjectArrayPriorityQueue toQueue(Stream stream) { + return stream.collect(ObjectArrayPriorityQueue::new, ObjectArrayPriorityQueue::enqueue, ObjectArrayPriorityQueue::merge); + } + + private ObjectArrayPriorityQueue merge(ObjectArrayPriorityQueue a) { + enqueueAll(a.toArray((T[])new Object[a.size()])); + return this; + } @Override public void enqueue(T e) { diff --git a/src/main/java/speiger/src/collections/objects/queues/ObjectHeapPriorityQueue.java b/src/main/java/speiger/src/collections/objects/queues/ObjectHeapPriorityQueue.java index 426ebba..fde01d2 100644 --- a/src/main/java/speiger/src/collections/objects/queues/ObjectHeapPriorityQueue.java +++ b/src/main/java/speiger/src/collections/objects/queues/ObjectHeapPriorityQueue.java @@ -7,6 +7,9 @@ import java.util.function.Consumer; import java.util.function.BiFunction; import java.util.Objects; import java.util.Optional; + +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.function.Predicate; import speiger.src.collections.objects.collections.ObjectCollection; @@ -183,6 +186,29 @@ public class ObjectHeapPriorityQueue extends AbstractObjectPriorityQueue return queue; } + /** + * Creates a Collector for a ArrayFIFOQueue + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectHeapPriorityQueue> toQueue() { + return Collector.of(ObjectHeapPriorityQueue::new, ObjectHeapPriorityQueue::enqueue, ObjectHeapPriorityQueue::merge); + } + + /** + * Collects a Stream to a ArrayFIFOQueue + * @param the keyType of elements maintained by this Collection + * @return a queue with the contents of the Stream + */ + public static ObjectHeapPriorityQueue toQueue(Stream stream) { + return stream.collect(ObjectHeapPriorityQueue::new, ObjectHeapPriorityQueue::enqueue, ObjectHeapPriorityQueue::merge); + } + + private ObjectHeapPriorityQueue merge(ObjectHeapPriorityQueue a) { + enqueueAll(a.toArray((T[])new Object[a.size()])); + return this; + } + @Override public int size() { return size; diff --git a/src/main/java/speiger/src/collections/objects/sets/ObjectAVLTreeSet.java b/src/main/java/speiger/src/collections/objects/sets/ObjectAVLTreeSet.java index 0a0ebd3..88d2b13 100644 --- a/src/main/java/speiger/src/collections/objects/sets/ObjectAVLTreeSet.java +++ b/src/main/java/speiger/src/collections/objects/sets/ObjectAVLTreeSet.java @@ -9,6 +9,8 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.function.Predicate; import speiger.src.collections.objects.collections.ObjectBidirectionalIterator; @@ -179,6 +181,29 @@ public class ObjectAVLTreeSet extends AbstractObjectSet implements ObjectN while(iterator.hasNext()) add(iterator.next()); } + /** + * Creates a Collector for a AVLTreeSet + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectAVLTreeSet> toSet() { + return Collector.of(ObjectAVLTreeSet::new, ObjectAVLTreeSet::add, ObjectAVLTreeSet::merge); + } + + /** + * Collects a Stream to a AVLTreeSet + * @param the keyType of elements maintained by this Collection + * @return a set with the contents of the Stream + */ + public static ObjectAVLTreeSet toSet(Stream stream) { + return stream.collect(ObjectAVLTreeSet::new, ObjectAVLTreeSet::add, ObjectAVLTreeSet::merge); + } + + private ObjectAVLTreeSet merge(ObjectAVLTreeSet a) { + addAll(a); + return this; + } + /** only used for primitives * @return null */ diff --git a/src/main/java/speiger/src/collections/objects/sets/ObjectArraySet.java b/src/main/java/speiger/src/collections/objects/sets/ObjectArraySet.java index 580e062..60a107e 100644 --- a/src/main/java/speiger/src/collections/objects/sets/ObjectArraySet.java +++ b/src/main/java/speiger/src/collections/objects/sets/ObjectArraySet.java @@ -7,6 +7,8 @@ import java.util.function.BiFunction; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.Set; import java.util.function.Predicate; import speiger.src.collections.objects.collections.ObjectBidirectionalIterator; @@ -55,7 +57,7 @@ public class ObjectArraySet extends AbstractObjectSet implements ObjectOrd * @param array the array that should be used for set. */ public ObjectArraySet(T[] array) { - this(array, array.length); + this(array, 0, array.length); } /** @@ -69,6 +71,18 @@ public class ObjectArraySet extends AbstractObjectSet implements ObjectOrd addAll(array, length); } + /** + * Constructur using initial Array + * @param array the array that should be used for set. + * @param offset the starting offset of where the array should be copied from + * @param length the amount of elements present within the array + * @throws NegativeArraySizeException if the length is negative + */ + public ObjectArraySet(T[] array, int offset, int length) { + this(length); + addAll(array, offset, length); + } + /** * A Helper constructor that allows to create a Set with exactly the same values as the provided collection. * @param c the elements that should be added to the set. @@ -110,6 +124,29 @@ public class ObjectArraySet extends AbstractObjectSet implements ObjectOrd for(ObjectIterator iter = s.iterator();iter.hasNext();data[size++] = iter.next()); } + /** + * Creates a Collector for a ArraySet + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectArraySet> toList() { + return Collector.of(ObjectArraySet::new, ObjectArraySet::add, ObjectArraySet::merge); + } + + /** + * Collects a Stream to a ArraySet + * @param the keyType of elements maintained by this Collection + * @return a set with the contents of the Stream + */ + public static ObjectArraySet toList(Stream stream) { + return stream.collect(ObjectArraySet::new, ObjectArraySet::add, ObjectArraySet::merge); + } + + private ObjectArraySet merge(ObjectArraySet a) { + addAll(a); + return this; + } + @Override public boolean add(T o) { int index = findIndex(o); diff --git a/src/main/java/speiger/src/collections/objects/sets/ObjectLinkedOpenCustomHashSet.java b/src/main/java/speiger/src/collections/objects/sets/ObjectLinkedOpenCustomHashSet.java index 2cd42c7..dd0921a 100644 --- a/src/main/java/speiger/src/collections/objects/sets/ObjectLinkedOpenCustomHashSet.java +++ b/src/main/java/speiger/src/collections/objects/sets/ObjectLinkedOpenCustomHashSet.java @@ -8,6 +8,8 @@ import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Optional; +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.function.Predicate; import speiger.src.collections.objects.collections.ObjectCollection; @@ -191,6 +193,29 @@ public class ObjectLinkedOpenCustomHashSet extends ObjectOpenCustomHashSet while(iterator.hasNext()) add(iterator.next()); } + /** + * Creates a Collector for a LinkedCustomHashSet + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectLinkedOpenCustomHashSet> toLinkedSet(ObjectStrategy strategy) { + return Collector.of(() -> new ObjectLinkedOpenCustomHashSet<>(strategy), ObjectLinkedOpenCustomHashSet::add, ObjectLinkedOpenCustomHashSet::merge); + } + + /** + * Collects a Stream to a LinkedCustomHashSet + * @param the keyType of elements maintained by this Collection + * @return a set with the contents of the Stream + */ + public static ObjectLinkedOpenCustomHashSet toLinkedSet(Stream stream, ObjectStrategy strategy) { + return stream.collect(() -> new ObjectLinkedOpenCustomHashSet<>(strategy), ObjectLinkedOpenCustomHashSet::add, ObjectLinkedOpenCustomHashSet::merge); + } + + private ObjectLinkedOpenCustomHashSet merge(ObjectLinkedOpenCustomHashSet a) { + addAll(a); + return this; + } + @Override public void addFirst(T o) { if(strategy.equals(o, null)) { diff --git a/src/main/java/speiger/src/collections/objects/sets/ObjectLinkedOpenHashSet.java b/src/main/java/speiger/src/collections/objects/sets/ObjectLinkedOpenHashSet.java index fd988ee..ace32fc 100644 --- a/src/main/java/speiger/src/collections/objects/sets/ObjectLinkedOpenHashSet.java +++ b/src/main/java/speiger/src/collections/objects/sets/ObjectLinkedOpenHashSet.java @@ -6,6 +6,8 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.function.Consumer; import java.util.function.BiFunction; import java.util.function.Predicate; @@ -164,6 +166,29 @@ public class ObjectLinkedOpenHashSet extends ObjectOpenHashSet implements while(iterator.hasNext()) add(iterator.next()); } + /** + * Creates a Collector for a LinkedHashSet + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectLinkedOpenHashSet> toLinkedSet() { + return Collector.of(ObjectLinkedOpenHashSet::new, ObjectLinkedOpenHashSet::add, ObjectLinkedOpenHashSet::merge); + } + + /** + * Collects a Stream to a LinkedHashSet + * @param the keyType of elements maintained by this Collection + * @return a set with the contents of the Stream + */ + public static ObjectLinkedOpenHashSet toLinkedSet(Stream stream) { + return stream.collect(ObjectLinkedOpenHashSet::new, ObjectLinkedOpenHashSet::add, ObjectLinkedOpenHashSet::merge); + } + + private ObjectLinkedOpenHashSet merge(ObjectLinkedOpenHashSet a) { + addAll(a); + return this; + } + @Override public void addFirst(T o) { if(o == null) { diff --git a/src/main/java/speiger/src/collections/objects/sets/ObjectOpenCustomHashSet.java b/src/main/java/speiger/src/collections/objects/sets/ObjectOpenCustomHashSet.java index 7115958..11b3335 100644 --- a/src/main/java/speiger/src/collections/objects/sets/ObjectOpenCustomHashSet.java +++ b/src/main/java/speiger/src/collections/objects/sets/ObjectOpenCustomHashSet.java @@ -7,6 +7,8 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.function.Consumer; import java.util.function.BiFunction; import java.util.function.Predicate; @@ -211,6 +213,29 @@ public class ObjectOpenCustomHashSet extends AbstractObjectSet implements while(iterator.hasNext()) add(iterator.next()); } + /** + * Creates a Collector for a CustomHashSet + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectOpenCustomHashSet> toSet(ObjectStrategy strategy) { + return Collector.of(() -> new ObjectOpenCustomHashSet<>(strategy), ObjectOpenCustomHashSet::add, ObjectOpenCustomHashSet::merge); + } + + /** + * Collects a Stream to a CustomHashSet + * @param the keyType of elements maintained by this Collection + * @return a set with the contents of the Stream + */ + public static ObjectOpenCustomHashSet toSet(Stream stream, ObjectStrategy strategy) { + return stream.collect(() -> new ObjectOpenCustomHashSet<>(strategy), ObjectOpenCustomHashSet::add, ObjectOpenCustomHashSet::merge); + } + + private ObjectOpenCustomHashSet merge(ObjectOpenCustomHashSet a) { + addAll(a); + return this; + } + /** * Helper getter function to get the current strategy * @return the current strategy diff --git a/src/main/java/speiger/src/collections/objects/sets/ObjectOpenHashSet.java b/src/main/java/speiger/src/collections/objects/sets/ObjectOpenHashSet.java index da3e31b..5a16785 100644 --- a/src/main/java/speiger/src/collections/objects/sets/ObjectOpenHashSet.java +++ b/src/main/java/speiger/src/collections/objects/sets/ObjectOpenHashSet.java @@ -7,6 +7,8 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.function.Consumer; import java.util.function.BiFunction; import java.util.function.Predicate; @@ -182,6 +184,29 @@ public class ObjectOpenHashSet extends AbstractObjectSet implements ITrimm while(iterator.hasNext()) add(iterator.next()); } + /** + * Creates a Collector for a HashSet + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectOpenHashSet> toSet() { + return Collector.of(ObjectOpenHashSet::new, ObjectOpenHashSet::add, ObjectOpenHashSet::merge); + } + + /** + * Collects a Stream to a HashSet + * @param the keyType of elements maintained by this Collection + * @return a set with the contents of the Stream + */ + public static ObjectOpenHashSet toSet(Stream stream) { + return stream.collect(ObjectOpenHashSet::new, ObjectOpenHashSet::add, ObjectOpenHashSet::merge); + } + + private ObjectOpenHashSet merge(ObjectOpenHashSet a) { + addAll(a); + return this; + } + @Override public boolean add(T o) { if(o == null) { diff --git a/src/main/java/speiger/src/collections/objects/sets/ObjectRBTreeSet.java b/src/main/java/speiger/src/collections/objects/sets/ObjectRBTreeSet.java index 6f9ad61..1f6d38b 100644 --- a/src/main/java/speiger/src/collections/objects/sets/ObjectRBTreeSet.java +++ b/src/main/java/speiger/src/collections/objects/sets/ObjectRBTreeSet.java @@ -3,6 +3,8 @@ package speiger.src.collections.objects.sets; import java.util.Collection; import java.util.Collections; import java.util.Optional; +import java.util.stream.Stream; +import java.util.stream.Collector; import java.util.Comparator; import java.util.function.Consumer; import java.util.function.BiFunction; @@ -179,6 +181,29 @@ public class ObjectRBTreeSet extends AbstractObjectSet implements ObjectNa while(iterator.hasNext()) add(iterator.next()); } + /** + * Creates a Collector for a RBTreeSet + * @param the keyType of elements maintained by this Collection + * @return a collector + */ + public static Collector, ObjectRBTreeSet> toSet() { + return Collector.of(ObjectRBTreeSet::new, ObjectRBTreeSet::add, ObjectRBTreeSet::merge); + } + + /** + * Collects a Stream to a RBTreeSet + * @param the keyType of elements maintained by this Collection + * @return a set with the contents of the Stream + */ + public static ObjectRBTreeSet toSet(Stream stream) { + return stream.collect(ObjectRBTreeSet::new, ObjectRBTreeSet::add, ObjectRBTreeSet::merge); + } + + private ObjectRBTreeSet merge(ObjectRBTreeSet a) { + addAll(a); + return this; + } + /** only used for primitives * @return null */ diff --git a/src/main/java/speiger/src/collections/objects/utils/ObjectAsyncBuilder.java b/src/main/java/speiger/src/collections/objects/utils/ObjectAsyncBuilder.java index 67c70dc..e1b20ef 100644 --- a/src/main/java/speiger/src/collections/objects/utils/ObjectAsyncBuilder.java +++ b/src/main/java/speiger/src/collections/objects/utils/ObjectAsyncBuilder.java @@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.LockSupport; import java.util.function.Consumer; +import java.util.Optional; import java.util.function.IntFunction; import java.util.function.BiFunction; import java.util.Comparator; @@ -288,9 +289,8 @@ public class ObjectAsyncBuilder * @param operator that reduces the elements. * @return self with the reduce action applied */ - public ObjectAsyncBuilder reduce(ObjectObjectUnaryOperator operator) { - task = new SimpleReduceTask<>(iterable.iterator(), operator); - return this; + public ObjectAsyncBuilder> reduce(ObjectObjectUnaryOperator operator) { + return new ObjectAsyncBuilder<>(new SimpleReduceTask<>(iterable.iterator(), operator)); } /** @@ -371,9 +371,8 @@ public class ObjectAsyncBuilder * @param filter that decides the desired elements * @return self with the findFirst function applied */ - public ObjectAsyncBuilder findFirst(Predicate filter) { - task = new FindFirstTask<>(iterable.iterator(), filter); - return this; + public ObjectAsyncBuilder> findFirst(Predicate filter) { + return new ObjectAsyncBuilder<>(new FindFirstTask<>(iterable.iterator(), filter)); } /** @@ -484,7 +483,7 @@ public class ObjectAsyncBuilder } } - private static class SimpleReduceTask extends BaseObjectTask + private static class SimpleReduceTask extends BaseObjectTask> { ObjectIterator iter; ObjectObjectUnaryOperator operator; @@ -494,6 +493,7 @@ public class ObjectAsyncBuilder public SimpleReduceTask(ObjectIterator iter, ObjectObjectUnaryOperator operator) { this.iter = iter; this.operator = operator; + this.setResult(Optional.empty()); } @Override @@ -508,7 +508,7 @@ public class ObjectAsyncBuilder } } if(!iter.hasNext()) { - setResult(value); + setResult(Optional.ofNullable(value)); return true; } return false; @@ -579,7 +579,7 @@ public class ObjectAsyncBuilder } } - private static class FindFirstTask extends BaseObjectTask + private static class FindFirstTask extends BaseObjectTask> { ObjectIterator iter; Predicate filter; @@ -587,6 +587,7 @@ public class ObjectAsyncBuilder public FindFirstTask(ObjectIterator iter, Predicate filter) { this.iter = iter; this.filter = filter; + this.setResult(Optional.empty()); } @Override @@ -594,7 +595,7 @@ public class ObjectAsyncBuilder while(shouldRun() && iter.hasNext()) { T entry = iter.next(); if(filter.test(iter.next())) { - setResult(entry); + setResult(Optional.ofNullable(entry)); return true; } } diff --git a/src/main/java/speiger/src/collections/objects/utils/ObjectCollections.java b/src/main/java/speiger/src/collections/objects/utils/ObjectCollections.java index b3e940a..9dd93b4 100644 --- a/src/main/java/speiger/src/collections/objects/utils/ObjectCollections.java +++ b/src/main/java/speiger/src/collections/objects/utils/ObjectCollections.java @@ -114,7 +114,10 @@ public class ObjectCollections return new SingletonCollection<>(element); } - protected static CollectionWrapper wrapper() { + /** + * Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed. + */ + public static CollectionWrapper wrapper() { return new CollectionWrapper<>(); } diff --git a/src/main/java/speiger/src/collections/shorts/lists/CopyOnWriteShortArrayList.java b/src/main/java/speiger/src/collections/shorts/lists/CopyOnWriteShortArrayList.java index 93a9cc6..081dd18 100644 --- a/src/main/java/speiger/src/collections/shorts/lists/CopyOnWriteShortArrayList.java +++ b/src/main/java/speiger/src/collections/shorts/lists/CopyOnWriteShortArrayList.java @@ -111,7 +111,6 @@ public class CopyOnWriteShortArrayList extends AbstractShortList implements ITri System.arraycopy(a, offset, data, 0, length); } - private void setArray(short[] data) { this.data = data; } diff --git a/src/main/java/speiger/src/collections/shorts/lists/ImmutableShortList.java b/src/main/java/speiger/src/collections/shorts/lists/ImmutableShortList.java index b63c483..dff0f70 100644 --- a/src/main/java/speiger/src/collections/shorts/lists/ImmutableShortList.java +++ b/src/main/java/speiger/src/collections/shorts/lists/ImmutableShortList.java @@ -1,12 +1,15 @@ package speiger.src.collections.shorts.lists; import java.util.Arrays; +import java.util.stream.IntStream; +import java.util.stream.StreamSupport; import java.util.Collection; import java.util.NoSuchElementException; import java.util.Objects; import java.util.function.Predicate; import java.util.function.UnaryOperator; -import java.util.function.IntPredicate;import java.util.function.IntUnaryOperator; +import java.util.function.IntPredicate; +import java.util.function.IntUnaryOperator; import speiger.src.collections.shorts.collections.ShortCollection; import speiger.src.collections.shorts.functions.ShortComparator; @@ -18,8 +21,6 @@ import speiger.src.collections.shorts.functions.function.ShortPredicate; import speiger.src.collections.shorts.functions.function.ShortShortUnaryOperator; import speiger.src.collections.objects.utils.ObjectArrays; import speiger.src.collections.shorts.utils.ShortIterators; -import java.util.stream.IntStream; -import java.util.stream.StreamSupport; import speiger.src.collections.shorts.collections.ShortSplititerator; import speiger.src.collections.shorts.utils.ShortSplititerators; import speiger.src.collections.utils.SanityChecks; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2BooleanLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2BooleanLinkedOpenCustomHashMap.java index 941e611..0f46aec 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2BooleanLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2BooleanLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto if(strategy.equals(keys[pos], key)) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto if(isEmpty() || strategy.equals(firstShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto if(isEmpty() || strategy.equals(lastShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto public boolean getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto public boolean getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Short2BooleanLinkedOpenCustomHashMap extends Short2BooleanOpenCusto firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ByteLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ByteLinkedOpenCustomHashMap.java index 4fe7585..7bb303a 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ByteLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ByteLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM if(strategy.equals(keys[pos], key)) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM if(isEmpty() || strategy.equals(firstShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM if(isEmpty() || strategy.equals(lastShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM public byte getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM public byte getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Short2ByteLinkedOpenCustomHashMap extends Short2ByteOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2CharLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2CharLinkedOpenCustomHashMap.java index 2f4abf2..b8fb567 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2CharLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2CharLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM if(strategy.equals(keys[pos], key)) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM if(isEmpty() || strategy.equals(firstShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM if(isEmpty() || strategy.equals(lastShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM public char getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM public char getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Short2CharLinkedOpenCustomHashMap extends Short2CharOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2DoubleLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2DoubleLinkedOpenCustomHashMap.java index db11bb0..46e38f6 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2DoubleLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2DoubleLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH if(strategy.equals(keys[pos], key)) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH if(isEmpty() || strategy.equals(firstShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH if(isEmpty() || strategy.equals(lastShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH public double getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH public double getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Short2DoubleLinkedOpenCustomHashMap extends Short2DoubleOpenCustomH firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2FloatLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2FloatLinkedOpenCustomHashMap.java index 6c5d143..26682ea 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2FloatLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2FloatLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas if(strategy.equals(keys[pos], key)) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas if(isEmpty() || strategy.equals(firstShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas if(isEmpty() || strategy.equals(lastShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas public float getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas public float getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Short2FloatLinkedOpenCustomHashMap extends Short2FloatOpenCustomHas firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2IntLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2IntLinkedOpenCustomHashMap.java index b4d832b..dd6b5d8 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2IntLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2IntLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap if(strategy.equals(keys[pos], key)) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap if(isEmpty() || strategy.equals(firstShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap if(isEmpty() || strategy.equals(lastShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap public int getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap public int getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Short2IntLinkedOpenCustomHashMap extends Short2IntOpenCustomHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2LongLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2LongLinkedOpenCustomHashMap.java index 939e4dd..94ea538 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2LongLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2LongLinkedOpenCustomHashMap.java @@ -199,13 +199,13 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -213,7 +213,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -221,7 +221,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -233,13 +233,13 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -247,7 +247,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM if(strategy.equals(keys[pos], key)) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -255,7 +255,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -268,7 +268,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -279,7 +279,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -292,7 +292,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -303,7 +303,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -314,7 +314,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM if(isEmpty() || strategy.equals(firstShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -322,7 +322,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -336,7 +336,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM if(isEmpty() || strategy.equals(lastShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -344,7 +344,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -357,7 +357,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM public long getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -365,7 +365,7 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM public long getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -541,8 +541,8 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -559,8 +559,8 @@ public class Short2LongLinkedOpenCustomHashMap extends Short2LongOpenCustomHashM firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ObjectLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ObjectLinkedOpenCustomHashMap.java index bd9469d..86de880 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ObjectLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ObjectLinkedOpenCustomHashMap.java @@ -193,13 +193,13 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -207,7 +207,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -215,7 +215,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -227,13 +227,13 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -241,7 +241,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust if(strategy.equals(keys[pos], key)) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -249,7 +249,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -262,7 +262,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -273,7 +273,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -286,7 +286,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -297,7 +297,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -308,7 +308,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust if(isEmpty() || strategy.equals(firstShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -316,7 +316,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -330,7 +330,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust if(isEmpty() || strategy.equals(lastShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -338,7 +338,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -351,7 +351,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust public V getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -359,7 +359,7 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust public V getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -535,8 +535,8 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -553,8 +553,8 @@ public class Short2ObjectLinkedOpenCustomHashMap extends Short2ObjectOpenCust firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ShortLinkedOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ShortLinkedOpenCustomHashMap.java index 03fabb3..7db85d3 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ShortLinkedOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ShortLinkedOpenCustomHashMap.java @@ -191,13 +191,13 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -205,7 +205,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -213,7 +213,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -225,13 +225,13 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -239,7 +239,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas if(strategy.equals(keys[pos], key)) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -247,7 +247,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -260,7 +260,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -271,7 +271,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -284,7 +284,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(strategy.hashCode(key)) & mask; @@ -295,7 +295,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -306,7 +306,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas if(isEmpty() || strategy.equals(firstShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -314,7 +314,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas if(isEmpty() || strategy.equals(lastShortKey(), key)) return false; if(strategy.equals(key, (short)0)) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -336,7 +336,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas int pos = HashUtil.mix(strategy.hashCode(key)) & mask; while(!strategy.equals(keys[pos], (short)0)) { if(strategy.equals(keys[pos], key)) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -349,7 +349,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas public short getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -357,7 +357,7 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas public short getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -533,8 +533,8 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -551,8 +551,8 @@ public class Short2ShortLinkedOpenCustomHashMap extends Short2ShortOpenCustomHas firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2BooleanLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2BooleanLinkedOpenHashMap.java index eab1c13..db56e8f 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2BooleanLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2BooleanLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp if(keys[pos] == key) { boolean lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp if(containsNull) { boolean lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp if(keys[pos] == key) { boolean lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp if(isEmpty() || firstShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp if(isEmpty() || lastShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp public boolean getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp public boolean getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Short2BooleanLinkedOpenHashMap extends Short2BooleanOpenHashMap imp firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ByteLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ByteLinkedOpenHashMap.java index 1184410..01cb7b8 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ByteLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ByteLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement if(keys[pos] == key) { byte lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement if(containsNull) { byte lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement if(keys[pos] == key) { byte lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement if(isEmpty() || firstShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement if(isEmpty() || lastShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement public byte getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement public byte getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Short2ByteLinkedOpenHashMap extends Short2ByteOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2CharLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2CharLinkedOpenHashMap.java index b786dce..74efd3a 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2CharLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2CharLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement if(keys[pos] == key) { char lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement if(containsNull) { char lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement if(keys[pos] == key) { char lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement if(isEmpty() || firstShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement if(isEmpty() || lastShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement public char getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement public char getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Short2CharLinkedOpenHashMap extends Short2CharOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2DoubleLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2DoubleLinkedOpenHashMap.java index 97cb633..59082bb 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2DoubleLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2DoubleLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple if(keys[pos] == key) { double lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple if(containsNull) { double lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple if(keys[pos] == key) { double lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple if(isEmpty() || firstShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple if(isEmpty() || lastShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple public double getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple public double getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Short2DoubleLinkedOpenHashMap extends Short2DoubleOpenHashMap imple firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2FloatLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2FloatLinkedOpenHashMap.java index d48b268..a8aef0d 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2FloatLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2FloatLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme if(keys[pos] == key) { float lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme if(containsNull) { float lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme if(keys[pos] == key) { float lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme if(isEmpty() || firstShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme if(isEmpty() || lastShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme public float getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme public float getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Short2FloatLinkedOpenHashMap extends Short2FloatOpenHashMap impleme firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2IntLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2IntLinkedOpenHashMap.java index c81efb4..25e8242 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2IntLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2IntLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements if(keys[pos] == key) { int lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements if(containsNull) { int lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements if(keys[pos] == key) { int lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements if(isEmpty() || firstShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements if(isEmpty() || lastShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements public int getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements public int getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Short2IntLinkedOpenHashMap extends Short2IntOpenHashMap implements firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2LongLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2LongLinkedOpenHashMap.java index 04abf02..ef1e1e1 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2LongLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2LongLinkedOpenHashMap.java @@ -176,13 +176,13 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -190,7 +190,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement if(keys[pos] == key) { long lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -198,7 +198,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -210,13 +210,13 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement if(containsNull) { long lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -224,7 +224,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement if(keys[pos] == key) { long lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -232,7 +232,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -245,7 +245,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -256,7 +256,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -269,7 +269,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -280,7 +280,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -291,7 +291,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement if(isEmpty() || firstShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -299,7 +299,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -313,7 +313,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement if(isEmpty() || lastShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -321,7 +321,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -334,7 +334,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement public long getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -342,7 +342,7 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement public long getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -539,8 +539,8 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -557,8 +557,8 @@ public class Short2LongLinkedOpenHashMap extends Short2LongOpenHashMap implement firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ObjectLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ObjectLinkedOpenHashMap.java index c18efd4..c6c86e3 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ObjectLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ObjectLinkedOpenHashMap.java @@ -170,13 +170,13 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -184,7 +184,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap if(keys[pos] == key) { V lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -192,7 +192,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -204,13 +204,13 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap if(containsNull) { V lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -218,7 +218,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap if(keys[pos] == key) { V lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -226,7 +226,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -239,7 +239,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -250,7 +250,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -263,7 +263,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -274,7 +274,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -285,7 +285,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap if(isEmpty() || firstShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -293,7 +293,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -307,7 +307,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap if(isEmpty() || lastShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -315,7 +315,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -328,7 +328,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap public V getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -336,7 +336,7 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap public V getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -522,8 +522,8 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -540,8 +540,8 @@ public class Short2ObjectLinkedOpenHashMap extends Short2ObjectOpenHashMap firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ShortLinkedOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ShortLinkedOpenHashMap.java index 5f429a1..7e1f647 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ShortLinkedOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ShortLinkedOpenHashMap.java @@ -168,13 +168,13 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -182,7 +182,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme if(keys[pos] == key) { short lastValue = values[pos]; values[pos] = value; - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -190,7 +190,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -202,13 +202,13 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme if(containsNull) { short lastValue = values[nullIndex]; values[nullIndex] = value; - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return lastValue; } values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -216,7 +216,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme if(keys[pos] == key) { short lastValue = values[pos]; values[pos] = value; - moveToLastIndex(pos); + moveToLastIndex(pos, false); return lastValue; } pos = ++pos & mask; @@ -224,7 +224,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -237,7 +237,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -248,7 +248,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToFirstIndex(pos); + moveToFirstIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -261,7 +261,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme values[nullIndex] = value; containsNull = true; onNodeAdded(nullIndex); - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, true); } else { int pos = HashUtil.mix(Short.hashCode(key)) & mask; @@ -272,7 +272,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme keys[pos] = key; values[pos] = value; onNodeAdded(pos); - moveToLastIndex(pos); + moveToLastIndex(pos, true); } if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor)); return getDefaultReturnValue(); @@ -283,7 +283,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme if(isEmpty() || firstShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToFirstIndex(nullIndex); + moveToFirstIndex(nullIndex, false); return true; } } @@ -291,7 +291,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToFirstIndex(pos); + moveToFirstIndex(pos, false); return true; } pos = ++pos & mask; @@ -305,7 +305,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme if(isEmpty() || lastShortKey() == key) return false; if(key == (short)0) { if(containsNull) { - moveToLastIndex(nullIndex); + moveToLastIndex(nullIndex, false); return true; } } @@ -313,7 +313,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme int pos = HashUtil.mix(Short.hashCode(key)) & mask; while(keys[pos] != (short)0) { if(keys[pos] == key) { - moveToLastIndex(pos); + moveToLastIndex(pos, false); return true; } pos = ++pos & mask; @@ -326,7 +326,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme public short getAndMoveToFirst(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToFirstIndex(index); + moveToFirstIndex(index, false); return values[index]; } @@ -334,7 +334,7 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme public short getAndMoveToLast(short key) { int index = findIndex(key); if(index < 0) return getDefaultReturnValue(); - moveToLastIndex(index); + moveToLastIndex(index, false); return values[index]; } @@ -531,8 +531,8 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme containsNull = false; } - protected void moveToFirstIndex(int startPos) { - if(size == 1 || firstIndex == startPos) return; + protected void moveToFirstIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || firstIndex == startPos) return; if(lastIndex == startPos) { lastIndex = (int)(links[startPos] >>> 32); links[lastIndex] |= 0xFFFFFFFFL; @@ -549,8 +549,8 @@ public class Short2ShortLinkedOpenHashMap extends Short2ShortOpenHashMap impleme firstIndex = startPos; } - protected void moveToLastIndex(int startPos) { - if(size == 1 || lastIndex == startPos) return; + protected void moveToLastIndex(int startPos, boolean adding) { + if(size == (adding ? 0 : 1) || lastIndex == startPos) return; if(firstIndex == startPos) { firstIndex = (int)links[startPos]; links[lastIndex] |= 0xFFFFFFFF00000000L; diff --git a/src/main/java/speiger/src/collections/shorts/queues/ShortArrayPriorityQueue.java b/src/main/java/speiger/src/collections/shorts/queues/ShortArrayPriorityQueue.java index 182663e..6000bbb 100644 --- a/src/main/java/speiger/src/collections/shorts/queues/ShortArrayPriorityQueue.java +++ b/src/main/java/speiger/src/collections/shorts/queues/ShortArrayPriorityQueue.java @@ -174,7 +174,6 @@ public class ShortArrayPriorityQueue extends AbstractShortPriorityQueue queue.size = size; return queue; } - @Override public void enqueue(short e) { if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (long)(array.length >> 1), (long)SanityChecks.MAX_ARRAY_SIZE), size+1)); diff --git a/src/main/java/speiger/src/collections/shorts/sets/ShortArraySet.java b/src/main/java/speiger/src/collections/shorts/sets/ShortArraySet.java index d19baed..6b349b3 100644 --- a/src/main/java/speiger/src/collections/shorts/sets/ShortArraySet.java +++ b/src/main/java/speiger/src/collections/shorts/sets/ShortArraySet.java @@ -55,7 +55,7 @@ public class ShortArraySet extends AbstractShortSet implements ShortOrderedSet * @param array the array that should be used for set. */ public ShortArraySet(short[] array) { - this(array, array.length); + this(array, 0, array.length); } /** @@ -69,6 +69,18 @@ public class ShortArraySet extends AbstractShortSet implements ShortOrderedSet addAll(array, length); } + /** + * Constructur using initial Array + * @param array the array that should be used for set. + * @param offset the starting offset of where the array should be copied from + * @param length the amount of elements present within the array + * @throws NegativeArraySizeException if the length is negative + */ + public ShortArraySet(short[] array, int offset, int length) { + this(length); + addAll(array, offset, length); + } + /** * A Helper constructor that allows to create a Set with exactly the same values as the provided collection. * @param c the elements that should be added to the set. diff --git a/src/main/java/speiger/src/collections/shorts/utils/ShortAsyncBuilder.java b/src/main/java/speiger/src/collections/shorts/utils/ShortAsyncBuilder.java index 47ea834..cf65a33 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/ShortAsyncBuilder.java +++ b/src/main/java/speiger/src/collections/shorts/utils/ShortAsyncBuilder.java @@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.LockSupport; import java.util.function.Consumer; +import speiger.src.collections.shorts.functions.OptionalShort; import speiger.src.collections.shorts.functions.ShortConsumer; import speiger.src.collections.shorts.functions.ShortComparator; @@ -210,9 +211,8 @@ public class ShortAsyncBuilder * @param operator that reduces the elements. * @return self with the reduce action applied */ - public ShortAsyncBuilder reduce(ShortShortUnaryOperator operator) { - task = new SimpleReduceTask(iterable.iterator(), operator); - return this; + public ObjectAsyncBuilder reduce(ShortShortUnaryOperator operator) { + return new ObjectAsyncBuilder<>(new SimpleReduceTask(iterable.iterator(), operator)); } /** @@ -292,9 +292,8 @@ public class ShortAsyncBuilder * @param filter that decides the desired elements * @return self with the findFirst function applied */ - public ShortAsyncBuilder findFirst(ShortPredicate filter) { - task = new FindFirstTask(iterable.iterator(), filter); - return this; + public ObjectAsyncBuilder findFirst(ShortPredicate filter) { + return new ObjectAsyncBuilder<>(new FindFirstTask(iterable.iterator(), filter)); } /** @@ -404,7 +403,7 @@ public class ShortAsyncBuilder } } - private static class SimpleReduceTask extends BaseShortTask + private static class SimpleReduceTask extends BaseObjectTask { ShortIterator iter; ShortShortUnaryOperator operator; @@ -414,6 +413,7 @@ public class ShortAsyncBuilder public SimpleReduceTask(ShortIterator iter, ShortShortUnaryOperator operator) { this.iter = iter; this.operator = operator; + this.setResult(OptionalShort.empty()); } @Override @@ -428,7 +428,7 @@ public class ShortAsyncBuilder } } if(!iter.hasNext()) { - setResult(value); + setResult(OptionalShort.of(value)); return true; } return false; @@ -498,7 +498,7 @@ public class ShortAsyncBuilder } } - private static class FindFirstTask extends BaseShortTask + private static class FindFirstTask extends BaseObjectTask { ShortIterator iter; ShortPredicate filter; @@ -506,6 +506,7 @@ public class ShortAsyncBuilder public FindFirstTask(ShortIterator iter, ShortPredicate filter) { this.iter = iter; this.filter = filter; + this.setResult(OptionalShort.empty()); } @Override @@ -513,7 +514,7 @@ public class ShortAsyncBuilder while(shouldRun() && iter.hasNext()) { short entry = iter.nextShort(); if(filter.test(iter.nextShort())) { - setResult(entry); + setResult(OptionalShort.of(entry)); return true; } } diff --git a/src/main/java/speiger/src/collections/shorts/utils/ShortCollections.java b/src/main/java/speiger/src/collections/shorts/utils/ShortCollections.java index 794057c..e2942ed 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/ShortCollections.java +++ b/src/main/java/speiger/src/collections/shorts/utils/ShortCollections.java @@ -109,7 +109,10 @@ public class ShortCollections return new SingletonCollection(element); } - protected static CollectionWrapper wrapper() { + /** + * Internal Use mainly. Its a collection wrapper with 0 dependencies for those actions where a collector is needed. + */ + public static CollectionWrapper wrapper() { return new CollectionWrapper(); }