Class HashBackedPriorityQueue<T>
- java.lang.Object
-
- org.processmining.earthmoversstochasticconformancechecking.datastructures.HashBackedPriorityQueue<T>
-
- Type Parameters:
T-
- All Implemented Interfaces:
java.lang.Iterable<T>,java.util.Collection<T>,java.util.Queue<T>
public class HashBackedPriorityQueue<T> extends java.lang.Object implements java.util.Queue<T>Adapted implementation of the HashBackedPriorityQueue by bvdongen to support generics. Besides, this implementation is less memory efficient than the original implementation but therefore is easier to maintain and relies only on java-native libraries. It is IMPORTANT thatObject.equals(Object)andObject.hashCode()are implemented. Moreover, it is possible that the comparator has a stronger assumption on what is equal. -> Idea: Hash code and equals consider the state (e.g. replay state) -> Comparator: More sophisticated ordering based on state evaluation values- Author:
- brockhoff
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<T,java.lang.Integer>locationMapprotected static intNEVprotected java.util.ArrayList<T>queuePriority queue represented as a balanced binary heap: the two children of queue[n] are queue[2*n+1] and queue[2*(n+1)].
-
Constructor Summary
Constructors Constructor Description HashBackedPriorityQueue(int initialCapacity, java.util.Comparator<T> itemComparator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(T object)Inserts the specified element into this priority queue.booleanaddAll(java.util.Collection<? extends T> c)booleanaddOrUpdate(T object)booleanaddOrUpdateIfBetter(T object)protected booleancheckInv(int loc)voidclear()booleancontains(java.lang.Object object)booleancontainsAll(java.util.Collection<?> c)Telement()Tget(java.lang.Object o)java.util.Comparator<T>getItemComparator()java.util.Map<T,java.lang.Integer>getLocationMap()protected booleanisBetter(T object1, T object2)First order sorting is based on F score alone.booleanisEmpty()java.util.Iterator<T>iterator()booleanoffer(T object)Inserts the specified element into this priority queue.Tpeek()protected Tpeek(int location)Tpoll()Tremove()booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.Collection<?> c)protected voidsiftDown(int positionToFill, T object)Inserts item x at position k, maintaining heap invariant by demoting x down the tree repeatedly until it is less than or equal to its children or is a leaf.protected voidsiftUp(int fromPosition, T object)Inserts item x at position k, maintaining heap invariant by promoting x up the tree until it is greater than or equal to its parent, or is the root.intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
locationMap
protected final java.util.Map<T,java.lang.Integer> locationMap
-
NEV
protected static final int NEV
- See Also:
- Constant Field Values
-
queue
protected java.util.ArrayList<T> queue
Priority queue represented as a balanced binary heap: the two children of queue[n] are queue[2*n+1] and queue[2*(n+1)]. The priority queue is ordered by the record's natural ordering: For each node n in the heap and each descendant d of n, n <= d. The element with the best value is in queue[0], assuming the queue is nonempty.
-
-
Constructor Detail
-
HashBackedPriorityQueue
public HashBackedPriorityQueue(int initialCapacity, java.util.Comparator<T> itemComparator)
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<T>
-
contains
public boolean contains(java.lang.Object object)
- Specified by:
containsin interfacejava.util.Collection<T>
-
peek
protected T peek(int location)
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<T>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
add
public boolean add(T object)
Inserts the specified element into this priority queue. Does not allow to add two objects with the same hash code.
-
addOrUpdate
public boolean addOrUpdate(T object)
-
addOrUpdateIfBetter
public boolean addOrUpdateIfBetter(T object)
-
isBetter
protected boolean isBetter(T object1, T object2)
First order sorting is based on F score alone.
-
offer
public boolean offer(T object)
Inserts the specified element into this priority queue.- Specified by:
offerin interfacejava.util.Queue<T>- Returns:
true(as specified byQueue.offer(E))
-
siftUp
protected void siftUp(int fromPosition, T object)Inserts item x at position k, maintaining heap invariant by promoting x up the tree until it is greater than or equal to its parent, or is the root.- Parameters:
fromPosition-marking- the item to insert
-
siftDown
protected void siftDown(int positionToFill, T object)Inserts item x at position k, maintaining heap invariant by demoting x down the tree repeatedly until it is less than or equal to its children or is a leaf.- Parameters:
positionToFill- the position to fillmarking- the item to insert
-
checkInv
protected boolean checkInv(int loc)
-
iterator
public java.util.Iterator<T> iterator()
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<T>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfacejava.util.Collection<T>
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection<T>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<T>
-
addAll
public boolean addAll(java.util.Collection<? extends T> c)
- Specified by:
addAllin interfacejava.util.Collection<T>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<T>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<T>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<T>
-
getLocationMap
public java.util.Map<T,java.lang.Integer> getLocationMap()
-
getItemComparator
public java.util.Comparator<T> getItemComparator()
-
get
public T get(java.lang.Object o)
-
-