Skip to content

Commit b491082

Browse files
Added annotations for FibonacciHeap
1 parent 84edc67 commit b491082

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src.primitives/algorithms/FibonacciHeap.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
primitives.common.FibonacciHeap = function (isMaximum) {
1+
/**
2+
* Creates Fibonacci Heap structure
3+
*
4+
* @param {boolean} isMaximum Is maximum heap
5+
* @returns {FibonacciHeap} Returns new FibonacciHeap object
6+
*/
7+
primitives.common.FibonacciHeap = function (isMaximum) {
28
var root = null,
39
count = 0,
410
nodes = {};
511

12+
/**
13+
* @typedef {Object} HeapResult
14+
* @property {string} key Key
15+
* @property {number} priority Priority
16+
* @property {Object} item Context object
17+
*/
618
function Result(node) {
719
this.key = node.key;
820
this.priority = node.priority;
@@ -22,6 +34,11 @@
2234
this.right = null;
2335
}
2436

37+
/**
38+
* Validates internal structure consistency.
39+
*
40+
* @returns {boolean} Returns true if structure pass data consistency check.
41+
*/
2542
function validate() {
2643
var totalNodes = 0;
2744
for (var key in nodes) {
@@ -105,6 +122,12 @@
105122
}
106123
}
107124

125+
/**
126+
* Adds a new item into the heap
127+
* @param {string} key A key of the new element
128+
* @param {number} priority A priority of the new element
129+
* @param {object} item A context object of the new element
130+
*/
108131
function add(key, priority, item) {
109132
if (nodes.hasOwnProperty(key)) {
110133
throw "Duplicate keys are not supported!";
@@ -145,6 +168,11 @@
145168
node.left = node.key;
146169
}
147170

171+
/**
172+
* Gets priority of element by key
173+
* @param {string} key The element key
174+
* @returns {number} Returns priority of the element
175+
*/
148176
function getPriority(key) {
149177
var result = null;
150178
if (nodes.hasOwnProperty(key)) {
@@ -153,6 +181,11 @@
153181
return result;
154182
}
155183

184+
/**
185+
* Returns heap root element
186+
*
187+
* @returns {HeapResult} Returns root element of the heap
188+
*/
156189
function heapRoot() {
157190
var result = null;
158191
if (root != null) {
@@ -161,6 +194,11 @@
161194
return result;
162195
}
163196

197+
/**
198+
* Returns heap root element with removal
199+
*
200+
* @returns {HeapResult} Returns root element of the heap
201+
*/
164202
function extractRoot() {
165203
var result = heapRoot();
166204
if (result != null) {
@@ -240,6 +278,11 @@
240278
node2.parent = node1.key;
241279
}
242280

281+
/**
282+
* Sets priority of an element by key
283+
* @param {string} key The key of the element
284+
* @param {number} priority Priority
285+
*/
243286
function setPriority(key, priority) {
244287
var node = nodes[key];
245288
if (isMaximum ? node.priority > priority : node.priority < priority) {
@@ -284,6 +327,10 @@
284327
}
285328
}
286329

330+
/**
331+
* Deletes heap element by key
332+
* @param {string} key The Key
333+
*/
287334
function deleteKey(key) {
288335
setPriority(key, isMaximum ? Infinity : -1);
289336
extractRoot();

0 commit comments

Comments
 (0)