npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hashtable-patch-valeriansaliou

v2.1.5

Published

Native HashTable and ES6 compatible Map for Node.js

Downloads

9

Readme

HashTable

Sometimes you need to store so much data in memory that V8 can get a bit clogged up. This Node.js module provides an interface to a native hashmap data structure that exists outside of V8's memory constraints.

To install, simply:

npm install hashtable-patch-valeriansaliou

"But Isaac, javascript already has hash tables! They're called objects, dummy"

V8 is great, but was never really meant for driving large software systems. Try adding a few million non-integer keys to an object and you'll start to see things bog down. This module is not intended to be a general replacement for javascript objects (that would be silly). Instead, it is meant to be used when you need maps larger than V8's virtual machine can handle.

Usage

Update: As of version 1.0.0, this module will no longer work on Node 0.10 or earlier. If this is a problem use 0.x.x.

Everything you might want to do first requires a new HashMap object (which corresponds to a native c++ unordered_map):

var HashTable = require('hashtable');
var hashtable = new HashTable();

hashtable.put('key', {value: 'value'});

console.log(hashtable.get('key'));

...

> { value: 'value' }

And that's it! Note that values can be any javascript type, including objects. The module properly creates and removes references (aka 'handles' if you know something about v8 internals) as needed, so you don't have to worry about any garbage collection funny business. Just use the module like you would any other javascript library.

The hash table implementation is provided by C++11's unordered_map class. Currently there is no fallback for older compilers. Pull requests welcome.

put ( key, value )

Insert a new key/value pair in the hashmap. The key can be any javascript type, except undefined and null, including objects. The value can be any javascript type, including objects.

get ( key )

Lookup a value from its key. Will return undefined if the key does not exist.

has ( key )

Check if key exists. Will return false if the key does not exist; otherwise true.

remove ( key )

Remove a key/value pair by its key. If the key does not exist, no action will be performed and it will return false. If a pair is removed, then it will return true.

clear ()

Removes all key/value pairs from the hash table.

size ()

Returns the number of key/value pairs in the hash table.

forEach ( cb, context )

cb is an iterator function that will be called with each key/value pair like cb.call(c, key, value), if context is not provided, the global.

keys ()

Will return an array of the keys stored in the hashtable.

rehash ( n )

Will increase the number of buckets to at least n, possibly causing a rehash of the hash table. See unordered_map#rehash

reserve ( n )

Gives a hint to the implementation which may cause a rehash to the most appropriate number of buckets to contain n key/value pairs. See unordered_map#reserve

max_load_factor () or max_load_factor ( factor )

Either returns or sets the max load factor of the hash table implementation. This value determines when the hash map is rehashed with a new bucket count. By default it is 1.0. See unordered_map#max_load_factor

You're right anonymous internet user! Just install HashTable like above, but then use like this:

var Map = require('hashtable/es6-map');

var map = new Map();
map.set('key', {value: 'value'});
map.set('something', 'else');

console.log('There are', map.size, 'item(s) in the map');

iterator = map.entries();
while (!iterator.done) {
    console.log(iterator.key, '=', iterator.value);
    iterator.next();
}

See the official ES6 Map documentation

This package is made possible because of Grokker, one of the best places to work. If you are a JS developer looking for a new gig, send me an email at ['chad', String.fromCharCode(64), 'grokker', String.fromCharCode(0x2e), 'com'].join('').