Small Additions & Redsign

- Added: Stack.isEmpty was missing
- Changed: remove/removeLast/enqueue/enqueueFirst no longer use Type
Suffixes
This commit is contained in:
2021-06-23 18:38:23 +02:00
parent 3676849efc
commit 9f4bede08e
9 changed files with 39 additions and 27 deletions
@@ -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");
@@ -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<m;i++) {
int index = (first + i) % array.length;
@@ -156,7 +156,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
}
@Override
public boolean REMOVE_LAST(KEY_TYPE e) {
public boolean removeLast(KEY_TYPE e) {
if(first == last) return false;
if(first == last) return false;
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
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<size;i++)
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
return false;
}
@Override
public boolean REMOVE_LAST(KEY_TYPE e) {
public boolean removeLast(KEY_TYPE e) {
for(int i = size-1;i>=0;i--)
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
return false;
@@ -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<size;i++)
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
return false;
}
@Override
public boolean REMOVE_LAST(KEY_TYPE e) {
public boolean removeLast(KEY_TYPE e) {
for(int i = size-1;i>=0;i--)
if(KEY_EQUALS(e, array[i])) return removeIndex(i);
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.
* @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
@@ -38,7 +38,7 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue<CLA
* Method to insert a element into the PriorityQueue
* @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
* @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
* @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
* @param e the element that should be 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
@@ -97,7 +97,7 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue<CLA
#if !TYPE_OBJECT
@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
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); }
@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
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
public default CLASS_TYPE[] toArray() { return toArray(new CLASS_TYPE[size()]); }