PrioritySearchQueue

class PrioritySearchQueue[A, P, K]

Container whose elements have two different orders: by priority and by lookup key.

Supports efficient implementation of the following operations:

  • insertion (O(log n)),
  • lookup by key (O(log n)),
  • deletion by key (O(log n)),
  • access to minimal-by-priority element (O(1)),
  • deletion of minimal-by-priority element (O(log n)).

Implemented using FingerTree.

Type Params
A

element type

K

lookup key. Unique—the queue holds at most one element with any given key.

P

priority of an element. Multiple elements can have the same priority.

Companion
object
class Object
trait Matchable
class Any

Value members

Concrete methods

def containsKey(key: K)(implicit K: Order[K]): Boolean
def deleteLt(p: P)(implicit P: Order[P]): PrioritySearchQueue[A, P, K]

Removes elements with priority less than p.

Removes elements with priority less than p.

''O(min(k*log(n), (n-k)*log(n), n))'', where ''k'' is the number of actually removed elements. For large ''k'', this method is more efficient than iterated deleteMin.

To also return the removed elements, use splitBeforePrio.

def deleteLte(p: P)(implicit P: Order[P]): PrioritySearchQueue[A, P, K]

Removes elements with priority less than or equal to p.

Removes elements with priority less than or equal to p.

''O(min(k*log(n), (n-k)*log(n), n))'', where ''k'' is the number of actually removed elements. For large ''k'', this method is more efficient than iterated deleteMin.

To also return the removed elements, use splitAfterPrio.

def deleteMin(implicit P: Order[P]): PrioritySearchQueue[A, P, K]

Removes an element with minimum priority.

Removes an element with minimum priority.

If there are multiple elements with the same minimum priority, it is guaranteed to remove the one returned by minimum.

''O(log(n))''.

If this queue is empty, returns this.

def get(key: K)(implicit K: Order[K]): Maybe[A]

Looks up an element by key.

Looks up an element by key.

def insert(elem: A)(implicit K: Order[K]): (PrioritySearchQueue[A, P, K], Maybe[A])

Inserts the given element into this queue.

Inserts the given element into this queue.

If an element with the same key is already present in this queue, it is replaced by elem and the replaced element is returned in the second part of the returned pair.

def isEmpty: Boolean
def minimum: Maybe[A]

Returns an element with minimum priority, or Maybe.Empty if this queue is empty.

Returns an element with minimum priority, or Maybe.Empty if this queue is empty.

If there are multiple elements with the same minimum priority, it is unspecified which of them is returned.

def nonEmpty: Boolean
def removeByKey(key: K)(implicit K: Order[K]): (PrioritySearchQueue[A, P, K], Maybe[A])

Removes an element by key.

Removes an element by key.

Returns the removed element, if any, in the second part of the returned pair.

def size: Int
def splitAfterPrio(p: P)(implicit P: Order[P]): (PrioritySearchQueue[A, P, K], PrioritySearchQueue[A, P, K])

Splits this queue into elements with priority less than or equal to p and elements with priority greater than p.

Splits this queue into elements with priority less than or equal to p and elements with priority greater than p.

def splitBeforePrio(p: P)(implicit P: Order[P]): (PrioritySearchQueue[A, P, K], PrioritySearchQueue[A, P, K])

Splits this queue into elements with priority less than p and elements with priority greater than or equal to p.

Splits this queue into elements with priority less than p and elements with priority greater than or equal to p.

def toUnsortedList: List[A]