Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a84957

Browse files
committed
Merge pull request mgechev#78 from Jakehp/master
Added docs to Hash table.
2 parents 721cb40 + 49d594a commit 5a84957

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

src/data-structures/hash-table.js

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,42 @@
2626
(function (exports) {
2727
'use strict';
2828

29+
/**
30+
* Constructs a Node to store data and next/prev nodes in Hash table.
31+
*
32+
* @public
33+
* @constructor
34+
* @param {Number|String} key Key of the node.
35+
* @param {Number|String} data Data to be stored in hash table.
36+
*/
2937
exports.Node = function (key, data) {
3038
this.key = key;
3139
this.data = data;
3240
this.next = undefined;
3341
this.prev = undefined;
3442
};
3543

44+
/**
45+
* Construct a Hash table..
46+
*
47+
* @public
48+
* @constructor
49+
*/
3650
exports.Hashtable = function () {
3751
this.buckets = [];
3852
// The higher the bucket count; less likely for collisions.
3953
this.maxBucketCount = 100;
4054
};
4155

42-
/*
43-
Using simple non-crypto x->integer based hash.
44-
*/
56+
/**
57+
* Simple non-crypto hash used to hash keys, which determines
58+
* while bucket the value will be placed in.
59+
* A javascript implementation of Java's 32bitint hash.
60+
*
61+
* @public
62+
* @method
63+
* @param {Number|String} val Key to be hashed.
64+
*/
4565
exports.Hashtable.prototype.hashCode = function (val) {
4666
var i;
4767
var hashCode = 0;
@@ -63,6 +83,14 @@
6383
return hashCode;
6484
};
6585

86+
/**
87+
* Puts data into the table based on hashed key value.
88+
*
89+
* @public
90+
* @method
91+
* @param {Number|String} key Key for data.
92+
* @param {Number|String} data Data to be stored in table.
93+
*/
6694
exports.Hashtable.prototype.put = function (key, data, hashCode) {
6795
/*
6896
Make collision testing easy with optional hashCode parameter.
@@ -104,6 +132,13 @@
104132
newNode.prev = first;
105133
};
106134

135+
/**
136+
* Get's data from the table based on key.
137+
*
138+
* @public
139+
* @method
140+
* @param {Number|String} key Key for data to be retrieved.
141+
*/
107142
exports.Hashtable.prototype.get = function (key, hashCode) {
108143
/*
109144
Make collision testing easy with optional hashCode parameter.
@@ -143,6 +178,13 @@
143178
}
144179
};
145180

181+
/**
182+
* Removes data from the table based on key.
183+
*
184+
* @public
185+
* @method
186+
* @param {Number|String} key Key of the data to be removed.
187+
*/
146188
exports.Hashtable.prototype.remove = function (key, hashCode) {
147189
/*
148190
Make collision testing easy with optional hashCode parameter.

0 commit comments

Comments
 (0)