Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

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
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

1 decade ago by alexandre

Sweet! I'm going to use this a lot. Thanks for sharing.
Alex

1 decade ago by clok

Thanks! I just posted the plugin on PointOfImpact, so hopefully others will find it useful too.

EDIT: updated the link

1 decade ago by Graphikos

It's now active: http://pointofimpactjs.com/plugins/view/25/concise-perl-style-hash-plugin

Thanks for the contribution!
Page 1 of 1
« first « previous next › last »