Class BackedGeneralPriorityQueue<E,K extends Comparable<K>>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- net.automatalib.common.smartcollection.AbstractSmartCollection<E>
-
- net.automatalib.common.smartcollection.BackedGeneralPriorityQueue<E,K>
-
- Type Parameters:
E- element class.K- key class.
- All Implemented Interfaces:
Iterable<E>,Collection<E>,SmartCollection<E>,SmartGeneralPriorityQueue<E,K>,SmartPriorityQueue<E>
public class BackedGeneralPriorityQueue<E,K extends Comparable<K>> extends AbstractSmartCollection<E> implements SmartGeneralPriorityQueue<E,K>
ASmartGeneralPriorityQueueimplementation that is backed by aSmartDynamicPriorityQueue.The default
SmartDynamicPriorityQueueto be used is aBinaryHeap, but every other implementation of this interface may be used. The backing queue is specified in the constructor.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBackedGeneralPriorityQueue.Entry<E,K extends Comparable<K>>Note: this class has a natural ordering that is inconsistent with equals.
-
Constructor Summary
Constructors Constructor Description BackedGeneralPriorityQueue()BackedGeneralPriorityQueue(int initialCapacity)BackedGeneralPriorityQueue(Supplier<? extends SmartDynamicPriorityQueue<BackedGeneralPriorityQueue.Entry<E,K>>> supplier)BackedGeneralPriorityQueue(List<? extends E> init, List<K> keys)BackedGeneralPriorityQueue(SmartDynamicPriorityQueue<BackedGeneralPriorityQueue.Entry<E,K>> backingQueue)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ElementReferenceadd(E elem, @Nullable K key)Inserts an element with the specified key.voidchangeKey(ElementReference ref, K newKey)Changes the key of an element in the priority key.Echoose()Retrieves an arbitrary element from the collection.ElementReferencechooseRef()Retrieves the reference to an arbitrary element from the collection.voidclear()voiddeepClear()Thoroughly clears the collection, fixing all issues that may have been caused by a call of the aboveSmartCollection.quickClear().EextractMin()Retrieves and removes the element with the minimum key in the priority queue.@Nullable ElementReferencefind(@Nullable Object element)Retrieves the reference for a given element.Eget(ElementReference ref)Retrieves an element by its reference.booleanisEmpty()Iterator<E>iterator()EpeekMin()Retrieves, but does not remove the element with the minimum key in the priority queue.voidquickClear()Quickly clears this collection.ElementReferencereferencedAdd(E elem)Adds an element to the collection, returning a reference to the newly added element.Iterator<ElementReference>referenceIterator()Retrieves an iterator for iterating over the references of elements in this collection.voidremove(ElementReference ref)Removes an element (by its reference) from the collection.voidreplace(ElementReference ref, E newElement)Replaces the element referenced by the given reference with the specified element.voidsetDefaultKey(K defaultKey)Sets the default key, which is used for elements that are inserted with no explicit key specified.intsize()-
Methods inherited from class net.automatalib.common.smartcollection.AbstractSmartCollection
add, addAll, addAll, references, remove
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
add, addAll, contains, containsAll, equals, hashCode, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
-
Methods inherited from interface net.automatalib.common.smartcollection.SmartCollection
addAll, addAll, references, remove
-
-
-
-
Constructor Detail
-
BackedGeneralPriorityQueue
public BackedGeneralPriorityQueue()
-
BackedGeneralPriorityQueue
public BackedGeneralPriorityQueue(int initialCapacity)
-
BackedGeneralPriorityQueue
public BackedGeneralPriorityQueue(Supplier<? extends SmartDynamicPriorityQueue<BackedGeneralPriorityQueue.Entry<E,K>>> supplier)
-
BackedGeneralPriorityQueue
public BackedGeneralPriorityQueue(SmartDynamicPriorityQueue<BackedGeneralPriorityQueue.Entry<E,K>> backingQueue)
Constructor. Explicitly initializes this queue with a given backing queue. Note that the provided queue must be empty and must not be used in any other way after being passed to the constructor.- Parameters:
backingQueue- the backing queue.
-
-
Method Detail
-
choose
public E choose()
Description copied from interface:SmartCollectionRetrieves an arbitrary element from the collection.- Specified by:
choosein interfaceSmartCollection<E>- Overrides:
choosein classAbstractSmartCollection<E>- Returns:
- an arbitrary element from the collection
-
chooseRef
public ElementReference chooseRef()
Description copied from interface:SmartCollectionRetrieves the reference to an arbitrary element from the collection. If the collection is empty, aNoSuchElementExceptionis thrown.- Specified by:
chooseRefin interfaceSmartCollection<E>- Overrides:
chooseRefin classAbstractSmartCollection<E>- Returns:
- the reference to an arbitrary element in the collection
-
find
public @Nullable ElementReference find(@Nullable Object element)
Description copied from interface:SmartCollectionRetrieves the reference for a given element. If the element is not contained in the collection,nullis returned.- Specified by:
findin interfaceSmartCollection<E>- Overrides:
findin classAbstractSmartCollection<E>- Parameters:
element- the element to search for.- Returns:
- the reference to this element, or
null.
-
quickClear
public void quickClear()
Description copied from interface:SmartCollectionQuickly clears this collection. This method is supposed to perform the minimum amount of effort such that this collection is emptied, disregarding all other side effects such as referencing or garbage collection issues.Depending on the implementation, this may be just the same as
Collection.clear(). However, this could also have side effects like hampering the garbage collection or such.After calling this method, even a call of the normal
Collection.clear()is not guaranteed to fix all these issues. This can only be achieved by the methodSmartCollection.deepClear()below.- Specified by:
quickClearin interfaceSmartCollection<E>- Overrides:
quickClearin classAbstractSmartCollection<E>
-
deepClear
public void deepClear()
Description copied from interface:SmartCollectionThoroughly clears the collection, fixing all issues that may have been caused by a call of the aboveSmartCollection.quickClear().- Specified by:
deepClearin interfaceSmartCollection<E>- Overrides:
deepClearin classAbstractSmartCollection<E>
-
iterator
public Iterator<E> iterator()
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Overrides:
iteratorin classAbstractSmartCollection<E>
-
get
public E get(ElementReference ref)
Description copied from interface:SmartCollectionRetrieves an element by its reference.If the reference belongs to another collection, the behavior is undefined.
- Specified by:
getin interfaceSmartCollection<E>- Parameters:
ref- the element's reference.- Returns:
- the element.
-
referencedAdd
public ElementReference referencedAdd(E elem)
Description copied from interface:SmartCollectionAdds an element to the collection, returning a reference to the newly added element. If the collection does not support containing the same element multiple times, a reference to the previously existing element is returned.- Specified by:
referencedAddin interfaceSmartCollection<E>- Parameters:
elem- the element to be added.- Returns:
- a reference to this element in the collection.
-
add
public ElementReference add(E elem, @Nullable K key)
Description copied from interface:SmartGeneralPriorityQueueInserts an element with the specified key.- Specified by:
addin interfaceSmartGeneralPriorityQueue<E,K extends Comparable<K>>- Parameters:
elem- the element to insert.key- the key for this element.- Returns:
- the reference to the inserted element.
-
setDefaultKey
public void setDefaultKey(K defaultKey)
Description copied from interface:SmartGeneralPriorityQueueSets the default key, which is used for elements that are inserted with no explicit key specified.- Specified by:
setDefaultKeyin interfaceSmartGeneralPriorityQueue<E,K extends Comparable<K>>- Parameters:
defaultKey- the new default key.
-
changeKey
public void changeKey(ElementReference ref, K newKey)
Description copied from interface:SmartGeneralPriorityQueueChanges the key of an element in the priority key.- Specified by:
changeKeyin interfaceSmartGeneralPriorityQueue<E,K extends Comparable<K>>- Parameters:
ref- reference to the element whose key is to be changed.newKey- the new key of this element.
-
remove
public void remove(ElementReference ref)
Description copied from interface:SmartCollectionRemoves an element (by its reference) from the collection.If the reference does not belong to this collection, the behavior is undefined.
- Specified by:
removein interfaceSmartCollection<E>- Parameters:
ref- the reference to the element to be removed.
-
referenceIterator
public Iterator<ElementReference> referenceIterator()
Description copied from interface:SmartCollectionRetrieves an iterator for iterating over the references of elements in this collection.- Specified by:
referenceIteratorin interfaceSmartCollection<E>- Returns:
- the reference iterator.
-
replace
public void replace(ElementReference ref, E newElement)
Description copied from interface:SmartCollectionReplaces the element referenced by the given reference with the specified element.- Specified by:
replacein interfaceSmartCollection<E>- Parameters:
ref- the reference of the element to be replaced.newElement- the replacement.
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>- Overrides:
clearin classAbstractCollection<E>
-
peekMin
public E peekMin()
Description copied from interface:SmartPriorityQueueRetrieves, but does not remove the element with the minimum key in the priority queue. If there are several elements with minimal key values, one of them is chosen arbitrarily.- Specified by:
peekMinin interfaceSmartPriorityQueue<E>- Returns:
- an element with a minimal key.
-
extractMin
public E extractMin()
Description copied from interface:SmartPriorityQueueRetrieves and removes the element with the minimum key in the priority queue. If there are several elements with minimal key values, one of them is chosen arbitrarily.- Specified by:
extractMinin interfaceSmartPriorityQueue<E>- Returns:
- the element with the previously minimal key.
-
-