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 🙏

© 2025 – Pkg Stats / Ryan Hefner

indexed-hash-map

v1.0.7

Published

A Hash Map supporting O(1) key lookup, numeric indexing, insertion, and deletion.

Downloads

555

Readme

IdxHashMap

A JavaScript data structure providing O(1) insertion, deletion, numeric indexing, and key-based lookup at the cost of space. utilizes the pop and swap method for deletion, be careful if strict indexed order matters

Installation

npm install indexed-hash-map

Usage:

const IdxHashMap = require('indexed-hash-map');

const map = new IdxHashMap();

map.set("name", "Ari");
map.set("color", "purple");

console.log(map.get("name"));        // Ari
console.log(map.idx(1));              // purple

// .find is increased to O(1) if given a direct key or index
console.log(map.find("color"));  // purple O(1)

// if .find is still given a callback, then it remains as it's original O(n)
const foundValue = map.find((value) => value === "purple");
console.log(foundValue);  // purple O(n)

// if not present, returns undefined like the normal array method.
console.log(map.find("age")); // undefined 

// includes is increased to O(1) from O(n).
console.log(map.includes("color"));   // true

// indexOfKey is increased to O(1) from O(n)
console.log(map.indexOfKey("color")); // 1

// forEach, map and filter remain their original time complexity of O(n)
map.forEach((val, idx) => console.log(idx, val)); // 0 Ari, 1 purple

const upperCaseValues = map.map(val => val.toUpperCase());
console.log(upperCaseValues); // ["ARI", "PURPLE"]

const filteredMap = map.filter((val) => val !== "Ari");
filteredMap.forEach((val, idx) => console.log(idx, val)); // 0 purple

//since the key is an object, it allows for any combination of the three properties (key, value, idx) to be given in an object as an argument and returned. 
for (const {value, key, idx} of map) {
  console.log(idx, key, value);          //(0, name, Ari), (1, color, purple)
}

map.del("name");

console.log(map.len());               // 1
console.log(map.length)               // 1

Other Usage:

IdxHashMap also allows for 2 arguments to be passed, the key mapped to a node, as well as the index mapped to a node.

If data storage and loading is a factor, you can restore for serialzation by passing the map keys and map indicies.

for more performance optimzation, you can use the first argument to map custom keys from an object, while the second argument would be the pre-allocated array.

There are probably even more uses for this that I am not aware of yet, but will maybe update the readme with more info.

Message me for any questions!