Package minpq
Class DoubleMapMinPQ<E>
- java.lang.Object
-
- minpq.DoubleMapMinPQ<E>
-
-
Field Summary
Fields Modifier and Type Field Description private Map<E,Double>elementToPriorityMapof elements to their associated priority values.private NavigableMap<Double,Set<E>>priorityToElementNavigableMapof priority values to all elements that share the same priority values.
-
Constructor Summary
Constructors Constructor Description DoubleMapMinPQ()Constructs an empty instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(E element, double priority)Adds an element with the given priority value.voidchangePriority(E element, double priority)Updates the given elements' associated priority value.booleancontains(E element)Returns true if the given element is in this priority queue.private EfirstOf(Iterable<E> it)Returns any one element from the given iterable.EpeekMin()Returns the element with the minimum priority value.EremoveMin()Returns and removes the element with the minimum priority value.intsize()Returns the number of elements in this priority queue.
-
-
-
Field Detail
-
priorityToElement
private final NavigableMap<Double,Set<E>> priorityToElement
NavigableMapof priority values to all elements that share the same priority values.
-
-
Method Detail
-
add
public void add(E element, double priority)
Description copied from interface:MinPQAdds an element with the given priority value.
-
contains
public boolean contains(E element)
Description copied from interface:MinPQReturns true if the given element is in this priority queue.
-
peekMin
public E peekMin()
Description copied from interface:MinPQReturns the element with the minimum priority value.
-
removeMin
public E removeMin()
Description copied from interface:MinPQReturns and removes the element with the minimum priority value.
-
changePriority
public void changePriority(E element, double priority)
Description copied from interface:MinPQUpdates the given elements' associated priority value.- Specified by:
changePriorityin interfaceMinPQ<E>- Parameters:
element- the element whose associated priority value should be modified.priority- the updated priority value.
-
size
public int size()
Description copied from interface:MinPQReturns the number of elements in this priority queue.
-
-