// Instantiate keyval. var kv = new keyval();// Add 1 million key value pairs. for (var i = 1; i <= 1000000; i++) { // 1st arg is the key, second is the value. kv.set(i.toString(), i); }
// Delete a key value pair. kv.del('100000');
// Iterate over the key value pairs. var tmp, foo; while (tmp = kv.itr()) { // Assign the value to foo. foo = tmp.v; }
// Rewind the iterator to the first key. kv.rwd();
// Get the number of key value pairs set. var length = kv.len;
// Empty the key value pair pool. kv.empty();
- Iterates key value associated data faster than using a JavaScript object (~10x on Chrome, ~5x on Firefox)
- Finds a specified key in 0ms
- Deletes a specified key in 0ms
- Provides key count in 0ms
- Sets key value associated data a bit slower than using a JavaScript object
Tested on Chrome, Firefox (pending for the rest of the browsers)