1 decade ago by clok
I found myself wanting associative hash tables similar to those in Perl to manage my common entity data and I did not want to include all of jQuery with my distro, although that could change as I get more comfortable with jQuery.
That said, I put together a plugin for ImpactJS that gives me these functions is a concise object compatible with ImpactJS. Here is the source code for GitHub impact-pHash.
This Implementation was inspired by Mojavelinux, Inc.
Simply include the plugin as 'plugin.phash' and create a new pHash
and an object will be created with the following functions:
The key-value pair will be stored as
There is also a
that tracks the size of the pHash.
Also, a standard JavaScript object can be included in the new call to populate the pHash on initialization.
or just
This is currrently used in PiSpace to manage the entity vertices.
The PiSpace Source code is on GitHub
That said, I put together a plugin for ImpactJS that gives me these functions is a concise object compatible with ImpactJS. Here is the source code for GitHub impact-pHash.
This Implementation was inspired by Mojavelinux, Inc.
Simply include the plugin as 'plugin.phash' and create a new pHash
var buckets = new pHash;
and an object will be created with the following functions:
this.set(key, value) this.get(key) this.has(key) this.pop(key) this.keys() this.values() this.each(fxn) this.clear()
The key-value pair will be stored as
value = this.items[key]
There is also a
this.len
that tracks the size of the pHash.
Also, a standard JavaScript object can be included in the new call to populate the pHash on initialization.
var jsObj = { key1: val1, key2: val2, key3: val3 }; var buckets = new pHash(jsObj);
or just
var buckets = new pHash( { key1: val1, key2: val2, key3: val3 } );
This is currrently used in PiSpace to manage the entity vertices.
The PiSpace Source code is on GitHub