From 357b40e6701189bbd04f9d703033a0fdebcb3f6c Mon Sep 17 00:00:00 2001 From: Speiger Date: Wed, 23 Jun 2021 19:22:19 +0200 Subject: [PATCH] PriorityQueues no longer extends Object Variant. --- Changelog.md | 5 ++- README.md | 5 +++ .../templates/queues/ArrayFIFOQueue.template | 25 ++----------- .../queues/ArrayPriorityQueue.template | 15 ++------ .../queues/HeapPriorityQueue.template | 15 ++------ .../templates/queues/PriorityDequeue.template | 27 +------------- .../templates/queues/PriorityQueue.template | 37 +++---------------- .../ints/base/BaseIntPriorityQueueTest.java | 25 +++++-------- 8 files changed, 33 insertions(+), 121 deletions(-) diff --git a/Changelog.md b/Changelog.md index 15142f8f..3853c22d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,8 +1,9 @@ # Changelog of versions -## Version 0.3.0 +## Version 0.3.0 (Breaking 0.2.0) - Added: Stack.isEmpty was missing - Changed: remove/removeLast/enqueue/enqueueFirst no longer use Type Suffixes - Removed: Suffixes for unmodifiable & synchronize functions. -- Changed: Primitive Stacks no longer depend on the base Stack class. Because seriously not needed. \ No newline at end of file +- Changed: Primitive Stacks no longer depend on the base Stack class. Because seriously not needed. +- Changed: PriorityQueues no longer extends Object Variant. \ No newline at end of file diff --git a/README.md b/README.md index 9f1e71e5..95657349 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,11 @@ But its focus is a different one. - SplitIterators - Iterators +# Notes about Versions +Any 0.x.0 version (Minor) can be reason for massive changes including API. +To ensure that problems can be dealt with even if it is breaking the current API. +Any breaking changes will be Documented (once 1.0 is released) + # How to install Using Gradle: ```gradle 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 6d5a491a..fbe8d2c5 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template @@ -115,7 +115,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G } @Override - public KEY_TYPE DEQUEUE() { + public KEY_TYPE dequeue() { if(first == last) throw new NoSuchElementException(); KEY_TYPE data = array[first]; #if TYPE_OBJECT @@ -127,7 +127,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G } @Override - public KEY_TYPE DEQUEUE_LAST() { + public KEY_TYPE dequeueLast() { if(first == last) throw new NoSuchElementException(); if(last == 0) last = array.length; KEY_TYPE data = array[--last]; @@ -139,7 +139,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G } @Override - public KEY_TYPE PEEK(int index) { + public KEY_TYPE peek(int index) { if(first == last || index < 0 || index > size()) throw new NoSuchElementException(); return array[(first + index) % array.length]; } @@ -264,25 +264,6 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G return input; } -#if !TYPE_OBJECT - @Override - public CLASS_TYPE[] toArray(CLASS_TYPE[] input) { - if(input == null || input.length < size()) input = NEW_CLASS_ARRAY(size()); - if (first <= last) { - for(int i = 0,m=last-first;i MIN_CAPACITY && size <= array.length / 4) resize(size, array.length / 2); 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 fea0b135..a63f51ad 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template @@ -191,7 +191,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY } @Override - public KEY_TYPE DEQUEUE() { + public KEY_TYPE dequeue() { if(size <= 0) throw new NoSuchElementException(); int index = findFirstIndex(); KEY_TYPE value = array[index]; @@ -204,7 +204,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY } @Override - public KEY_TYPE PEEK(int index) { + public KEY_TYPE peek(int index) { if(index < 0 || index >= size) throw new NoSuchElementException(); return array[index]; } @@ -268,15 +268,6 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY return input; } -#if !TYPE_OBJECT - @Override - public CLASS_TYPE[] toArray(CLASS_TYPE[] input) { - if(input == null || input.length < size()) input = new CLASS_TYPE[size()]; - for(int i = 0;i= size) throw new NoSuchElementException(); return array[index]; } @@ -265,15 +265,6 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_ return input; } -#if !TYPE_OBJECT - @Override - public CLASS_TYPE[] toArray(CLASS_TYPE[] input) { - if(input == null || input.length < size()) input = new CLASS_TYPE[size()]; - for(int i = 0;i #else -public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue, ITERABLE KEY_GENERIC_TYPE +public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TYPE #endif { -#if TYPE_OBJECT /** * @return true if the PriorityQueue is empty */ @@ -33,7 +31,6 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue= 0 && value < 100); } } else { for(int i = 0;i<100;i++) { - Assert.assertEquals(i, queue.peekInt(i)); + Assert.assertEquals(i, queue.peek(i)); } } } @@ -68,16 +68,16 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest } queue.remove(40); for(int i = 0;i<99;i++) { - if(i >= 40) Assert.assertEquals(i + 1, queue.dequeueInt()); - else Assert.assertEquals(i, queue.dequeueInt()); + if(i >= 40) Assert.assertEquals(i + 1, queue.dequeue()); + else Assert.assertEquals(i, queue.dequeue()); } for(int i = 0;i<100;i++) { queue.enqueue(i); } queue.removeLast(40); for(int i = 0;i<99;i++) { - if(i >= 40) Assert.assertEquals(i + 1, queue.dequeueInt()); - else Assert.assertEquals(i, queue.dequeueInt()); + if(i >= 40) Assert.assertEquals(i + 1, queue.dequeue()); + else Assert.assertEquals(i, queue.dequeue()); } } } @@ -102,28 +102,21 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest Assert.assertArrayEquals(array, nonData); } else { - Integer[] ref = IntArrays.wrap(TEST_ARRAY); - Integer[] shiftArray = new Integer[100]; int[] shiftPrimArray = new int[100]; for(int i = 0; i < 100; i++) { queue.enqueue(i); shiftPrimArray[(i+80) % 100] = i; - shiftArray[(i+80) % 100] = Integer.valueOf(i); } - Assert.assertArrayEquals(ref, queue.toArray()); - Assert.assertArrayEquals(ref, queue.toArray(new Integer[100])); - Assert.assertArrayEquals(ref, queue.toArray(null)); Assert.assertArrayEquals(TEST_ARRAY, queue.toIntArray()); Assert.assertArrayEquals(TEST_ARRAY, queue.toIntArray(new int[100])); Assert.assertArrayEquals(TEST_ARRAY, queue.toIntArray(null)); IntPriorityQueue other = create(queue.toIntArray()); for(int i = 0;i<20;i++) { - other.dequeueInt(); + other.dequeue(); other.enqueue(i); } Assert.assertArrayEquals(shiftPrimArray, other.toIntArray()); Assert.assertArrayEquals(shiftPrimArray, other.toIntArray(new int[100])); - Assert.assertArrayEquals(shiftArray, other.toArray()); } } }