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, 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(List<? extends E> init, List<K> keys)
public BackedGeneralPriorityQueue(Class<? extends SmartDynamicPriorityQueue<?>> backingClazz)
public BackedGeneralPriorityQueue(SmartDynamicPriorityQueue<?> backingQueue)
backingQueue
- the backing queue.public E choose()
SmartCollection
null
is returned. Note, however, that a
null
return value doesn't necessary mean that the
collection is empty, since it may contain null
elements.choose
in interface SmartCollection<E>
choose
in class AbstractSmartCollection<E>
null
.public ElementReference chooseRef()
SmartCollection
null
is returned. In contrast
to the above SmartCollection.choose()
, this method returns null
if and only if the collection is empty.chooseRef
in interface SmartCollection<E>
chooseRef
in class AbstractSmartCollection<E>
null
.public ElementReference find(Object element)
SmartCollection
null
is returned.find
in interface SmartCollection<E>
find
in class AbstractSmartCollection<E>
element
- the element to search for.null
.public E get(ElementReference ref)
SmartCollection
get
in interface SmartCollection<E>
ref
- the element's reference.public Iterator<ElementReference> referenceIterator()
SmartCollection
referenceIterator
in interface SmartCollection<E>
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 remove(ElementReference ref)
SmartCollection
remove
in interface SmartCollection<E>
ref
- the reference to the element to be removed.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 void clear()
clear
in interface Collection<E>
clear
in class AbstractCollection<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in class AbstractCollection<E>
public Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in class AbstractSmartCollection<E>
public int size()
size
in interface Collection<E>
size
in class AbstractCollection<E>
public void setDefaultKey(K defaultKey)
SmartGeneralPriorityQueue
setDefaultKey
in interface SmartGeneralPriorityQueue<E,K extends Comparable<K>>
defaultKey
- the new defualt 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 E extractMin()
SmartPriorityQueue
extractMin
in interface SmartPriorityQueue<E>
public E peekMin()
SmartPriorityQueue
peekMin
in interface SmartPriorityQueue<E>
public void deepClear()
SmartCollection
SmartCollection.quickClear()
.deepClear
in interface SmartCollection<E>
deepClear
in class AbstractSmartCollection<E>
public void quickClear()
SmartCollection
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>
Copyright © 2015. All Rights Reserved.