Click or drag to resize

HeapBaseTElement Class

General base class for all Heap classes. A heap is a specialized tree-based datastructure which has its elements ordered in such a way that every parent is larger / equal than its children, if the heap is a max-heap and in the case of a min-heap every parent is smaller/equal than its children. See: http://en.wikipedia.org/wiki/Heap_%28data_structure%29
The heap classes implement the basic operations on a heap: delete max/min, increase/decrease key, insert and merge.
Inheritance Hierarchy

Namespace:  SD.Tools.Algorithmia.Heaps
Assembly:  SD.Tools.Algorithmia (in SD.Tools.Algorithmia.dll) Version: 1.3.3.0 (1.3.18.0209)
Syntax
public abstract class HeapBase<TElement>
where TElement : class

Type Parameters

TElement
The type of the elements in this heap

The HeapBaseTElement type exposes the following members.

Constructors
  NameDescription
Protected methodHeapBaseTElement
Initializes a new instance of the HeapBaseTElement class.
Top
Properties
  NameDescription
Public propertyCount
Gets the number of elements in the heap.
Protected propertyElementCompareFunc
Gets the element compare func, which is the func to compare two elements based on the heap type: the function returns true if the first element is indeed the correct parent of the second element or false if not.
Public propertyIsMinHeap
Gets a value indicating whether this instance is a min heap (true) or a max heap (false)
Protected propertyKeyCompareFunc
Gets the key compare func to compare elements based on key.
Public propertyRoot
Gets the root of the heap. Depending on the fact if this is a min or max heap, it returns the element with the minimum key (min heap) or the element with the maximum key (max heap). If the heap is empty, null / default is returned
Top
Methods
  NameDescription
Public methodClear
Clears all elements from the heap
Public methodContains
Determines whether this heap contains the element specified
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodExtractRoot
Extracts and removes the root of the heap.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodInsert
Inserts the specified element into the heap at the right spot
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRemove
Removes the element specified
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodUpdateKeyTKeyType
Updates the key of the element passed in. Only use this method for elements where the key is a property of the element, not the element itself. This means that if you have a heap with value typed elements (e.g. integers), updating the key is updating the value of the element itself, and because a heap might contain elements with the same value, this could lead to undefined results.
Top
Remarks
As this class can both handle min heaps as well as max heaps, the delete max/min is called 'ExtractRoot'. The increase/decrease key method is called 'UpdateKey'.

Heaps can't store value types. This is because changing a value type really makes it a different value, while changing the contents of an object doesn't make it a different object.

See Also