Skip to content

pconstr/rawhash

Repository files navigation

rawhash

Build Status

An experimental binary friendly alternative to using a hash as a key:value cache, for node.js.

Keys are binary Buffer objects rather than strings. Values are arbitrary objects.

rawhash is built on google-sparsehash (not included) and murmurhash3 (included).

Install

get google-sparsehash:

  • on Debian/Ubuntu: apt-get install libsparsehash-dev
  • on OS X: brew install google-sparsehash or port install google-sparsehash

or get the latest version from the google-sparsehash project

then install rawhash itself:

npm install rawhash

Usage

var rh = require('rawhash');
var k = new Buffer(6);
var h = new rh.Sparse();
h.set(k, {a:1, b:2});
console.log(h.get(k));
h.each(function(k, v) {
  console.log(k, v);
});
h.del(k);

There are 3 kinds of hashes:

  • Sparse is slower, but uses less memory, uses sparse_hash_map<>
  • Dense is faster, but uses more memory, uses dense_hash_map<>
  • Map is usually somewhere between Sparse and Dense, uses the STL's map<> which is actually ordered and supports range queries - not exposed in Map

Sparse and Dense take an optional argument to seed murmurhash3.

var h = new rh.Dense(42);

Performance

This is largely TBD

On a synthetic test (see ./perf/) with 150K sets, gets and deletes (very similar to ./test.js) on a low-end MBP, this is how rawhash compares with using a Javascript hash:

Sparse 509 ms
Dense  330 ms
Map    463 ms
{}     754 ms

License

(The MIT License)

Copyright (c) 2011 Carlos Guerreiro, perceptiveconstructs.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

experimental in-memory key:value cache where keys are binary Buffers

Resources

License

Stars

Watchers

Forks

Packages

No packages published