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

van-emde-boas

v1.0.1

Published

van Emde Boas trees

Downloads

7

Readme

van-emde-boas

TypeScript implementation of van Emde Boas trees.

A van Emde Boas tree efficiently stores integers in a predefined range from 0 to some upper bound k, and permits insert, delete, find, predecessor, and successor operations in O(log log k) time and O(n) space, where n is the number of stored elements. For a universe of 64-bit numbers, for example, log log 2^64 = 6, and a van Emde Boas tree thus becomes faster than, e.g., a binary search tree as soon as the number of stored values exceeds 64 (modulo differing constanty factors of the implementations). In general, van Emde Boas trees are worth considering in any situation where the range of values is constrained and the number of values to be stored is greater than the number of bits required to encode the largest number (again, modulo constant factors which may make simpler data structures faster in practice up to some multiple of that heuristic value), or whereever fast successor/predecessor queries are required. E.g., internet routers often use vEBs to store ranges of IP addresses.

This package exports a single class:

export declare class VEB {
    readonly bound: number;
    readonly size: number;
    constructor(bound: number);
    insert(x: number): boolean;
    delete(x: number): boolean;
    has(x: number): boolean;
    next(x: number): number;
    prev(x: number): number;
    keys(): Generator<number>;
    values(): Generator<number>;
    entries(): Generator<[number, number]>;
    [Symbol.iterator](): Generator<number>;
}

The [Symbol.iterator], keys, and values methods each return a generator that iterates over the values stored in the tree, and entries duplicates those values to produce pairs, similar to the built-in Set object. The size property reports the number of elements currently stored in the tree. Other methods behave as follows:

  • insert(x) returns true when x is successfully inserted, and false when x was already in the tree. Insertion does do bounds checking, and will throw an error for values that are not in the range [0, bound).
  • delete(x) returns true when x is successfully deleted, and false when x was not in the tree to begin with.
  • has(x) returns true when x is in the tree (previously inserted and not deleted), and false otherwise.
  • next(x) returns x if x is in the tree, -1 if x is larger than any element in the tree, and otherwise returns the next value larger than x which is in the tree.
  • prev(x) returns x if x is in the tree, -1 if x is smaller than any element in the tree, and otherwise returns the next value smaller than x which is in the tree.

Comparison to other Libraries

The only other NPM package currently implementing a van Emde Boas tree is vebt. Compared to vebt, this implementation is consistently 2 to 3 times faster based on a combined benchmark of constructing a tree, inserting elements, querying successors of all elements, and deleting all elements. With delete operations removed from consideration, this package benchmarks as approximately 2.5 to 3.5 times faster than vebt for combined construction, insertion, and successor query operations. Insertion operations alone are of comparable speed for small (<= 8-bit) universes, but this library becomes 2 to 3 times faster than vebt for larger universe sizes. Additionally, vebt consistently throw's type errors when attempting to remove an element, and begins to throw errors on insertion in larger universes when n > 2^15.