Added Priority Queue Module
This commit is contained in:
parent
ce9343348e
commit
3ce52668df
File diff suppressed because it is too large
Load Diff
|
@ -75,7 +75,8 @@ public class CollectionModule extends BaseModule
|
|||
addClassMapper("LIST_ITERATOR", "ListIterator");
|
||||
addClassMapper("BI_ITERATOR", "BidirectionalIterator");
|
||||
addClassMapper("ITERATOR", "Iterator");
|
||||
addClassMapper("STACK", "Stack");
|
||||
if(keyType.isObject()) addSimpleMapper("STACK", "Stack");
|
||||
else addClassMapper("STACK", "Stack");
|
||||
addClassMapper("STRATEGY", "Strategy");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
|
@ -12,22 +16,46 @@ public class PrioQueueModule extends BaseModule
|
|||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
protected void loadFlags() {}
|
||||
@Override
|
||||
protected void loadFunctions() {}
|
||||
@Override
|
||||
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||
return new TreeSet<>(Arrays.asList("Wrappers", "Implementations", "Dequeue", "FiFoQueue", "HeapQueue", "ArrayPrioQueue"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(isModuleEnabled()) addFlag("QUEUE_MODULE");
|
||||
if(isModuleEnabled("Wrappers")) addKeyFlag("QUEUES_FEATURE");
|
||||
boolean implementations = isModuleEnabled("Implementations");
|
||||
if(isModuleEnabled("Dequeue")) {
|
||||
addKeyFlag("DEQUEUE_FEATURE");
|
||||
if(implementations && isModuleEnabled("FiFoQueue")) addKeyFlag("FIFO_QUEUE_FEATURE");
|
||||
}
|
||||
if(implementations && isModuleEnabled("HeapQueue")) addKeyFlag("HEAP_QUEUE_FEATURE");
|
||||
if(implementations && isModuleEnabled("ArrayPrioQueue")) addKeyFlag("ARRAY_QUEUE_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!isModuleEnabled()) addBlockedFiles("PriorityQueue", "AbstractPriorityQueue");
|
||||
if(!isModuleEnabled("Wrappers")) addBlockedFiles("PriorityQueues");
|
||||
boolean implementations = !isModuleEnabled("Implementations");
|
||||
boolean dequeue = !isModuleEnabled("Dequeue");
|
||||
if(dequeue) addBlockedFiles("PriorityDequeue");
|
||||
if(dequeue || implementations || !isModuleEnabled("FiFoQueue")) addBlockedFiles("ArrayFIFOQueue");
|
||||
if(implementations || !isModuleEnabled("HeapQueue")) addBlockedFiles("HeapPriorityQueue");
|
||||
if(implementations || !isModuleEnabled("ArrayPrioQueue")) addBlockedFiles("ArrayPriorityQueue");
|
||||
|
||||
if(keyType == ClassType.BOOLEAN) {
|
||||
addBlockedFiles("QueueTests");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRemappers()
|
||||
{
|
||||
protected void loadRemappers() {
|
||||
//Main Classes
|
||||
addRemapper("AbstractPriorityQueue", "Abstract%sPriorityQueue");
|
||||
|
||||
|
@ -38,8 +66,7 @@ public class PrioQueueModule extends BaseModule
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void loadClasses()
|
||||
{
|
||||
protected void loadClasses() {
|
||||
//Implementation Classes
|
||||
addClassMapper("ARRAY_FIFO_QUEUE", "ArrayFIFOQueue");
|
||||
addClassMapper("ARRAY_PRIORITY_QUEUE", "ArrayPriorityQueue");
|
||||
|
|
|
@ -26,8 +26,8 @@ import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
|||
#endif
|
||||
#endif
|
||||
#if SET_MODULE && !TYPE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if LINKED_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||
#else if LINKED_CUSTOM_SET_FEATURE
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package speiger.src.collections.PACKAGE.lists;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
#if DEQUEUE_FEATURE
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.function.BiFunction;
|
||||
#else if PRIMITIVES
|
||||
import java.nio.JAVA_BUFFER;
|
||||
|
@ -31,9 +33,13 @@ import speiger.src.collections.PACKAGE.collections.STACK;
|
|||
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if DEQUEUE_FEATURE
|
||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
#if DEQUEUE_FEATURE
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
|
@ -62,10 +68,10 @@ import speiger.src.collections.utils.SanityChecks;
|
|||
*
|
||||
* @Type(T)
|
||||
*/
|
||||
#if TYPE_OBJECT
|
||||
public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, Stack KEY_GENERIC_TYPE
|
||||
#else
|
||||
#if DEQUEUE_FEATURE
|
||||
public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, STACK KEY_GENERIC_TYPE
|
||||
#else
|
||||
public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements STACK KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE first;
|
||||
|
@ -222,6 +228,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
return true;
|
||||
}
|
||||
|
||||
#if DEQUEUE_FEATURE
|
||||
@Override
|
||||
public void enqueue(KEY_TYPE e) {
|
||||
add(e);
|
||||
|
@ -232,6 +239,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
add(0, e);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void push(KEY_TYPE e) {
|
||||
add(e);
|
||||
|
@ -291,6 +299,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
return a;
|
||||
}
|
||||
|
||||
#if DEQUEUE_FEATURE
|
||||
@Override
|
||||
public KEY_TYPE first() {
|
||||
if(first == null) throw new NoSuchElementException();
|
||||
|
@ -303,11 +312,11 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
return last.value;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE peek(int index) {
|
||||
return GET_KEY((size() - 1) - index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_KEY(int index) {
|
||||
checkRange(index);
|
||||
|
@ -525,6 +534,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
}
|
||||
|
||||
#endif
|
||||
#if DEQUEUE_FEATURE
|
||||
@Override
|
||||
public void onChanged() {}
|
||||
@Override
|
||||
|
@ -538,25 +548,24 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
|
||||
@Override
|
||||
public KEY_TYPE dequeueLast() {
|
||||
return pop();
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE pop() {
|
||||
if(last == null) throw new NoSuchElementException();
|
||||
return unlinkLast(last);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE pop() {
|
||||
return dequeueLast();
|
||||
}
|
||||
|
||||
#if DEQUEUE_FEATURE
|
||||
@Override
|
||||
public boolean removeFirst(KEY_TYPE e) {
|
||||
if(size == 0) return false;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
if(KEY_EQUALS(entry.value, e)) {
|
||||
unlink(entry);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#if TYPE_OBJECT
|
||||
return remove(e);
|
||||
#else
|
||||
return REMOVE_KEY(e);
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -571,6 +580,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE swapRemove(int index) {
|
||||
checkRange(index);
|
||||
|
@ -653,7 +663,14 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
#else
|
||||
@Override
|
||||
public boolean REMOVE_KEY(KEY_TYPE e) {
|
||||
return removeFirst(e);
|
||||
if(size == 0) return false;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||
if(KEY_EQUALS(entry.value, e)) {
|
||||
unlink(entry);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,9 @@ import java.util.Iterator;
|
|||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if QUEUES_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Type Speciifc PriorityDeque or Dequeue interface to allow implementations like FIFO queues.
|
||||
|
@ -81,6 +83,7 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
|
|||
*/
|
||||
public default KEY_TYPE last() { return peek(size()-1); }
|
||||
|
||||
#if QUEUES_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped PriorityDequeue that is Synchronized
|
||||
* @return a new PriorityDequeue that is synchronized
|
||||
|
@ -96,6 +99,7 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
|
|||
*/
|
||||
public default PRIORITY_DEQUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
|
||||
}
|
|
@ -12,7 +12,9 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if QUEUES_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
|
@ -147,8 +149,9 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
|||
* @return draining iterator of the PriorityQueue
|
||||
*/
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
#endif
|
||||
|
||||
#if QUEUES_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||
* @return a new PriorityQueue that is synchronized
|
||||
|
@ -163,7 +166,8 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
|||
* @see PRIORITY_QUEUES#synchronize
|
||||
*/
|
||||
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A method to drop the contents of the Queue without clearing the queue
|
||||
* @Type(E)
|
||||
|
|
|
@ -37,8 +37,8 @@ import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
|||
#endif
|
||||
#if !TYPE_BOOLEAN && OBJECT_ASYNC_MODULE
|
||||
#if SET_MODULE
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if LINKED_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||
#else if LINKED_CUSTOM_SET_FEATURE
|
||||
|
|
|
@ -11,7 +11,9 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
|||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
#if DEQUEUE_FEATURE
|
||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
|
@ -46,6 +48,7 @@ public class PRIORITY_QUEUES
|
|||
return queue instanceof SynchronizedPriorityQueue ? (SynchronizedPriorityQueue KEY_GENERIC_TYPE)queue : new SynchronizedPriorityQueueBRACES(queue, mutex);
|
||||
}
|
||||
|
||||
#if DEQUEUE_FEATURE
|
||||
/**
|
||||
* Returns a synchronized PriorityDequeue instance based on the instance given.
|
||||
* @param dequeue that should be synchronized
|
||||
|
@ -67,6 +70,7 @@ public class PRIORITY_QUEUES
|
|||
return dequeue instanceof SynchronizedPriorityDequeue ? (SynchronizedPriorityDequeue KEY_GENERIC_TYPE)dequeue : new SynchronizedPriorityDequeueBRACES(dequeue, mutex);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Wrapper class for synchronization
|
||||
* @Type(T)
|
||||
|
@ -134,6 +138,7 @@ public class PRIORITY_QUEUES
|
|||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.count(filter); } }
|
||||
}
|
||||
|
||||
#if DEQUEUE_FEATURE
|
||||
/**
|
||||
* Wrapper class for synchronization
|
||||
* @Type(T)
|
||||
|
@ -166,4 +171,5 @@ public class PRIORITY_QUEUES
|
|||
@Override
|
||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { synchronized(mutex) { return dequeue.copy(); } }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue