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

adaptive-set

v0.1.3

Published

Utils for implementing a Set data structure that dynamically adjusts its internal representation based on the number of elements it contains.

Downloads

952

Readme

adaptive-set

Docs Build Status npm-version Coverage Status minified-size

A set of utils for implementing specialized Set data structure designed to optimize memory usage and performance based on the number of elements it contains. It adapts its internal representation to efficiently handle cases where there are no items, a single item, or multiple items.

  • No Items: When the set is empty, it uses an undefined value to represent the absence of elements, minimizing memory usage.
  • Single Item: When the set contains exactly one item, it uses a array [item] to store the single element, providing quick access and iteration.
  • Multiple Items: When the set contains more than one item, it switches to using a standard Set to leverage its efficient handling of multiple elements.

This adaptive approach ensures that the it remains efficient and performant across different usage scenarios, making it an ideal choice for applications where the number of elements can vary significantly.

Install

npm add adaptive-set

Example

import { add, has, remove, size, type AdaptiveSet } from "adaptive-set";

type Fn = () => void;

class MyClass {
  private listeners?: AdaptiveSet<Fn>;

  public notify(): void {
    if (this.listeners) {
      for (const listener of this.listeners) {
        listener();
      }
    }
  }

  public addListener(listener: Fn): void {
    this.listeners = add(this.listeners, listener);
  }

  public removeListener(listener: Fn): void {
    this.listeners = remove(this.listeners, listener);
  }

  public hasListener(listener: Fn): boolean {
    return has(this.listeners, listener);
  }

  public getListenerCount(): number {
    return size(this.listeners);
  }

  public clearListeners(): void {
    this.listeners = undefined;
  }
}