From 78dfa286b0081ca198180f3fad8528905d6152b2 Mon Sep 17 00:00:00 2001 From: Speiger Date: Thu, 16 Dec 2021 13:46:55 +0100 Subject: [PATCH] New Version - Fixed: Bugs with Queues starting with the wrong size - Fixed: ArrayGrowth for Queues was +1 instead of +50% - Added: Benchmarks with java and FastUtil --- Changelog.md | 5 +++++ build.gradle | 2 +- .../collections/templates/maps/impl/misc/ArrayMap.template | 2 +- .../collections/templates/queues/ArrayFIFOQueue.template | 4 ++-- .../collections/templates/queues/ArrayPriorityQueue.template | 4 ++-- .../collections/templates/queues/HeapPriorityQueue.template | 4 ++-- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Changelog.md b/Changelog.md index 2704742..41bc646 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,10 @@ # Changelog of versions +### Version 0.5.2 +- Fixed: Bugs with Queues starting with the wrong size +- Fixed: ArrayGrowth for Queues was +1 instead of +50% +- Added: Benchmarks with java and FastUtil + ### Version 0.5.1 - Fixed: Reworked the NavigableSet/Map implementations of RBTree/AVLTree/Array Sets/Maps so they are now deemed stable. - Added: Another 150k Unit tests. diff --git a/build.gradle b/build.gradle index afd86fc..fcd8464 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ repositories { } archivesBaseName = 'Primitive Collections' -version = '0.5.1'; +version = '0.5.2'; sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template index c400abd..ebef006 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template @@ -641,7 +641,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN protected void grow(int newSize) { if(newSize < keys.length) return; - newSize = Math.min(newSize, keys.length == 0 ? 2 : keys.length * 2); + newSize = Math.max(newSize, keys.length == 0 ? 2 : keys.length * 2); keys = Arrays.copyOf(keys, newSize); values = Arrays.copyOf(values, newSize); } 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 d9001a5..6e0fc2c 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template @@ -114,8 +114,8 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K @Override public void enqueue(KEY_TYPE e) { - array[last] = e; - last = ++last % array.length; + array[last++] = e; + if(last == array.length) last = 0; if(last == first) expand(); } 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 d03b005..537fe90 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template @@ -19,6 +19,7 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.utils.ARRAYS; +import speiger.src.collections.utils.SanityChecks; /** * A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases. @@ -70,7 +71,6 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE public ARRAY_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { if(size < 0) throw new IllegalAccessError("Size has to be 0 or positive"); if(size > 0) array = NEW_KEY_ARRAY(size); - this.size = size; comparator = comp; } @@ -187,7 +187,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE @Override public void enqueue(KEY_TYPE e) { - if(size == array.length) array = Arrays.copyOf(array, size+1); + if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (array.length >> 1), SanityChecks.MAX_ARRAY_SIZE), size+1)); if(firstIndex != -1){ int compare = comparator == null ? COMPAREABLE_TO_KEY(e, array[firstIndex]) : comparator.compare(e, array[firstIndex]); if(compare < 0) firstIndex = size; 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 8ba9021..82d4f44 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template @@ -19,6 +19,7 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.utils.ARRAYS; +import speiger.src.collections.utils.SanityChecks; /** * A Simple Heap base Priority Queue implementation @@ -66,7 +67,6 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU */ public HEAP_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { if(size > 0) array = NEW_KEY_ARRAY(size); - this.size = size; comparator = comp; } @@ -207,7 +207,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU @Override public void enqueue(KEY_TYPE e) { - if(size == array.length) array = Arrays.copyOf(array, size + 1); + if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (array.length >> 1), SanityChecks.MAX_ARRAY_SIZE), size+1)); array[size++] = e; ARRAYS.shiftUp(array, size-1, comparator); }