Judy Arrays are fast, memory efficient, ordered associative arrays.
var Judy = require('judy-ffi');
var j = new Judy();
j.put('cow', 'moo');
console.log('A cow goes', j.get('cow')); // A cow goes moo
j.put('bird', 'coo');
j.size(); // 2
j.find(); // [ {'bird': 'coo'}, {'cow': 'moo'} ]
j.find('b'); // [ {'bird': 'coo'} ]
j.find('c'); // [ {'cow': 'moo'} ]
j.find('b', 'c'); // [ {'bird': 'coo'} ]
j.forEach(function(k,v) {
console.log('A %s goes %s', k, v);
});
// A bird goes coo
// A cow goes moo
j.delete_all('c'); // [ 'cow' ]
j.find(); // [ {'bird': 'coo'} ]
j.delete_all(); // [ 'bird' ]
j.find(); // []
- libjudy
- Debian-based:
apt-get install libjudy
- OSX:
brew install judy
- Debian-based:
new Judy()
returns a new Judy Array instance.
size()
to get number of entries.
put()
to store new entries or overwrite existing entries in Judy array.
get()
to retrieve entries from Judy array.
delete()
to delete an entry from Judy array.
delete_all()
to delete all keys starting with prefix
and less than maxKey
find()
to search for all entries with keys starting with prefix
and less than maxKey
forEach()
to iterate through entries with keys starting with prefix
and less than maxKey
. The callback is invoked with the key and value of each matched entry.