ht
ht
is a HashTable implementation in javascript that can be used in both node and the browser.
Installation
npm install ht
Or download the source (minified)
Note ht
depends on declare.js
, extended
, is-extended
, and array-extended
Usage
To create a new HashTable
var Ht = ;var ht = ;
put(key, value)
Adds a new key value pair to the hash table, ht supports any value as a key.
var key = {} key2 = {};ht;ht; ht; //"value1";ht; //"value2";
If your key contains a hashCode
, function then that will be used to put the key value pair into the hash table.
{ thisfirstName = first; thislastName = last;} Personprototype{ return thisfirstName + thislastName;} ht;ht; ht; //"this is bob"
get(key)
Get a a value based on the key.
ht;ht; ht; //"value1";ht
set(key)
Set a a value based on the key.
ht;ht; ht; //"value1";ht
remove(key)
Removes a key value pair.
ht;ht; ht; //"value1";ht
contains(key)
Returns true or false if the table does or does not contain a given key value pair.
ht;ht; ht; //true;ht
concat(hashTable
Concats two hash tables together into a new one.
var ht1 = ht2 = ; ht1;ht1; var key = {} key2 = {};ht2;ht2; var ht3 = ht1; ht3; //trueht3; //trueht1; //trueht1; //true
clear
Clear all items from the hash table
ht;ht; htclear; ht; //falseht; //false
keys
Returns an array of all keys in the table.
ht;ht; ht; //["key1", "key2"]
values
Gets all values in the hash table.
ht;ht; ht; //["value1", "value2"]
entrySet
Returns an array of all key value pairs in the table.
ht;ht; ht; //[{key: "key1", value: "value1"}, {key: "key2", value: "value2"}]
isEmpty
Returns true if the table contains any values, false otherwise.
var ht = ; ht; //true ht;ht; ht; //false
Array methods.
Each hash table contains the following array like methods.
Note each method will pass a key and value to the iterator instead of a value and index.
ht;ht; ht;
forEach
filter
map
every
some
reduce
reduceRight