Class MockBinaryHeap<TKey, TValue>
Implements a mock heap to enable testing abstract class of BinaryHeapBase<TKey, TValue>.
Implements
Inherited Members
Namespace: AlgorithmsAndDataStructuresTests.DataStructures.BinaryHeaps.API
Assembly: AlgorithmsAndDataStructuresTests.dll
Syntax
public class MockBinaryHeap<TKey, TValue> : BinaryHeapBase<TKey, TValue>, IBinaryHeap<TKey, TValue> where TKey : IComparable<TKey>
Type Parameters
Name | Description |
---|---|
TKey | |
TValue |
Constructors
| Improve this Doc View SourceMockBinaryHeap(List<KeyValuePair<TKey, TValue>>)
Constructor
Declaration
public MockBinaryHeap(List<KeyValuePair<TKey, TValue>> array)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<TKey, TValue>> | array | An array of key-value pairs to be converted to a heap. |
Methods
| Improve this Doc View SourceBubbleDown_Iteratively(Int32, Int32)
Implements the bubble down/trickle down operation using iteration.
Declaration
public override void BubbleDown_Iteratively(int rootIndex, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rootIndex | The index of the root element, the element for which the trickle down should be performed. |
System.Int32 | heapArrayLength | The length of the heap array. |
Overrides
BubbleDown_Recursively(Int32, Int32)
Implements the bubble down/trickle down operation using recursion.
Declaration
public override void BubbleDown_Recursively(int rootIndex, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rootIndex | The index of the root element, the element for which the trickle down should be performed. |
System.Int32 | heapArrayLength | The length of the heap array. |
Overrides
BubbleUp_Iteratively(Int32, Int32)
Moves the value in the given index, up in the heap till its position is found. The position is defined such to respect heap ordering property.
Declaration
public override void BubbleUp_Iteratively(int index, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the element that should be bubbled up. |
System.Int32 | heapArrayLength | The length/size of the heap array. |
Overrides
BuildHeap_Iteratively(Int32)
Note that passing the array size is not a must, as the class itself contains the array and has access to its size. However some algorithms such as HeapSort which rely on a heap to perform sorting, are better implemented, if we have the length of the array passed to these methods.
Declaration
public override void BuildHeap_Iteratively(int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | heapArrayLength | The length of the heap array. |
Overrides
BuildHeap_Recursively(Int32)
Builds a heap using recursion, and does so in situ.
Declaration
public override void BuildHeap_Recursively(int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | heapArrayLength | The length of the heap array. |
Overrides
Insert(KeyValuePair<TKey, TValue>, Int32)
Inserts a new value into heap.
Declaration
public override void Insert(KeyValuePair<TKey, TValue> keyValue, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | keyValue | The key-value to be inserted into the heap. |
System.Int32 | heapArrayLength | The length of the heap array. |
Overrides
TryFindRoot(out KeyValuePair<TKey, TValue>, Int32)
Finds the root of the heap, without removing it.
Declaration
public override bool TryFindRoot(out KeyValuePair<TKey, TValue> keyValue, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | keyValue | The key-value of the root. |
System.Int32 | heapArrayLength | The length of the heap array. |
Returns
Type | Description |
---|---|
System.Boolean | True in case of success, and false in case of failure. |
Overrides
TryRemoveRoot(out KeyValuePair<TKey, TValue>, Int32)
Removes the root of the heap. In a MinHeap and MinMaxHeap this is the min, and in a MaxHeap and MaxMinHeap this is the max.
Declaration
public override bool TryRemoveRoot(out KeyValuePair<TKey, TValue> keyValue, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | keyValue | The key-value of the root. |
System.Int32 | heapArrayLength | The length of the heap array. |
Returns
Type | Description |
---|---|
System.Boolean | True in case of success, and false otherwise. |