Skip to content

Javascript hashtables. Use *anything* as a key, not just strings.

License

Notifications You must be signed in to change notification settings

benekastah/js-hashtable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JS HashTable

An easy way to use anything you need/want as a key to a hash.

Install:

The npm module name used to be hashtable, but I renamed it because someone else requested to use it and I haven't updated this project in a couple years.

$ npm install js-hashtable

API

There are two classes for your hashtable pleasure:

QHash

QHash stands for "quick hash". It's primary advantage is that it is light and fast. QHash will not check to see if two keys are similar enough to be declared equal (for the most part). Therefore, if you pass in an object as a key, only that object will be able to retrieve the value. In this way, QHash offers more security than HashTable.

var bob, hash, apiKey;
bob = new Person('Bob');
apiKey = new SomeLongUniqueThing();

apiKeys = new QHash();
apiKeys.set(bob, apiKey); // -> apiKey

apiKeys.get(bob); // -> apiKey

apiKeys.set(bob, null); // -> null
apiKeys.remove(bob); // -> null
apiKeys.get(bob); // -> undefined

HashTable

Alias: Hash

This hash will convert all keys passed in to a string. Objects with the same properties in different orders will generate the same strings. Therefore, the object does not have to be exactly the same in order to retrieve the value, but instead must share all the same information. Inherited values will not be accounted for.

Like QHash, HashTable supports the get, set and remove functions, but we now have a little extra.

var routes, hkey = Hash.key;

routes = new Hash();
// Define a route in your routes hash
routes.set(/^\/user\/all(\.json)?$/, UsersController.displayAll);
// Two ways to do the same thing
routes[hkey( /^\/user\/(\d*)$/ )] = UsersController.displayById;

About

Javascript hashtables. Use *anything* as a key, not just strings.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published