Small Additions & Redsign
- Added: Stack.isEmpty was missing - Changed: remove/removeLast/enqueue/enqueueFirst no longer use Type Suffixes
This commit is contained in:
parent
3676849efc
commit
9f4bede08e
|
@ -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
|
|
@ -216,8 +216,6 @@ public class GlobalVariables
|
||||||
addFunctionValueMappers("COMPUTE_IF_ABSENT", "compute%sIfAbsent");
|
addFunctionValueMappers("COMPUTE_IF_ABSENT", "compute%sIfAbsent");
|
||||||
addFunctionValueMappers("COMPUTE_IF_PRESENT", "compute%sIfPresent");
|
addFunctionValueMappers("COMPUTE_IF_PRESENT", "compute%sIfPresent");
|
||||||
addFunctionValueMapper("COMPUTE", "compute");
|
addFunctionValueMapper("COMPUTE", "compute");
|
||||||
addFunctionMapper("ENQUEUE_FIRST", "enqueueFirst");
|
|
||||||
addFunctionMapper("ENQUEUE", "enqueue");
|
|
||||||
addFunctionMapper("DEQUEUE_LAST", "dequeueLast");
|
addFunctionMapper("DEQUEUE_LAST", "dequeueLast");
|
||||||
addFunctionMapper("DEQUEUE", "dequeue");
|
addFunctionMapper("DEQUEUE", "dequeue");
|
||||||
addFunctionMappers("POLL_FIRST_ENTRY_KEY", "pollFirst%sKey");
|
addFunctionMappers("POLL_FIRST_ENTRY_KEY", "pollFirst%sKey");
|
||||||
|
|
|
@ -101,14 +101,14 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ENQUEUE(KEY_TYPE e) {
|
public void enqueue(KEY_TYPE e) {
|
||||||
array[last] = e;
|
array[last] = e;
|
||||||
last = ++last % array.length;
|
last = ++last % array.length;
|
||||||
if(last == first) expand();
|
if(last == first) expand();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ENQUEUE_FIRST(KEY_TYPE e) {
|
public void enqueueFirst(KEY_TYPE e) {
|
||||||
if(first == 0) first = array.length;
|
if(first == 0) first = array.length;
|
||||||
array[--first] = e;
|
array[--first] = e;
|
||||||
if(first == last) expand();
|
if(first == last) expand();
|
||||||
|
@ -145,7 +145,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean REMOVE(KEY_TYPE e) {
|
public boolean remove(KEY_TYPE e) {
|
||||||
if(first == last) return false;
|
if(first == last) return false;
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
int index = (first + i) % array.length;
|
int index = (first + i) % array.length;
|
||||||
|
@ -156,7 +156,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean REMOVE_LAST(KEY_TYPE e) {
|
public boolean removeLast(KEY_TYPE e) {
|
||||||
if(first == last) return false;
|
if(first == last) return false;
|
||||||
if(first == last) return false;
|
if(first == last) return false;
|
||||||
for(int i = size()-1;i>=0;i--) {
|
for(int i = size()-1;i>=0;i--) {
|
||||||
|
|
|
@ -180,7 +180,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ENQUEUE(KEY_TYPE e) {
|
public void enqueue(KEY_TYPE e) {
|
||||||
if(size == array.length) array = Arrays.copyOf(array, size+1);
|
if(size == array.length) array = Arrays.copyOf(array, size+1);
|
||||||
if(firstIndex != -1){
|
if(firstIndex != -1){
|
||||||
int compare = comparator == null ? COMPAREABLE_TO_KEY(e, array[firstIndex]) : comparator.compare(e, array[firstIndex]);
|
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
|
@Override
|
||||||
public boolean REMOVE(KEY_TYPE e) {
|
public boolean remove(KEY_TYPE e) {
|
||||||
for(int i = 0;i<size;i++)
|
for(int i = 0;i<size;i++)
|
||||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean REMOVE_LAST(KEY_TYPE e) {
|
public boolean removeLast(KEY_TYPE e) {
|
||||||
for(int i = size-1;i>=0;i--)
|
for(int i = size-1;i>=0;i--)
|
||||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -200,7 +200,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ENQUEUE(KEY_TYPE e) {
|
public void enqueue(KEY_TYPE e) {
|
||||||
if(size == array.length) array = Arrays.copyOf(array, size + 1);
|
if(size == array.length) array = Arrays.copyOf(array, size + 1);
|
||||||
array[size++] = e;
|
array[size++] = e;
|
||||||
ARRAYS.shiftUp(array, size-1, comparator);
|
ARRAYS.shiftUp(array, size-1, comparator);
|
||||||
|
@ -225,14 +225,14 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean REMOVE(KEY_TYPE e) {
|
public boolean remove(KEY_TYPE e) {
|
||||||
for(int i = 0;i<size;i++)
|
for(int i = 0;i<size;i++)
|
||||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean REMOVE_LAST(KEY_TYPE e) {
|
public boolean removeLast(KEY_TYPE e) {
|
||||||
for(int i = size-1;i>=0;i--)
|
for(int i = size-1;i>=0;i--)
|
||||||
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -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.
|
* 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
|
* @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
|
* A Method to remove a element from the last place instead of the first
|
||||||
* @return the last element inserted
|
* @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
|
* @param e the boxed element that should be inserted
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@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
|
* Boxed Method for the dequeue last method
|
||||||
* @return the last element of the Dequeue
|
* @return the last element of the Dequeue
|
||||||
|
|
|
@ -38,7 +38,7 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue<CLA
|
||||||
* Method to insert a element into the PriorityQueue
|
* Method to insert a element into the PriorityQueue
|
||||||
* @param e the element that should be inserted
|
* @param e the element that should be inserted
|
||||||
*/
|
*/
|
||||||
public void ENQUEUE(KEY_TYPE e);
|
public void enqueue(KEY_TYPE e);
|
||||||
/**
|
/**
|
||||||
* Method to extract a element from the PriorityQueue
|
* Method to extract a element from the PriorityQueue
|
||||||
* @return a element from the Queue
|
* @return a element from the Queue
|
||||||
|
@ -63,13 +63,13 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue<CLA
|
||||||
* @param e the element that should be removed
|
* @param e the element that should be removed
|
||||||
* @return if a searched element was removed
|
* @return if a searched element was removed
|
||||||
*/
|
*/
|
||||||
public boolean REMOVE(KEY_TYPE e);
|
public boolean remove(KEY_TYPE e);
|
||||||
/**
|
/**
|
||||||
* Removes the last found element in the queue
|
* Removes the last found element in the queue
|
||||||
* @param e the element that should be removed
|
* @param e the element that should be removed
|
||||||
* @return if a searched element was removed
|
* @return if a searched element was removed
|
||||||
*/
|
*/
|
||||||
public boolean REMOVE_LAST(KEY_TYPE e);
|
public boolean removeLast(KEY_TYPE e);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to notify the Queue to be revalidate its data
|
* Allows to notify the Queue to be revalidate its data
|
||||||
|
@ -97,7 +97,7 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue<CLA
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default void enqueue(CLASS_TYPE e) { ENQUEUE(OBJ_TO_KEY(e)); }
|
public default void enqueue(CLASS_TYPE e) { enqueue(OBJ_TO_KEY(e)); }
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default CLASS_TYPE dequeue() { return KEY_TO_OBJ(DEQUEUE()); }
|
public default CLASS_TYPE dequeue() { return KEY_TO_OBJ(DEQUEUE()); }
|
||||||
|
|
||||||
|
@ -107,9 +107,9 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue<CLA
|
||||||
public default CLASS_TYPE first() { return peek(0); }
|
public default CLASS_TYPE first() { return peek(0); }
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default boolean remove(CLASS_TYPE e) { return REMOVE(OBJ_TO_KEY(e)); }
|
public default boolean remove(CLASS_TYPE e) { return remove(OBJ_TO_KEY(e)); }
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default boolean removeLast(CLASS_TYPE e) { return REMOVE_LAST(OBJ_TO_KEY(e)); }
|
public default boolean removeLast(CLASS_TYPE e) { return removeLast(OBJ_TO_KEY(e)); }
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default CLASS_TYPE[] toArray() { return toArray(new CLASS_TYPE[size()]); }
|
public default CLASS_TYPE[] toArray() { return toArray(new CLASS_TYPE[size()]); }
|
||||||
|
|
|
@ -29,6 +29,14 @@ public interface Stack<T>
|
||||||
*/
|
*/
|
||||||
public int size();
|
public int size();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return if the stack is empty
|
||||||
|
*/
|
||||||
|
public default boolean isEmpty() {
|
||||||
|
return size() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the stack
|
* Clears the stack
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -26,7 +26,7 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
||||||
if(getValidPriorityQueueTests().contains(PriorityQueueTest.IN_OUT)) {
|
if(getValidPriorityQueueTests().contains(PriorityQueueTest.IN_OUT)) {
|
||||||
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
||||||
for(int i = 0;i<100;i++) {
|
for(int i = 0;i<100;i++) {
|
||||||
queue.enqueueInt(i);
|
queue.enqueue(i);
|
||||||
}
|
}
|
||||||
for(int i = 0;i<100;i++) {
|
for(int i = 0;i<100;i++) {
|
||||||
Assert.assertEquals(i, queue.dequeueInt());
|
Assert.assertEquals(i, queue.dequeueInt());
|
||||||
|
@ -43,7 +43,7 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
||||||
if(getValidPriorityQueueTests().contains(PriorityQueueTest.PEEK)) {
|
if(getValidPriorityQueueTests().contains(PriorityQueueTest.PEEK)) {
|
||||||
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
||||||
for(int i = 0;i<100;i++) {
|
for(int i = 0;i<100;i++) {
|
||||||
queue.enqueueInt(i);
|
queue.enqueue(i);
|
||||||
}
|
}
|
||||||
if(isUnsortedRead()) {
|
if(isUnsortedRead()) {
|
||||||
for(int i = 0;i<100;i++) {
|
for(int i = 0;i<100;i++) {
|
||||||
|
@ -64,17 +64,17 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
||||||
if(getValidPriorityQueueTests().contains(PriorityQueueTest.REMOVE)) {
|
if(getValidPriorityQueueTests().contains(PriorityQueueTest.REMOVE)) {
|
||||||
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
||||||
for(int i = 0;i<100;i++) {
|
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++) {
|
for(int i = 0;i<99;i++) {
|
||||||
if(i >= 40) Assert.assertEquals(i + 1, queue.dequeueInt());
|
if(i >= 40) Assert.assertEquals(i + 1, queue.dequeueInt());
|
||||||
else Assert.assertEquals(i, queue.dequeueInt());
|
else Assert.assertEquals(i, queue.dequeueInt());
|
||||||
}
|
}
|
||||||
for(int i = 0;i<100;i++) {
|
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++) {
|
for(int i = 0;i<99;i++) {
|
||||||
if(i >= 40) Assert.assertEquals(i + 1, queue.dequeueInt());
|
if(i >= 40) Assert.assertEquals(i + 1, queue.dequeueInt());
|
||||||
else Assert.assertEquals(i, queue.dequeueInt());
|
else Assert.assertEquals(i, queue.dequeueInt());
|
||||||
|
@ -89,7 +89,7 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
||||||
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
||||||
if(isUnsortedRead()) {
|
if(isUnsortedRead()) {
|
||||||
for(int i = 0;i<100;i++) {
|
for(int i = 0;i<100;i++) {
|
||||||
queue.enqueueInt(i);
|
queue.enqueue(i);
|
||||||
}
|
}
|
||||||
int[] array = queue.toIntArray();
|
int[] array = queue.toIntArray();
|
||||||
IntArrays.stableSort(array);
|
IntArrays.stableSort(array);
|
||||||
|
|
Loading…
Reference in New Issue