diff --git a/data-structures_hash-table.js.html b/data-structures_hash-table.js.html index b524bb5c..07788ef2 100644 --- a/data-structures_hash-table.js.html +++ b/data-structures_hash-table.js.html @@ -54,6 +54,14 @@

Source: data-structures/hash-table.js

(function (exports) { 'use strict'; + /** + * Constructs a Node to store data and next/prev nodes in Hash table. + * + * @public + * @constructor + * @param {Number|String} key Key of the node. + * @param {Number|String} data Data to be stored in hash table. + */ exports.Node = function (key, data) { this.key = key; this.data = data; @@ -61,15 +69,27 @@

Source: data-structures/hash-table.js

this.prev = undefined; }; + /** + * Construct a Hash table.. + * + * @public + * @constructor + */ exports.Hashtable = function () { this.buckets = []; // The higher the bucket count; less likely for collisions. this.maxBucketCount = 100; }; - /* - Using simple non-crypto x->integer based hash. - */ + /** + * Simple non-crypto hash used to hash keys, which determines + * while bucket the value will be placed in. + * A javascript implementation of Java's 32bitint hash. + * + * @public + * @method + * @param {Number|String} val Key to be hashed. + */ exports.Hashtable.prototype.hashCode = function (val) { var i; var hashCode = 0; @@ -91,6 +111,14 @@

Source: data-structures/hash-table.js

return hashCode; }; + /** + * Puts data into the table based on hashed key value. + * + * @public + * @method + * @param {Number|String} key Key for data. + * @param {Number|String} data Data to be stored in table. + */ exports.Hashtable.prototype.put = function (key, data, hashCode) { /* Make collision testing easy with optional hashCode parameter. @@ -132,6 +160,13 @@

Source: data-structures/hash-table.js

newNode.prev = first; }; + /** + * Get's data from the table based on key. + * + * @public + * @method + * @param {Number|String} key Key for data to be retrieved. + */ exports.Hashtable.prototype.get = function (key, hashCode) { /* Make collision testing easy with optional hashCode parameter. @@ -171,6 +206,13 @@

Source: data-structures/hash-table.js

} }; + /** + * Removes data from the table based on key. + * + * @public + * @method + * @param {Number|String} key Key of the data to be removed. + */ exports.Hashtable.prototype.remove = function (key, hashCode) { /* Make collision testing easy with optional hashCode parameter. @@ -249,13 +291,13 @@

Source: data-structures/hash-table.js


diff --git a/module-data-structures_hash-table.Hashtable.html b/module-data-structures_hash-table.Hashtable.html new file mode 100644 index 00000000..e42e153e --- /dev/null +++ b/module-data-structures_hash-table.Hashtable.html @@ -0,0 +1,732 @@ + + + + + JSDoc: Class: Hashtable + + + + + + + + + + +
+ +

Class: Hashtable

+ + + + + + +
+ +
+ +

+ data-structures/hash-table. + + Hashtable +

+ + +
+ +
+
+ + + + + +

new Hashtable()

+ + + + + +
+ Construct a Hash table.. +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

get(key)

+ + + + + +
+ Get's data from the table based on key. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
key + + +Number +| + +String + + + + Key for data to be retrieved.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +

hashCode(val)

+ + + + + +
+ Simple non-crypto hash used to hash keys, which determines while bucket the value will be placed in. A javascript implementation of Java's 32bitint hash. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
val + + +Number +| + +String + + + + Key to be hashed.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +

put(key, data)

+ + + + + +
+ Puts data into the table based on hashed key value. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
key + + +Number +| + +String + + + + Key for data.
data + + +Number +| + +String + + + + Data to be stored in table.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +

remove(key)

+ + + + + +
+ Removes data from the table based on key. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
key + + +Number +| + +String + + + + Key of the data to be removed.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/module-data-structures_hash-table.Node.html b/module-data-structures_hash-table.Node.html new file mode 100644 index 00000000..005d7f10 --- /dev/null +++ b/module-data-structures_hash-table.Node.html @@ -0,0 +1,244 @@ + + + + + JSDoc: Class: Node + + + + + + + + + + +
+ +

Class: Node

+ + + + + + +
+ +
+ +

+ data-structures/hash-table. + + Node +

+ + +
+ +
+
+ + + + + +

new Node(key, data)

+ + + + + +
+ Constructs a Node to store data and next/prev nodes in Hash table. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
key + + +Number +| + +String + + + + Key of the node.
data + + +Number +| + +String + + + + Data to be stored in hash table.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/module-data-structures_hash-table.html b/module-data-structures_hash-table.html index a00e2279..8705c5b4 100644 --- a/module-data-structures_hash-table.html +++ b/module-data-structures_hash-table.html @@ -38,10 +38,7 @@

Module: data-structures/hash-table

-
Hash Table - -An associative array, that can map keys -(strings and numbers) to values in O(1).
+
Hash Table An associative array, that can map keys (strings and numbers) to values in O(1).
@@ -117,21 +114,7 @@

Module: data-structures/hash-table

Example
-
var hash = require('path-to-algorithms/src/data-structures'+
-'/hash-table');
-var hashTable = new hash.Hashtable();
-
-hashTable.put(10, 'value');
-hashTable.put('key', 10);
-
-console.log(hashTable.get(10)); // 'value'
-console.log(hashTable.get('key')); // 10
-
-hashTable.remove(10);
-hashTable.remove('key');
-
-console.log(hashTable.get(10)); // undefined
-console.log(hashTable.get('key')); // undefined
+
var hash = require('path-to-algorithms/src/data-structures'+
'/hash-table');
var hashTable = new hash.Hashtable();

hashTable.put(10, 'value');
hashTable.put('key', 10);

console.log(hashTable.get(10)); // 'value'
console.log(hashTable.get('key')); // 10

hashTable.remove(10);
hashTable.remove('key');

console.log(hashTable.get(10)); // undefined
console.log(hashTable.get('key')); // undefined
@@ -144,6 +127,16 @@
Example
+

Classes

+ +
+
Hashtable
+
+ +
Node
+
+
+ @@ -166,13 +159,13 @@
Example