Heap Class
Packages > @fluidframework/common-utils > Heap
Ordered Heap data structure implementation
Signature:
export declare class Heap<T>
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(comp) | Creates an instance of Heap with comparer |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
comp | IComparer |
Methods
Method | Modifiers | Description |
---|---|---|
add(x) | Add a value to the heap | |
count() | Get the number of elements in the Heap | |
get() | Get and remove the smallest element in the heap as determined by the order of the comparer | |
peek() | Return the smallest element in the heap as determined by the order of the comparer | |
remove(node) | Removes the given node from the heap | |
update(node) | Allows for heap to be updated after a node's value changes |
Constructors
Heap.(constructor)
Creates an instance of Heap with comparer
Signature:
constructor(comp: IComparer<T>);
Parameters
Parameter | Type | Description |
---|---|---|
comp | IComparer |
a comparer that specify how elements are ordered |
Properties
comp
Signature:
comp: IComparer<T>;
Methods
add
Add a value to the heap
Signature:
add(x: T): IHeapNode<T>;
Parameters
Parameter | Type | Description |
---|---|---|
x | T | value to add |
Returns:
IHeapNode<T>
the heap node that contains the value
count
Get the number of elements in the Heap
Signature:
count(): number;
Returns:
number
the number of elements in the Heap
get
Get and remove the smallest element in the heap as determined by the order of the comparer
Signature:
get(): T;
Returns:
T
the smallest value in the heap
peek
Return the smallest element in the heap as determined by the order of the comparer
Signature:
peek(): IHeapNode<T>;
Returns:
IHeapNode<T>
heap node containing the smallest element
remove
Removes the given node from the heap
Signature:
remove(node: IHeapNode<T>): void;
Parameters
Parameter | Type | Description |
---|---|---|
node | IHeapNode |
the node to remove from the heap |
Returns:
void
update
Allows for heap to be updated after a node’s value changes
Signature:
update(node: IHeapNode<T>): void;
Parameters
Parameter | Type | Description |
---|---|---|
node | IHeapNode |
Returns:
void