Show / Hide Table of Contents

Class BinaryHeap<TPriority, TValue>

Binary heap.

Inheritance
System.Object
BinaryHeap<TPriority, TValue>
Implements
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TPriority, TValue>>
System.Collections.IEnumerable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
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 Source

BinaryHeap()

Initializes a new instance of the BinaryHeap<TPriority, TValue> class.

Declaration
public BinaryHeap()
| Improve this Doc View Source

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

priorityComparison is null.

| Improve this Doc View Source

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

capacity is negative.

| Improve this Doc View Source

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

priorityComparison is null.

System.ArgumentOutOfRangeException

capacity is negative.

Properties

| Improve this Doc View Source

Capacity

Heap capacity.

Declaration
public int Capacity { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

Count

Number of element.

Declaration
public int Count { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

PriorityComparison

Priority comparer.

Declaration
public Comparison<TPriority> PriorityComparison { get; }
Property Value
Type Description
System.Comparison<TPriority>

Methods

| Improve this Doc View Source

Add(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.

| Improve this Doc View Source

GetEnumerator()

Declaration
public IEnumerator<KeyValuePair<TPriority, TValue>> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TPriority, TValue>>
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

ToArray()

Gets all heap values.

Declaration
public TValue[] ToArray()
Returns
Type Description
TValue[]

Array of heap values.

| Improve this Doc View Source

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.

| Improve this Doc View Source

ToString2()

Gets a string representation of this heap.

Declaration
public string ToString2()
Returns
Type Description
System.String

String representation.

| Improve this Doc View Source

ToStringTree()

Gets a string tree representation of this heap.

Declaration
public string ToStringTree()
Returns
Type Description
System.String

String representation.

| Improve this Doc View Source

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 Source

IEnumerable.GetEnumerator()

Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator

Implements

System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable

Extension Methods

GraphMLExtensions.SerializeToGraphML<TVertex, TEdge, TGraph>(TGraph, String)
GraphMLExtensions.SerializeToGraphML<TVertex, TEdge, TGraph>(TGraph, String, VertexIdentity<TVertex>, EdgeIdentity<TVertex, TEdge>)
GraphMLExtensions.SerializeToGraphML<TVertex, TEdge, TGraph>(TGraph, XmlWriter)
GraphMLExtensions.SerializeToGraphML<TVertex, TEdge, TGraph>(TGraph, XmlWriter, VertexIdentity<TVertex>, EdgeIdentity<TVertex, TEdge>)
GraphMLExtensions.DeserializeFromGraphML<TVertex, TEdge, TGraph>(TGraph, XmlReader, IdentifiableVertexFactory<TVertex>, IdentifiableEdgeFactory<TVertex, TEdge>)
GraphMLExtensions.DeserializeFromGraphML<TVertex, TEdge, TGraph>(TGraph, TextReader, IdentifiableVertexFactory<TVertex>, IdentifiableEdgeFactory<TVertex, TEdge>)
GraphMLExtensions.DeserializeFromGraphML<TVertex, TEdge, TGraph>(TGraph, String, IdentifiableVertexFactory<TVertex>, IdentifiableEdgeFactory<TVertex, TEdge>)
GraphMLExtensions.DeserializeAndValidateFromGraphML<TVertex, TEdge, TGraph>(TGraph, TextReader, IdentifiableVertexFactory<TVertex>, IdentifiableEdgeFactory<TVertex, TEdge>)
SerializationExtensions.SerializeToXml<TVertex, TEdge, TGraph>(TGraph, XmlWriter, VertexIdentity<TVertex>, EdgeIdentity<TVertex, TEdge>, String, String, String, String)
SerializationExtensions.SerializeToXml<TVertex, TEdge, TGraph>(TGraph, XmlWriter, VertexIdentity<TVertex>, EdgeIdentity<TVertex, TEdge>, String, String, String, String, Action<XmlWriter, TGraph>, Action<XmlWriter, TVertex>, Action<XmlWriter, TEdge>)
EdgeExtensions.IsPath<TVertex, TEdge>(IEnumerable<TEdge>)
EdgeExtensions.HasCycles<TVertex, TEdge>(IEnumerable<TEdge>)
EdgeExtensions.IsPathWithoutCycles<TVertex, TEdge>(IEnumerable<TEdge>)
GraphExtensions.ToDelegateVertexAndEdgeListGraph<TVertex, TEdge>(IEnumerable<TVertex>, TryFunc<TVertex, IEnumerable<TEdge>>)
GraphExtensions.ToDelegateVertexAndEdgeListGraph<TVertex, TEdge>(IEnumerable<TVertex>, Func<TVertex, IEnumerable<TEdge>>)
GraphExtensions.ToDelegateUndirectedGraph<TVertex, TEdge>(IEnumerable<TVertex>, TryFunc<TVertex, IEnumerable<TEdge>>)
GraphExtensions.ToDelegateUndirectedGraph<TVertex, TEdge>(IEnumerable<TVertex>, Func<TVertex, IEnumerable<TEdge>>)
GraphExtensions.ToAdjacencyGraph<TVertex, TEdge>(IEnumerable<TEdge>, Boolean)
GraphExtensions.ToAdjacencyGraph<TVertex, TEdge>(IEnumerable<TVertex>, Func<TVertex, IEnumerable<TEdge>>, Boolean)
GraphExtensions.ToBidirectionalGraph<TVertex, TEdge>(IEnumerable<TEdge>, Boolean)
GraphExtensions.ToBidirectionalGraph<TVertex, TEdge>(IEnumerable<TVertex>, Func<TVertex, IEnumerable<TEdge>>, Boolean)
GraphExtensions.ToUndirectedGraph<TVertex, TEdge>(IEnumerable<TEdge>, Boolean)
AlgorithmExtensions.IsDirectedAcyclicGraph<TVertex, TEdge>(IEnumerable<TEdge>)
AlgorithmExtensions.IsUndirectedAcyclicGraph<TVertex, TEdge>(IEnumerable<TEdge>)
  • Improve this Doc
  • View Source
In This Article
Back to top QuikGraph