Table of Contents

Class BinaryHeap<T>

Namespace
NMF.Expressions
Assembly
NMF.Expressions.dll

A binary heap, useful for sorting data and priority queues.

public class BinaryHeap<T> : ICollection<T>, IEnumerable<T>, IEnumerable

Type Parameters

T

The element type

Inheritance
BinaryHeap<T>
Implements
Inherited Members
Extension Methods

Constructors

BinaryHeap()

Creates a new binary heap

public BinaryHeap()

BinaryHeap(IComparer<T>)

Creates a new binary heap.

public BinaryHeap(IComparer<T> comparer)

Parameters

comparer IComparer<T>

The comparer used to compare the items

Properties

Capacity

Gets or sets the capacity of the heap.

public int Capacity { get; set; }

Property Value

int

Count

Gets the number of values in the heap.

public int Count { get; }

Property Value

int

IsReadOnly

Gets whether or not the binary heap is readonly.

public bool IsReadOnly { get; }

Property Value

bool

Methods

Add(T)

Adds a key and value to the heap.

public void Add(T item)

Parameters

item T

The item to add to the heap.

Clear()

Removes all items from the heap.

public void Clear()

Contains(T)

Checks to see if the binary heap contains the specified item.

public bool Contains(T item)

Parameters

item T

The item to search the binary heap for.

Returns

bool

A boolean, true if binary heap contains item.

Copy()

Creates a new instance of an identical binary heap.

public BinaryHeap<T> Copy()

Returns

BinaryHeap<T>

A BinaryHeap.

CopyTo(T[], int)

Copies the binary heap to an array at the specified index.

public void CopyTo(T[] array, int arrayIndex)

Parameters

array T[]

One dimensional array that is the destination of the copied elements.

arrayIndex int

The zero-based index at which copying begins.

GetEnumerator()

Gets an enumerator for the binary heap.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

An IEnumerator of type T.

Peek()

Gets the first value in the heap without removing it.

public T Peek()

Returns

T

The lowest value of type TValue.

Remove()

Removes and returns the first item in the heap.

public T Remove()

Returns

T

The next value in the heap.

Remove(T)

Removes an item from the binary heap. This utilizes the type T's Comparer and will not remove duplicates.

public bool Remove(T item)

Parameters

item T

The item to be removed.

Returns

bool

Boolean true if the item was removed.