Class BinaryHeap<TPriority, TValue>
Binary heap.
Inheritance
Implements
Inherited Members
Namespace: QuikGraph.Collections
Assembly: QuikGraph.dll
Syntax
[Serializable]
public class BinaryHeap<TPriority, TValue> : IEnumerable<KeyValuePair<TPriority, TValue>>, IEnumerable
Type Parameters
| Name | Description |
|---|---|
| TPriority | Priority metric type. |
| TValue | Value type. |
Remarks
Indexing rules:
parent index: (index - 1)/2 left child: 2 * index + 1 right child: 2 * index + 2
Reference: http://dotnetslackers.com/Community/files/folders/data-structures-and-algorithms/entry28722.aspx
Constructors
| Improve this Doc View SourceBinaryHeap()
Initializes a new instance of the BinaryHeap<TPriority, TValue> class.
Declaration
public BinaryHeap()
BinaryHeap(Comparison<TPriority>)
Initializes a new instance of the BinaryHeap<TPriority, TValue> class.
Declaration
public BinaryHeap(Comparison<TPriority> priorityComparison)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Comparison<TPriority> | priorityComparison | Priority comparer. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
BinaryHeap(Int32)
Initializes a new instance of the BinaryHeap<TPriority, TValue> class.
Declaration
public BinaryHeap(int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | capacity | Heap capacity. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentOutOfRangeException |
|
BinaryHeap(Int32, Comparison<TPriority>)
Initializes a new instance of the BinaryHeap<TPriority, TValue> class.
Declaration
public BinaryHeap(int capacity, Comparison<TPriority> priorityComparison)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | capacity | Heap capacity. |
| System.Comparison<TPriority> | priorityComparison | Priority comparer. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
| System.ArgumentOutOfRangeException |
|
Properties
| Improve this Doc View SourceCapacity
Heap capacity.
Declaration
public int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Count
Number of element.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
PriorityComparison
Priority comparer.
Declaration
public Comparison<TPriority> PriorityComparison { get; }
Property Value
| Type | Description |
|---|---|
| System.Comparison<TPriority> |
Methods
| Improve this Doc View SourceAdd(TPriority, TValue)
Adds the given value (with priority) into the heap.
Declaration
public void Add(TPriority priority, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TPriority | priority | Item priority. |
| TValue | value | The value. |
GetEnumerator()
Declaration
public IEnumerator<KeyValuePair<TPriority, TValue>> GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TPriority, TValue>> |
IndexOf(TValue)
Gets the index of the given value in the heap.
Declaration
public int IndexOf(TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TValue | value | The value. |
Returns
| Type | Description |
|---|---|
| System.Int32 | Index of the value if found, otherwise -1. |
Minimum()
Gets the minimum pair.
Declaration
public KeyValuePair<TPriority, TValue> Minimum()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.KeyValuePair<TPriority, TValue> | The minimal pair. |
Exceptions
| Type | Condition |
|---|---|
| System.InvalidOperationException | The heap is empty. |
MinimumUpdate(TPriority, TValue)
Updates the priority of the given value if the new priority is lower
than the current value priority (or add it if not present).
Declaration
public bool MinimumUpdate(TPriority priority, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TPriority | priority | The priority. |
| TValue | value | The value. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the heap was updated, false otherwise. |
RemoveMinimum()
Gets and removes the minimal pair.
Declaration
public KeyValuePair<TPriority, TValue> RemoveMinimum()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.KeyValuePair<TPriority, TValue> | The minimal pair. |
Exceptions
| Type | Condition |
|---|---|
| System.InvalidOperationException | The heap is empty. |
ToArray()
Gets all heap values.
Declaration
public TValue[] ToArray()
Returns
| Type | Description |
|---|---|
| TValue[] | Array of heap values. |
ToPairsArray()
Gets all values with their priorities.
Declaration
public KeyValuePair<TPriority, TValue>[] ToPairsArray()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.KeyValuePair<TPriority, TValue>[] | Array of heap priorities and values. |
ToString2()
Gets a string representation of this heap.
Declaration
public string ToString2()
Returns
| Type | Description |
|---|---|
| System.String | String representation. |
ToStringTree()
Gets a string tree representation of this heap.
Declaration
public string ToStringTree()
Returns
| Type | Description |
|---|---|
| System.String | String representation. |
Update(TPriority, TValue)
Updates the priority of the given value (or add it if not present).
Declaration
public void Update(TPriority priority, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TPriority | priority | The priority. |
| TValue | value | The value. |
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator |