Class comb.collections.HashTable
Extends
comb.collections.Collection.
Implementation of a HashTable for javascript. This HashTable implementation allows one to use anything as a key.
NOTE: THIS IS ~ 3 times slower than javascript native objectsA use case for this collection is when one needs to store items in which the key will not be a string, or number
Defined in: HashTable.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Field Attributes | Field Name and Description |
---|---|
an array of objects.
|
|
all keys contained in the table
|
|
all values contained in the table
|
Method Attributes | Method Name and Description |
---|---|
clear()
Clears out all items from the table.
|
|
concat(hashTable)
Returns a new HashTable containing the values of this HashTable, and the other table.
|
|
contains(key)
Tests if the table contains a particular key
|
|
every(cb, scope)
Determines if every item meets the condition returned by the callback.
|
|
filter(cb, scope)
Creates a new HashTable containg values that passed the filtering function.
|
|
forEach(cb, scope)
Loop through each value in the hashtable
|
|
map(cb, scope)
Loop through each value in the hashtable, collecting the value returned by the callback function.
|
|
put(key, value)
Put a key, value pair into the table
NOTE : the collection will not check if the key previously existed.
|
|
reduce(callback, initialValue)
Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
|
|
reduceRight(callback, initialValue)
Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value.
|
|
remove(key)
Remove a key value pair from the table.
|
|
some(cb, scope)
Determines if some items meet the condition returned by the callback.
|
- Methods borrowed from class comb.collections.Collection:
- indexOf, join, lastIndexOf, slice, toString
Field Detail
{Array}
entrySet
an array of objects. Each object contains a key, and value property.
{Array}
keys
all keys contained in the table
{Array}
values
all values contained in the table
Method Detail
clear()
Clears out all items from the table.
{comb.collections.HashTable}
concat(hashTable)
Returns a new HashTable containing the values of this HashTable, and the other table.
DOES NOT CHANGE THE ORIGINAL!
- Parameters:
- {comb.collections.HashTable} hashTable
- the hash table to concat with this.
- Returns:
- {comb.collections.HashTable} a new HashTable containing all values from both tables.
{Boolean}
contains(key)
Tests if the table contains a particular key
- Parameters:
- key
- the key to test
- Returns:
- {Boolean} true if it exitsts false otherwise.
{Boolean}
every(cb, scope)
Determines if every item meets the condition returned by the callback.
- Parameters:
- {Function} cb
- Function to callback with each item, the first aruguments is an object containing a key and value field
- {Object} scope Optional, Default: this
- scope to call the function in
- Returns:
- {Boolean} True if every item passed false otherwise
{comb.collections.HashTable}
filter(cb, scope)
Creates a new HashTable containg values that passed the filtering function.
- Parameters:
- {Function} cb
- Function to callback with each item, the first aruguments is an object containing a key and value field
- {Object} scope
- the scope to call the function.
- Returns:
- {comb.collections.HashTable} the HashTable containing the values that passed the filter.
forEach(cb, scope)
Loop through each value in the hashtable
- Parameters:
- {Function} cb
- the function to call with an object containing a key and value field
- {Object} scope
- the scope to call the funciton in
{Array}
map(cb, scope)
Loop through each value in the hashtable, collecting the value returned by the callback function.
- Parameters:
- {Function} cb
- Function to callback with each item, the first aruguments is an object containing a key and value field
- {Object} scope Optional, Default: this
- scope to call the function in
- Returns:
- {Array} an array containing the mapped values.
put(key, value)
Put a key, value pair into the table
NOTE : the collection will not check if the key previously existed.
- Parameters:
- {Anything} key
- the key to look up the object.
- {Anything} value
- the value that corresponds to the key.
- Returns:
- the value
reduce(callback, initialValue)
Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
- Parameters:
- {Function} callback
- Function to execute on each value in the array.
- initialValue
- Value to use as the first argument to the first call of the callback..
reduceRight(callback, initialValue)
Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value.
- Parameters:
- {Function} callback
- Function to execute on each value in the array.
- initialValue
- Value to use as the first argument to the first call of the callback..
remove(key)
Remove a key value pair from the table.
- Parameters:
- key
- the key of the key value pair to remove.
- Returns:
- the removed value.
{Boolean}
some(cb, scope)
Determines if some items meet the condition returned by the callback.
- Parameters:
- {Function} cb
- Function to callback with each item, the first aruguments is an object containing a key and value field
- {Object} scope Optional, Default: this
- scope to call the function in
- Returns:
- {Boolean} True if some items passed false otherwise