M&B: Bannerlord 1.1.0
The horns sound, the ravens gather.
Loading...
Searching...
No Matches
TaleWorlds.Library.PriorityQueue< TPriority, TValue > Class Template Reference

Priority queue based on binary heap, Elements with minimum priority dequeued first. More...

Inherits ICollection< KeyValuePair< TPriority, TValue > >.

Public Member Functions

 PriorityQueue ()
 Initializes a new instance of priority queue with default initial capacity and default priority comparer.
 
 PriorityQueue (int capacity)
 Initializes a new instance of priority queue with specified initial capacity and default priority comparer.
 
 PriorityQueue (int capacity, IComparer< TPriority > comparer)
 Initializes a new instance of priority queue with specified initial capacity and specified priority comparer.
 
 PriorityQueue (IComparer< TPriority > comparer)
 Initializes a new instance of priority queue with default initial capacity and specified priority comparer.
 
 PriorityQueue (IEnumerable< KeyValuePair< TPriority, TValue > > data)
 Initializes a new instance of priority queue with specified data and default priority comparer.
 
 PriorityQueue (IEnumerable< KeyValuePair< TPriority, TValue > > data, IComparer< TPriority > comparer)
 Initializes a new instance of priority queue with specified data and specified priority comparer.
 
void Enqueue (TPriority priority, TValue value)
 Enqueues element into priority queue.
 
KeyValuePair< TPriority, TValue > Dequeue ()
 Dequeues element with minimum priority and return its priority and value as KeyValuePair<TPriority,TValue>
 
TValue DequeueValue ()
 Dequeues element with minimum priority and return its value.
 
KeyValuePair< TPriority, TValue > Peek ()
 Returns priority and value of the element with minimun priority, without removing it from the queue.
 
TValue PeekValue ()
 Returns value of the element with minimun priority, without removing it from the queue.
 
void Add (KeyValuePair< TPriority, TValue > item)
 Enqueues element into priority queue.
 
void Clear ()
 Clears the collection.
 
bool Contains (KeyValuePair< TPriority, TValue > item)
 Determines whether the priority queue contains a specific element.
 
void CopyTo (KeyValuePair< TPriority, TValue >[] array, int arrayIndex)
 Copies the elements of the priority queue to an Array, starting at a particular Array index.
 
bool Remove (KeyValuePair< TPriority, TValue > item)
 Removes the first occurrence of a specific object from the priority queue.
 
IEnumerator< KeyValuePair< TPriority, TValue > > GetEnumerator ()
 Returns an enumerator that iterates through the collection.
 

Static Public Member Functions

static PriorityQueue< TPriority, TValue > MergeQueues (PriorityQueue< TPriority, TValue > pq1, PriorityQueue< TPriority, TValue > pq2)
 Merges two priority queues.
 
static PriorityQueue< TPriority, TValue > MergeQueues (PriorityQueue< TPriority, TValue > pq1, PriorityQueue< TPriority, TValue > pq2, IComparer< TPriority > comparer)
 Merges two priority queues and sets specified comparer for resultant priority queue.
 

Properties

bool IsEmpty [get]
 Gets whether priority queue is empty.
 
int Count [get]
 Gets number of elements in the priority queue.
 
bool IsReadOnly [get]
 Gets a value indicating whether the collection is read-only.
 

Detailed Description

Template Parameters
TPriorityType of priorities
TValueType of values

Constructor & Destructor Documentation

◆ PriorityQueue() [1/6]

◆ PriorityQueue() [2/6]

TaleWorlds.Library.PriorityQueue< TPriority, TValue >.PriorityQueue ( int  capacity)
Parameters
capacityinitial capacity

◆ PriorityQueue() [3/6]

TaleWorlds.Library.PriorityQueue< TPriority, TValue >.PriorityQueue ( int  capacity,
IComparer< TPriority >  comparer 
)
Parameters
capacityinitial capacity
comparerpriority comparer

◆ PriorityQueue() [4/6]

TaleWorlds.Library.PriorityQueue< TPriority, TValue >.PriorityQueue ( IComparer< TPriority >  comparer)
Parameters
comparerpriority comparer

◆ PriorityQueue() [5/6]

TaleWorlds.Library.PriorityQueue< TPriority, TValue >.PriorityQueue ( IEnumerable< KeyValuePair< TPriority, TValue > >  data)
Parameters
datadata to be inserted into priority queue

◆ PriorityQueue() [6/6]

TaleWorlds.Library.PriorityQueue< TPriority, TValue >.PriorityQueue ( IEnumerable< KeyValuePair< TPriority, TValue > >  data,
IComparer< TPriority >  comparer 
)
Parameters
datadata to be inserted into priority queue
comparerpriority comparer

Member Function Documentation

◆ MergeQueues() [1/2]

static PriorityQueue< TPriority, TValue > TaleWorlds.Library.PriorityQueue< TPriority, TValue >.MergeQueues ( PriorityQueue< TPriority, TValue >  pq1,
PriorityQueue< TPriority, TValue >  pq2 
)
static
Parameters
pq1first priority queue
pq2second priority queue
Returns
resultant priority queue

source priority queues must have equal comparers, otherwise InvalidOperationException will be thrown

◆ MergeQueues() [2/2]

static PriorityQueue< TPriority, TValue > TaleWorlds.Library.PriorityQueue< TPriority, TValue >.MergeQueues ( PriorityQueue< TPriority, TValue >  pq1,
PriorityQueue< TPriority, TValue >  pq2,
IComparer< TPriority >  comparer 
)
static
Parameters
pq1first priority queue
pq2second priority queue
comparercomparer for resultant priority queue
Returns
resultant priority queue

◆ Enqueue()

void TaleWorlds.Library.PriorityQueue< TPriority, TValue >.Enqueue ( TPriority  priority,
TValue  value 
)
Parameters
priorityelement priority
valueelement value

◆ Dequeue()

KeyValuePair< TPriority, TValue > TaleWorlds.Library.PriorityQueue< TPriority, TValue >.Dequeue ( )
Returns
priority and value of the dequeued element

Method throws InvalidOperationException if priority queue is empty

◆ DequeueValue()

TValue TaleWorlds.Library.PriorityQueue< TPriority, TValue >.DequeueValue ( )
Returns
value of the dequeued element

Method throws InvalidOperationException if priority queue is empty

◆ Peek()

KeyValuePair< TPriority, TValue > TaleWorlds.Library.PriorityQueue< TPriority, TValue >.Peek ( )
Returns
priority and value of the element with minimum priority

Method throws InvalidOperationException if priority queue is empty

◆ PeekValue()

TValue TaleWorlds.Library.PriorityQueue< TPriority, TValue >.PeekValue ( )
Returns
value of the element with minimum priority

Method throws InvalidOperationException if priority queue is empty

◆ Add()

void TaleWorlds.Library.PriorityQueue< TPriority, TValue >.Add ( KeyValuePair< TPriority, TValue >  item)
Parameters
itemelement to add

◆ Clear()

void TaleWorlds.Library.PriorityQueue< TPriority, TValue >.Clear ( )

◆ Contains()

bool TaleWorlds.Library.PriorityQueue< TPriority, TValue >.Contains ( KeyValuePair< TPriority, TValue >  item)
Parameters
itemThe object to locate in the priority queue
Returns
true if item is found in the priority queue; otherwise, false.

◆ CopyTo()

void TaleWorlds.Library.PriorityQueue< TPriority, TValue >.CopyTo ( KeyValuePair< TPriority, TValue >[]  array,
int  arrayIndex 
)
Parameters
arrayThe one-dimensional Array that is the destination of the elements copied from the priority queue. The Array must have zero-based indexing.
arrayIndexThe zero-based index in array at which copying begins.

It is not guaranteed that items will be copied in the sorted order.

◆ Remove()

bool TaleWorlds.Library.PriorityQueue< TPriority, TValue >.Remove ( KeyValuePair< TPriority, TValue >  item)
Parameters
itemThe object to remove from the ICollection <(Of <(T >)>).
Returns
true if item was successfully removed from the priority queue. This method returns false if item is not found in the collection.

◆ GetEnumerator()

IEnumerator< KeyValuePair< TPriority, TValue > > TaleWorlds.Library.PriorityQueue< TPriority, TValue >.GetEnumerator ( )
Returns
Enumerator

Returned enumerator does not iterate elements in sorted order.

Property Documentation

◆ IsEmpty

bool TaleWorlds.Library.PriorityQueue< TPriority, TValue >.IsEmpty
get

◆ Count

int TaleWorlds.Library.PriorityQueue< TPriority, TValue >.Count
get

◆ IsReadOnly

bool TaleWorlds.Library.PriorityQueue< TPriority, TValue >.IsReadOnly
get

For priority queue this property returns false.