Crystal AI  1.0.0
Crystal.PriorityQueue< TItem, TPriority > Class Template Reference

Priority queue. More...

Inheritance diagram for Crystal.PriorityQueue< TItem, TPriority >:
Crystal.IPriorityQueue< TItem, TPriority >

Public Member Functions

bool IsBinaryHeapValid ()
 Verifies if the heap is in a valid state. Use only for debugging. More...
 
TItem Peek ()
 Returns the item at the head of the queue without removing it. More...
 
void Enqueue (TItem item, TPriority priority)
 Enqueue a node to the priority queue. Lower values are placed in front. Ties are broken by first-in-first-out. If the queue is full, the result is undefined. If the node is already enqueued, the result is undefined. O(log n) More...
 
TItem Dequeue ()
 Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it. If queue is empty, result is undefined O(log n) More...
 
bool Contains (TItem item)
 Returns true if the queue has 1 or more of the specified items. More...
 
TItem Remove (TItem item)
 RemoveBehaviour the specified item. Note that the queue may contain multiples of the same item, in which case this removes the one that is closest to the head. More...
 
TItem Remove (Func< TItem, bool > predicate)
 RemoveBehaviour the specified item. Note that the queue may contain multiples of the same item, in which case this removes the one that is closest to the head. More...
 
void UpdatePriority (TItem item, TPriority priority)
 Updates the priority of the specified item. If the item does not exist in the queue, it simply returns. More...
 
void Clear ()
 Removes every node from the queue. More...
 
 PriorityQueue ()
 Initializes a new instance of the T:PriorityQueue`2 class. More...
 
 PriorityQueue (int maxNodes)
 Initializes a new instance of the T:Crystal.PriorityQueue`2 class. More...
 
- Public Member Functions inherited from Crystal.IPriorityQueue< TItem, TPriority >
TItem Peek ()
 Returns the item at the head of the queue without removing it. More...
 
void Enqueue (TItem item, TPriority priority)
 Enqueues an item to the list. Items with lower priority values are placed ahead of the queue. More...
 
TItem Dequeue ()
 Removes and returns the item at the head of the queue. In the event of a priority tie the item inserted first in the queue is returned. More...
 
bool Contains (TItem item)
 Returns true if the queue has 1 or more of the secified items. More...
 
TItem Remove (TItem item)
 RemoveBehaviour the specified item. Note that the queue may contain multiples of the same item, in which case this removes the one that is closest to the head. More...
 
TItem Remove (Func< TItem, bool > predicate)
 Removes the first item that matches the specified predicate. Note that the queue may contain multiples of the same item, in which case this removes the one that is closest to the head. More...
 
void UpdatePriority (TItem item, TPriority priority)
 Updates the priority of the specified item. If the item does not exist in the queue, it simply returns. More...
 
void Clear ()
 Removes every node from the queue. More...
 

Properties

bool HasNext [get]
 Returns true if there is an element at the head of the queue, i.e. if the queue is not empty. More...
 
int Count [get]
 Returns the number of nodes in the queue. O(1) More...
 
- Properties inherited from Crystal.IPriorityQueue< TItem, TPriority >
bool HasNext [get]
 Returns true if there is an element at the head of the queue, i.e. if the queue is not empty. More...
 
int Count [get]
 Returns the number of items in the queue. More...
 

Detailed Description

Priority queue.

Template Parameters
TItemThe type of the item.
TPriorityThe type of the priority.
See also
T:Crystal.IPriorityQueue`2
Type Constraints
TPriority :IComparable<TPriority> 

Constructor & Destructor Documentation

Crystal.PriorityQueue< TItem, TPriority >.PriorityQueue ( )
inline

Initializes a new instance of the T:PriorityQueue`2 class.

Crystal.PriorityQueue< TItem, TPriority >.PriorityQueue ( int  maxNodes)
inline

Initializes a new instance of the T:Crystal.PriorityQueue`2 class.

Parameters
maxNodesMax nodes.

Member Function Documentation

void Crystal.PriorityQueue< TItem, TPriority >.Clear ( )
inline

Removes every node from the queue.

bool Crystal.PriorityQueue< TItem, TPriority >.Contains ( TItem  item)
inline

Returns true if the queue has 1 or more of the specified items.

Parameters
itemItem.
TItem Crystal.PriorityQueue< TItem, TPriority >.Dequeue ( )
inline

Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it. If queue is empty, result is undefined O(log n)

void Crystal.PriorityQueue< TItem, TPriority >.Enqueue ( TItem  item,
TPriority  priority 
)
inline

Enqueue a node to the priority queue. Lower values are placed in front. Ties are broken by first-in-first-out. If the queue is full, the result is undefined. If the node is already enqueued, the result is undefined. O(log n)

bool Crystal.PriorityQueue< TItem, TPriority >.IsBinaryHeapValid ( )
inline

Verifies if the heap is in a valid state. Use only for debugging.

Returns
true if this instance is binary heap valid; otherwise, false.
TItem Crystal.PriorityQueue< TItem, TPriority >.Peek ( )
inline

Returns the item at the head of the queue without removing it.

TItem Crystal.PriorityQueue< TItem, TPriority >.Remove ( TItem  item)
inline

RemoveBehaviour the specified item. Note that the queue may contain multiples of the same item, in which case this removes the one that is closest to the head.

Parameters
itemItem.
TItem Crystal.PriorityQueue< TItem, TPriority >.Remove ( Func< TItem, bool >  predicate)
inline

RemoveBehaviour the specified item. Note that the queue may contain multiples of the same item, in which case this removes the one that is closest to the head.

void Crystal.PriorityQueue< TItem, TPriority >.UpdatePriority ( TItem  item,
TPriority  priority 
)
inline

Updates the priority of the specified item. If the item does not exist in the queue, it simply returns.

Parameters
itemItem.
priorityPriority.

Property Documentation

int Crystal.PriorityQueue< TItem, TPriority >.Count
get

Returns the number of nodes in the queue. O(1)

bool Crystal.PriorityQueue< TItem, TPriority >.HasNext
get

Returns true if there is an element at the head of the queue, i.e. if the queue is not empty.

true

false


The documentation for this class was generated from the following file: