diff --git a/Changelog.md b/Changelog.md new file mode 100644 index 00000000..857d7dd2 --- /dev/null +++ b/Changelog.md @@ -0,0 +1,6 @@ +# Changelog of versions + + +## Version 0.3.0 +- Added: Stack.isEmpty was missing +- Changed: remove/removeLast/enqueue/enqueueFirst no longer use Type Suffixes \ No newline at end of file diff --git a/src/builder/java/speiger/src/builder/GlobalVariables.java b/src/builder/java/speiger/src/builder/GlobalVariables.java index 63b038b5..68a8a9ad 100644 --- a/src/builder/java/speiger/src/builder/GlobalVariables.java +++ b/src/builder/java/speiger/src/builder/GlobalVariables.java @@ -216,8 +216,6 @@ public class GlobalVariables addFunctionValueMappers("COMPUTE_IF_ABSENT", "compute%sIfAbsent"); addFunctionValueMappers("COMPUTE_IF_PRESENT", "compute%sIfPresent"); addFunctionValueMapper("COMPUTE", "compute"); - addFunctionMapper("ENQUEUE_FIRST", "enqueueFirst"); - addFunctionMapper("ENQUEUE", "enqueue"); addFunctionMapper("DEQUEUE_LAST", "dequeueLast"); addFunctionMapper("DEQUEUE", "dequeue"); addFunctionMappers("POLL_FIRST_ENTRY_KEY", "pollFirst%sKey"); 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 1e179d4b..6d5a491a 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template @@ -101,14 +101,14 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G } @Override - public void ENQUEUE(KEY_TYPE e) { + public void enqueue(KEY_TYPE e) { array[last] = e; last = ++last % array.length; if(last == first) expand(); } @Override - public void ENQUEUE_FIRST(KEY_TYPE e) { + public void enqueueFirst(KEY_TYPE e) { if(first == 0) first = array.length; array[--first] = e; if(first == last) expand(); @@ -145,7 +145,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G } @Override - public boolean REMOVE(KEY_TYPE e) { + public boolean remove(KEY_TYPE e) { if(first == last) return false; for(int i = 0,m=size();i=0;i--) { 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 cff6cd04..fea0b135 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template @@ -180,7 +180,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY } @Override - public void ENQUEUE(KEY_TYPE e) { + public void enqueue(KEY_TYPE e) { if(size == array.length) array = Arrays.copyOf(array, size+1); if(firstIndex != -1){ int compare = comparator == null ? COMPAREABLE_TO_KEY(e, array[firstIndex]) : comparator.compare(e, array[firstIndex]); @@ -210,14 +210,14 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY } @Override - public boolean REMOVE(KEY_TYPE e) { + public boolean remove(KEY_TYPE e) { for(int i = 0;i=0;i--) if(KEY_EQUALS(e, array[i])) return removeIndex(i); return false; 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 5d091a04..756076cc 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template @@ -200,7 +200,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_ } @Override - public void ENQUEUE(KEY_TYPE e) { + public void enqueue(KEY_TYPE e) { if(size == array.length) array = Arrays.copyOf(array, size + 1); array[size++] = e; ARRAYS.shiftUp(array, size-1, comparator); @@ -225,14 +225,14 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_ } @Override - public boolean REMOVE(KEY_TYPE e) { + public boolean remove(KEY_TYPE e) { for(int i = 0;i=0;i--) if(KEY_EQUALS(e, array[i])) return removeIndex(i); return false; diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template b/src/builder/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template index c484685d..d6e7cda9 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template @@ -10,7 +10,7 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE * Method to insert a element into the first Index instead of the last. * @param e the element that should be inserted into the first place */ - public void ENQUEUE_FIRST(KEY_TYPE e); + public void enqueueFirst(KEY_TYPE e); /** * A Method to remove a element from the last place instead of the first * @return the last element inserted @@ -29,7 +29,7 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE * @param e the boxed element that should be inserted */ @Deprecated - public default void enqueueFirst(CLASS_TYPE e) { ENQUEUE_FIRST(OBJ_TO_KEY(e)); } + public default void enqueueFirst(CLASS_TYPE e) { enqueueFirst(OBJ_TO_KEY(e)); } /** * Boxed Method for the dequeue last method * @return the last element of the Dequeue diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template index 8ee734e4..48efa45f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template @@ -38,7 +38,7 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue */ public int size(); + + /** + * @return if the stack is empty + */ + public default boolean isEmpty() { + return size() == 0; + } + /** * Clears the stack */ diff --git a/src/test/java/speiger/src/collections/ints/base/BaseIntPriorityQueueTest.java b/src/test/java/speiger/src/collections/ints/base/BaseIntPriorityQueueTest.java index e0062c45..b3a3b431 100644 --- a/src/test/java/speiger/src/collections/ints/base/BaseIntPriorityQueueTest.java +++ b/src/test/java/speiger/src/collections/ints/base/BaseIntPriorityQueueTest.java @@ -26,7 +26,7 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest if(getValidPriorityQueueTests().contains(PriorityQueueTest.IN_OUT)) { IntPriorityQueue queue = create(EMPTY_ARRAY); for(int i = 0;i<100;i++) { - queue.enqueueInt(i); + queue.enqueue(i); } for(int i = 0;i<100;i++) { Assert.assertEquals(i, queue.dequeueInt()); @@ -43,7 +43,7 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest if(getValidPriorityQueueTests().contains(PriorityQueueTest.PEEK)) { IntPriorityQueue queue = create(EMPTY_ARRAY); for(int i = 0;i<100;i++) { - queue.enqueueInt(i); + queue.enqueue(i); } if(isUnsortedRead()) { for(int i = 0;i<100;i++) { @@ -64,17 +64,17 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest if(getValidPriorityQueueTests().contains(PriorityQueueTest.REMOVE)) { IntPriorityQueue queue = create(EMPTY_ARRAY); for(int i = 0;i<100;i++) { - queue.enqueueInt(i); + queue.enqueue(i); } - queue.removeInt(40); + 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()); } for(int i = 0;i<100;i++) { - queue.enqueueInt(i); + queue.enqueue(i); } - queue.removeLastInt(40); + 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()); @@ -89,7 +89,7 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest IntPriorityQueue queue = create(EMPTY_ARRAY); if(isUnsortedRead()) { for(int i = 0;i<100;i++) { - queue.enqueueInt(i); + queue.enqueue(i); } int[] array = queue.toIntArray(); IntArrays.stableSort(array);