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

ht

v0.0.2

Published

Hash Table Implementation for javascript

Downloads

19,739

Readme

Build Status

browser support

ht

ht is a HashTable implementation in javascript that can be used in both node and the browser.

Installation

npm install ht

Or download the source (minified)

Note ht depends on declare.js, extended, is-extended, and array-extended

Usage

To create a new HashTable

var Ht = require("ht");
var ht = new Ht();

put(key, value)

Adds a new key value pair to the hash table, ht supports any value as a key.

var key = {}, key2 = {};
ht.put(key, "value1");
ht.put(key2, "value2");

ht.get(key); //"value1";
ht.get(key2); //"value2";

If your key contains a hashCode, function then that will be used to put the key value pair into the hash table.

function Person(first, last){
    this.firstName = first;
    this.lastName = last;
}

Person.prototype.hashCode = function(){
    return this.firstName + this.lastName;
}

ht.put(new Person("bob", "yukon"), "this is bob");
ht.put(new Person("sally", "yukon"), "this is sally");

ht.get(new Person("bob", "yukon")); //"this is bob"

get(key)

Get a a value based on the key.

ht.put(new Date(2013, 1, 22), "value1");
ht.put(new Date(2013, 1, 23), "value2");

ht.get(new Date(2013, 1, 22)); //"value1";
ht.get(new Date(2013, 1, 23); //"value2";

set(key)

Set a a value based on the key.

ht.put(new Date(2013, 1, 22), "value1");
ht.put(new Date(2013, 1, 23), "value2");

ht.get(new Date(2013, 1, 22)); //"value1";
ht.get(new Date(2013, 1, 23); //"value2";

ht.set(new Date(2013, 1, 22), "new value1");
ht.set(new Date(2013, 1, 23), "new value2");

ht.get(new Date(2013, 1, 22)); //"new value1";
ht.get(new Date(2013, 1, 23); //"new value2";

remove(key)

Removes a key value pair.

ht.put(new Date(2013, 1, 22), "value1");
ht.put(new Date(2013, 1, 23), "value2");

ht.get(new Date(2013, 1, 22)); //"value1";
ht.get(new Date(2013, 1, 23); //"value2";

ht.remove(new Date(2013, 1, 22)); //"value1";
ht.remove(new Date(2013, 1, 23); //"value2";

ht.get(new Date(2013, 1, 22)); //null;
ht.get(new Date(2013, 1, 23); //null";

contains(key)

Returns true or false if the table does or does not contain a given key value pair.


ht.put(new Date(2013, 1, 22), "value1");
ht.put(new Date(2013, 1, 23), "value2");

ht.contains(new Date(2013, 1, 22)); //true;
ht.contains(new Date(2013, 1, 23); //true;

concat(hashTable

Concats two hash tables together into a new one.


var ht1 = new Ht(), ht2 = new Ht();

ht1.put(new Date(2013, 1, 22), "value1");
ht1.put(new Date(2013, 1, 23), "value2");

var key = {}, key2 = {};
ht2.put(key, "value1");
ht2.put(key2, "value2");

var ht3 = ht1.concat(ht2);

ht3.contains(key); //true
ht3.contains(key2); //true
ht1.contains(new Date(2013, 1, 22)); //true
ht1.contains(new Date(2013, 1, 23)); //true

clear

Clear all items from the hash table

ht.put("key1", "value1");
ht.put("key2", "value2");

ht.clear();

ht.contains("key1"); //false
ht.contains("key2"); //false

keys

Returns an array of all keys in the table.

ht.put("key1", "value1");
ht.put("key2", "value2");

ht.keys(); //["key1", "key2"]

values

Gets all values in the hash table.

ht.put("key1", "value1");
ht.put("key2", "value2");

ht.values(); //["value1", "value2"]

entrySet

Returns an array of all key value pairs in the table.

ht.put("key1", "value1");
ht.put("key2", "value2");

ht.entrySet(); //[{key: "key1", value: "value1"}, {key: "key2", value: "value2"}]

isEmpty

Returns true if the table contains any values, false otherwise.


var ht = new Ht();

ht.isEmpty(); //true

ht.put("key1", "value1");
ht.put("key2", "value2");

ht.isEmpty(); //false

Array methods.

Each hash table contains the following array like methods.

Note each method will pass a key and value to the iterator instead of a value and index.


ht.put("key1", "value1");
ht.put("key2", "value2");

ht.forEach(function(key, value){
    console.log(key + " : " + value);
});

  • forEach
  • filter
  • map
  • every
  • some
  • reduce
  • reduceRight