E
- element class.K
- key class.public class BackedGeneralPriorityQueue<E,K extends Comparable<K>> extends AbstractSmartCollection<E> implements SmartGeneralPriorityQueue<E,K>
SmartGeneralPriorityQueue
implementation that is backed by a SmartDynamicPriorityQueue
.
The default SmartDynamicPriorityQueue
to be used is a BinaryHeap
, but every other implementation of
this interface may be used. The backing queue is specified in the constructor.
Constructor and Description |
---|
BackedGeneralPriorityQueue() |
BackedGeneralPriorityQueue(int initialCapacity) |
BackedGeneralPriorityQueue(List<? extends E> init,
List<K> keys) |
BackedGeneralPriorityQueue(SmartDynamicPriorityQueue<net.automatalib.commons.smartcollections.BackedGeneralPriorityQueue.Entry<E,K>> backingQueue)
Constructor.
|
BackedGeneralPriorityQueue(Supplier<? extends SmartDynamicPriorityQueue<net.automatalib.commons.smartcollections.BackedGeneralPriorityQueue.Entry<E,K>>> supplier) |
Modifier and Type | Method and Description |
---|---|
ElementReference |
add(E elem,
K key)
Inserts an element with the specified key.
|
void |
changeKey(ElementReference ref,
K newKey)
Changes the key of an element in the priority key.
|
E |
choose()
Retrieves an arbitrary element from the collection.
|
ElementReference |
chooseRef()
Retrieves the reference to an arbitrary element from the collection.
|
void |
clear() |
void |
deepClear()
Thoroughly clears the collection, fixing all issues that may have been caused by a call of the above
SmartCollection.quickClear() . |
E |
extractMin()
Retrieves and removes the element with the minimum key in the priority queue.
|
@Nullable ElementReference |
find(@Nullable Object element)
Retrieves the reference for a given element.
|
E |
get(ElementReference ref)
Retrieves an element by its reference.
|
boolean |
isEmpty() |
Iterator<E> |
iterator() |
E |
peekMin()
Retrieves, but does not remove the element with the minimum key in the priority queue.
|
void |
quickClear()
Quickly clears this collection.
|
ElementReference |
referencedAdd(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.
|
void |
remove(ElementReference ref)
Removes an element (by its reference) from the collection.
|
void |
replace(ElementReference ref,
E newElement)
Replaces the element referenced by the given reference with the specified element.
|
void |
setDefaultKey(K defaultKey)
Sets the default key, which is used for elements that are inserted with no explicit key specified.
|
int |
size() |
add, addAll, addAll, references, remove
addAll, contains, containsAll, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addAll, addAll, references, remove
add, addAll, contains, containsAll, equals, hashCode, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
public BackedGeneralPriorityQueue()
public BackedGeneralPriorityQueue(int initialCapacity)
public BackedGeneralPriorityQueue(Supplier<? extends SmartDynamicPriorityQueue<net.automatalib.commons.smartcollections.BackedGeneralPriorityQueue.Entry<E,K>>> supplier)
public BackedGeneralPriorityQueue(SmartDynamicPriorityQueue<net.automatalib.commons.smartcollections.BackedGeneralPriorityQueue.Entry<E,K>> backingQueue)
backingQueue
- the backing queue.public E choose()
SmartCollection
choose
in interface SmartCollection<E>
choose
in class AbstractSmartCollection<E>
public ElementReference chooseRef()
SmartCollection
NoSuchElementException
is thrown.chooseRef
in interface SmartCollection<E>
chooseRef
in class AbstractSmartCollection<E>
public @Nullable ElementReference find(@Nullable Object element)
SmartCollection
null
is returned.find
in interface SmartCollection<E>
find
in class AbstractSmartCollection<E>
element
- the element to search for.null
.public void quickClear()
SmartCollection
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 method SmartCollection.deepClear()
below.
quickClear
in interface SmartCollection<E>
quickClear
in class AbstractSmartCollection<E>
public void deepClear()
SmartCollection
SmartCollection.quickClear()
.deepClear
in interface SmartCollection<E>
deepClear
in class AbstractSmartCollection<E>
public Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in class AbstractSmartCollection<E>
public E get(ElementReference ref)
SmartCollection
If the reference belongs to another collection, the behavior is undefined.
get
in interface SmartCollection<E>
ref
- the element's reference.public ElementReference referencedAdd(E elem)
SmartCollection
referencedAdd
in interface SmartCollection<E>
elem
- the element to be added.public ElementReference add(E elem, K key)
SmartGeneralPriorityQueue
add
in interface SmartGeneralPriorityQueue<E,K extends Comparable<K>>
elem
- the element to insert.key
- the key for this element.public void setDefaultKey(K defaultKey)
SmartGeneralPriorityQueue
setDefaultKey
in interface SmartGeneralPriorityQueue<E,K extends Comparable<K>>
defaultKey
- the new default key.public void changeKey(ElementReference ref, K newKey)
SmartGeneralPriorityQueue
changeKey
in interface SmartGeneralPriorityQueue<E,K extends Comparable<K>>
ref
- reference to the element whose key is to be changed.newKey
- the new key of this element.public void remove(ElementReference ref)
SmartCollection
If the reference does not belong to this collection, the behavior is undefined.
remove
in interface SmartCollection<E>
ref
- the reference to the element to be removed.public Iterator<ElementReference> referenceIterator()
SmartCollection
referenceIterator
in interface SmartCollection<E>
public void replace(ElementReference ref, E newElement)
SmartCollection
replace
in interface SmartCollection<E>
ref
- the reference of the element to be replaced.newElement
- the replacement.public int size()
size
in interface Collection<E>
size
in class AbstractCollection<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in class AbstractCollection<E>
public void clear()
clear
in interface Collection<E>
clear
in class AbstractCollection<E>
public E peekMin()
SmartPriorityQueue
peekMin
in interface SmartPriorityQueue<E>
public E extractMin()
SmartPriorityQueue
extractMin
in interface SmartPriorityQueue<E>
Copyright © 2020. All rights reserved.