Summer.Batch.Common.Collections.PriorityQueue< T > Class Template Reference

More...

Inheritance diagram for Summer.Batch.Common.Collections.PriorityQueue< T >:
Summer.Batch.Common.Collections.AbstractPriorityQueue< T > Summer.Batch.Common.Collections.IQueue< T >

Public Member Functions

 PriorityQueue (IComparer< T > comparer=null)
 Constructs a new priority queue with a default capacity and no elements. More...
 
 PriorityQueue (int capacity, IComparer< T > comparer=null)
 Constructs a new priority queue with the specified capacity and no elements. More...
 
 PriorityQueue (IEnumerable< T > enumerable, IComparer< T > comparer=null)
 Constructs a new priority queue and initializes it with the given elements. More...
 
override T Poll ()
 Removes the head of the queue and returns it. More...
 
override void Add (T item)
 Adds an item to the queue. The item is added at the correct position according to the current order. More...
 
override void Clear ()
 Removes all elements from the queue. More...
 
override bool Contains (T item)
 Checks if an element is inside the queue. The comparison is done using the current order rather than object.Equals(object). More...
 
override bool Remove (T item)
 Removes an item from the queue. More...
 
- Public Member Functions inherited from Summer.Batch.Common.Collections.AbstractPriorityQueue< T >
virtual T Peek ()
 Returns the head of the queue without removing it. More...
 
virtual void CopyTo (T[] array, int arrayIndex)
 Copies the elements of the queue to an array, preserving the order. More...
 
IEnumerator< T > GetEnumerator ()
 

Additional Inherited Members

- Protected Member Functions inherited from Summer.Batch.Common.Collections.AbstractPriorityQueue< T >
 AbstractPriorityQueue (IComparer< T > comparer=null)
 Constructs a new priority queue with a default capacity and no elements. More...
 
 AbstractPriorityQueue (int capacity, IComparer< T > comparer=null)
 Constructs a new priority queue with the specified capacity and no elements. More...
 
 AbstractPriorityQueue (IEnumerable< T > enumerable, IComparer< T > comparer=null)
 Constructs a new priority queue and initializes it with the given elements. More...
 
DoPoll ()
 Removes the head and returns it. More...
 
void DoAdd (T item)
 Adds an item to the queue. More...
 
void DoClear ()
 Clears the queue. More...
 
bool DoRemove (T item)
 Removes an item from the queue. More...
 
bool DoContains (T item)
 Checks if an item is present in the queue. More...
 
- Properties inherited from Summer.Batch.Common.Collections.AbstractPriorityQueue< T >
IComparer< T > Comparer [get, protected set]
 The comparer used to order the elements in the queue. Can be null if T implements IComparable<T>. More...
 
virtual int Count [get]
 The number of elements in the queue. More...
 
bool IsReadOnly [get]
 Always false More...
 
int Capacity [get, set]
 The internal capacity of the internal array. It is automatically expended when needed. Can be set if it can be estimated, thus avoiding multiple resize, or to reduce its size if the number of elements has been considerably reduced. More...
 

Detailed Description

A queue where elements are ordered by a IComparer<T> or according to their natural order if they implement IComparable<T>. The comparer always takes precedence.

The head of the queue is the minimum element with respect to the order. Ties are allowed and are broken arbitrarily.

Time complexity for Add, Contains, and Remove is O(log(n)). Time complexity for Poll and AbstractPriorityQueue<T>.Peek is O(1).

This implementation is NOT thread-safe.

Template Parameters
T The type of the elements in the queue.

Constructor & Destructor Documentation

Summer.Batch.Common.Collections.PriorityQueue< T >.PriorityQueue ( IComparer< T >  comparer = null)

Constructs a new priority queue with a default capacity and no elements.

Parameters
comparerthe comparer to use for ordering elements
Exceptions
InvalidOperationException  if T does not implement IComparable<T> and comparer is null.
Summer.Batch.Common.Collections.PriorityQueue< T >.PriorityQueue ( int  capacity,
IComparer< T >  comparer = null 
)

Constructs a new priority queue with the specified capacity and no elements.

Parameters
capacitythe initial capacity
comparerthe comparer to use for ordering elements
Exceptions
InvalidOperationException  if T does not implement IComparable<T> and comparer is null.
Summer.Batch.Common.Collections.PriorityQueue< T >.PriorityQueue ( IEnumerable< T >  enumerable,
IComparer< T >  comparer = null 
)

Constructs a new priority queue and initializes it with the given elements.

Parameters
enumerablean enumerable containing the initial elements
comparerthe comparer to use for ordering elements
Exceptions
InvalidOperationException  if T does not implement IComparable<T> and comparer is null.

Member Function Documentation

override void Summer.Batch.Common.Collections.PriorityQueue< T >.Add ( item)
virtual

Adds an item to the queue. The item is added at the correct position according to the current order.

Parameters
itemthe item to add

Implements Summer.Batch.Common.Collections.AbstractPriorityQueue< T >.

override void Summer.Batch.Common.Collections.PriorityQueue< T >.Clear ( )
virtual

Removes all elements from the queue.

Implements Summer.Batch.Common.Collections.AbstractPriorityQueue< T >.

override bool Summer.Batch.Common.Collections.PriorityQueue< T >.Contains ( item)
virtual

Checks if an element is inside the queue. The comparison is done using the current order rather than object.Equals(object).

Parameters
itemthe item to check
Returns
true if there is an item with the same order as item ; false otherwise

Implements Summer.Batch.Common.Collections.AbstractPriorityQueue< T >.

override T Summer.Batch.Common.Collections.PriorityQueue< T >.Poll ( )
virtual

Removes the head of the queue and returns it.

Returns
the head of the queue

Implements Summer.Batch.Common.Collections.AbstractPriorityQueue< T >.

override bool Summer.Batch.Common.Collections.PriorityQueue< T >.Remove ( item)
virtual

Removes an item from the queue.

Parameters
itemthe item to remove
Returns
true if the item was removed from the queue; false otherwise

Implements Summer.Batch.Common.Collections.AbstractPriorityQueue< T >.


The documentation for this class was generated from the following file:
  • Summer.Batch.Common/Collections/PriorityQueue.cs