HashTables are associative arrays that can be indexed with almost any type or primitive in the language and some from the environment. Object, Function, Array, RegExp, String, and Number work, as do DOM Elements. Other DOM types haven't been tested yet, nor have JSON objects, but should work. Null, NaN, undefined, Infinity, true, and false are not valid keys.
Released under the terms of the GPL3.0 http://www.opensource.org/licenses/gpl-3.0.html
- len, the number of keys that exist
- set, create or update a key
- get, retrieve a value by key
- store, stores one or more key:value pairs, if a single parameter is passed it becomes a key with a value of undefined
- unset, sets a value to
undefinedbut leaves the key
- del, returns specified key and associated value in an array and deletes them from the object
- keys, returns a new array of all keys
- each, iterate over the object and call a user supplied callback on each value
- flip, swaps keys and values, can optionally flip one key with its value
in particular, there is a completely untested type-based caching mechanism added entirely on a whim that will maintain an index of the indices of keys of a given type, in theory allowing much faster retrevials from large collections. It is currently configured to kick in once the object contains 500 pairs, if it works at all. I wrote those bits without any testing and there are probably some stupid mistakes I need to fix.
performance tests in the major browsers
add filter, some, and reduce methods
consider adding methods to manipulate the keys separately, although this breaks with user expectations for an associative structure