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(Class<? extends SmartDynamicPriorityQueue<?>> backingClazz) |
BackedGeneralPriorityQueue(int initialCapacity) |
BackedGeneralPriorityQueue(List<? extends E> init,
List<K> keys) |
BackedGeneralPriorityQueue(SmartDynamicPriorityQueue<?> backingQueue)
Constructor.
|
| 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 remove the element with the minimum key in the priority queue.
|
ElementReference |
find(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, removeaddAll, contains, containsAll, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddAll, addAll, references, removeadd, addAll, contains, containsAll, equals, hashCode, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArraypublic BackedGeneralPriorityQueue()
public BackedGeneralPriorityQueue(int initialCapacity)
public BackedGeneralPriorityQueue(Class<? extends SmartDynamicPriorityQueue<?>> backingClazz)
public BackedGeneralPriorityQueue(SmartDynamicPriorityQueue<?> backingQueue)
backingQueue - the backing queue.public E choose()
SmartCollectionNoSuchElementException
is thrownchoose in interface SmartCollection<E>choose in class AbstractSmartCollection<E>public ElementReference chooseRef()
SmartCollectionNoSuchElementException is thrown.chooseRef in interface SmartCollection<E>chooseRef in class AbstractSmartCollection<E>public ElementReference find(Object element)
SmartCollectionnull
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()
SmartCollectionSmartCollection.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)
SmartCollectionIf 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)
SmartCollectionreferencedAdd in interface SmartCollection<E>elem - the element to be added.public ElementReference add(E elem, K key)
SmartGeneralPriorityQueueadd in interface SmartGeneralPriorityQueue<E,K extends Comparable<K>>elem - the element to insert.key - the key for this element.public void setDefaultKey(K defaultKey)
SmartGeneralPriorityQueuesetDefaultKey in interface SmartGeneralPriorityQueue<E,K extends Comparable<K>>defaultKey - the new defualt key.public void changeKey(ElementReference ref, K newKey)
SmartGeneralPriorityQueuechangeKey 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)
SmartCollectionIf 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()
SmartCollectionreferenceIterator in interface SmartCollection<E>public void replace(ElementReference ref, E newElement)
SmartCollectionreplace 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()
SmartPriorityQueuepeekMin in interface SmartPriorityQueue<E>public E extractMin()
SmartPriorityQueueextractMin in interface SmartPriorityQueue<E>Copyright © 2018. All rights reserved.