|
26 | 26 | (function (exports) {
|
27 | 27 | 'use strict';
|
28 | 28 |
|
| 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 | + */ |
29 | 37 | exports.Node = function (key, data) {
|
30 | 38 | this.key = key;
|
31 | 39 | this.data = data;
|
32 | 40 | this.next = undefined;
|
33 | 41 | this.prev = undefined;
|
34 | 42 | };
|
35 | 43 |
|
| 44 | + /** |
| 45 | + * Construct a Hash table.. |
| 46 | + * |
| 47 | + * @public |
| 48 | + * @constructor |
| 49 | + */ |
36 | 50 | exports.Hashtable = function () {
|
37 | 51 | this.buckets = [];
|
38 | 52 | // The higher the bucket count; less likely for collisions.
|
39 | 53 | this.maxBucketCount = 100;
|
40 | 54 | };
|
41 | 55 |
|
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 | + */ |
45 | 65 | exports.Hashtable.prototype.hashCode = function (val) {
|
46 | 66 | var i;
|
47 | 67 | var hashCode = 0;
|
|
63 | 83 | return hashCode;
|
64 | 84 | };
|
65 | 85 |
|
| 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 | + */ |
66 | 94 | exports.Hashtable.prototype.put = function (key, data, hashCode) {
|
67 | 95 | /*
|
68 | 96 | Make collision testing easy with optional hashCode parameter.
|
|
104 | 132 | newNode.prev = first;
|
105 | 133 | };
|
106 | 134 |
|
| 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 | + */ |
107 | 142 | exports.Hashtable.prototype.get = function (key, hashCode) {
|
108 | 143 | /*
|
109 | 144 | Make collision testing easy with optional hashCode parameter.
|
|
143 | 178 | }
|
144 | 179 | };
|
145 | 180 |
|
| 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 | + */ |
146 | 188 | exports.Hashtable.prototype.remove = function (key, hashCode) {
|
147 | 189 | /*
|
148 | 190 | Make collision testing easy with optional hashCode parameter.
|
|
0 commit comments