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

bigboi

v0.0.2

Published

Big Sets and Big Maps! Get around the 2 ^ 24 item limit in JS Sets and Maps.

Downloads

6

Readme

GitHub license npm version PRs Welcome

BigBoi

JavaScript Set and Map native utilities have a maximum key size of 2 ^ 24 (16,777,216). BigBoiSet and BigBoiMap preserve the interface methods of the native Set and Map, while silently putting the items into bucketed instances of their respective native counterparts. Keys are hashed before bucketing, and therefore do not need to be uniformly distributed in order to be bucketed appropriately.

Installation

npm install --save bigboi or yarn add bigboi

Usage

Except for constructor, same interface as Set and Map

Simple vs Hashed

There are 2 variants of the Set and Map available.

import {
  BigBoiSetSimple,
  BigBoiMapSimple,
  BigBoiSetHashed,
  BigBoiMapHashed,
}

Simple:

The Simple variants will simply push items into a Set/Map until there is no room, then move onto the next one, and so on. The lookup process is naive, and will simply go through the buckets of items to check if a given key is present. This means that any given lookup has a worst case of (total items) / (2 ^ 24). Bear in mind, lookups happen on reads/checks, but also on insertions, as we don't want to add the same item to multiple different buckets.

Simple Pros:

  • Preserves insertion order
  • Don't have to specify item count ahead of time
  • Despite being naive, is actually faster up until ~500 million items
  • Keys can be any keys used in native JS Map or Set

Simple Cons:

  • Reads/writes slow down exponentially, but again, this only starts to penalize after ~500 million items

Hashed:

The Hashed variants will hash the keys and get a deterministic and uniformly distributed bucket assignment for each item. This means that there is O(1) reads and writes, allowing this solution to scale to an arbitrarily high number of items limited only by the available memory in the runtime environment.

Hashed Pros:

  • O(1) reads and writes allowing performant scaling to arbitrary size.

Hashed Cons:

  • The hashing of keys is computationally intensive. Because of this, despite being a scalable solution, up until ~500 million items, this implementation is slower
  • Only string keys
  • No insertion order preserved
const bigSet = new BigBoiSetSimple();

// Add elements
for (let i = 0; i < 20_000_000; i++) {
  bigSet.add('Hello' + i);
}

// Check if an element exists
bigSet.has('Hello0'); // returns true

// Remove an element
bigSet.delete('Hello0');

// Iterate over elements
bigSet.forEach((value) => {
  console.log(value);
});

// Return iterators
bigSet.entries();
bigSet.keys();
bigSet.values();

// Clear
bigSet.clear();
const bigMap = new BigBoiMapSimple();

// Add elements
for (let i = 0; i < 20_000_000; i++) {
  bigMap.add('Hello' + i, i);
}

// Get a value at a given key
bigMap.get('Hello0'); // returns 0

// Check if an element exists
bigMap.has('Hello0'); // returns true

// Remove an element
bigMap.delete('Hello0');

// Iterate over elements
bigMap.forEach((value, key) => {
  console.log(key, value);
});

// Return iterators
bigMap.entries();
bigMap.keys();
bigMap.values();

// Clear
bigMap.clear();

Contributing

We welcome contributions! Please see our contributing guidelines for more information.

License

MIT