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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zakkster/lite-spatial

v1.0.1

Published

Zero-GC spatial hash grid with linked-list chaining, epoch deduplication, box + radius queries, and O(1) insert/remove. SoA-aligned for particle engines.

Readme

@zakkster/lite-spatial

npm version npm bundle size npm downloads npm total downloads TypeScript Zero Dependencies License: MIT

Zero-GC spatial hash grid with linked-list chaining, epoch deduplication, box + radius queries, and O(1) insert/remove. Zero dependencies.

Why lite-spatial?

| Feature | lite-spatial | rbush | spatial-hash | p2.js | |---|---|---|---|---| | Zero-GC | Yes (TypedArrays) | No (objects) | No | No | | Insert | O(1) prepend | O(log n) | O(1) | O(1) | | Remove | O(k) cell | O(log n) | O(k) | O(k) | | Deduplication | Epoch marker | N/A | Manual | N/A | | Query output | Pre-allocated buffer | New array | New array | New array | | SoA aligned | Yes (id-indexed) | No | No | No | | Dependencies | 0 | 0 | 0 | 0 |

Installation

npm install @zakkster/lite-spatial

Quick Start

import { SpatialGrid } from '@zakkster/lite-spatial';

const grid = new SpatialGrid(800, 600, 64, 10000);
const queryBuf = new Int32Array(256);

// Per frame:
grid.clear();
for (let i = 0; i < entityCount; i++) grid.insert(i, x[i], y[i]);

// Query neighbors
const count = grid.queryBox(player.x - 100, player.y - 100, player.x + 100, player.y + 100, queryBuf);
for (let i = 0; i < count; i++) {
    const id = queryBuf[i];
    // narrow-phase collision check with entity id
}

How It Works

Linked-List Chaining

Each grid cell stores the head ID of a linked list. insert() prepends in O(1):

head[cell] → id3 → id1 → id0 → -1

No arrays-of-arrays, no push/pop, no GC. Just Int32Array pointer chasing.

Epoch Deduplication

When entities span multiple cells, queryBox can return duplicates. The dedupe flag uses a Uint8Array marker with epoch incrementing — the seen buffer is only flushed every 255 queries, not every call.

const count = grid.queryBox(0, 0, 800, 600, buf, true); // dedupe=true

Pre-Allocated Output Buffer

Query results write into a caller-owned Int32Array. No array allocation per query. Buffer overflow is handled by early-exit — the grid stops writing when the buffer is full and returns the count.


Full API

new SpatialGrid(width, height, cellSize, capacity)

| Param | Description | |---|---| | width/height | World dimensions (px) | | cellSize | Bucket size. Tune to ~2× your largest entity. | | capacity | Max entity count. Aligns with SoA pool size. |

Methods

| Method | Complexity | Description | |---|---|---| | .clear() | O(cells) | Reset all heads to -1. Call once per frame. | | .insert(id, x, y) | O(1) | Linked-list prepend. Out-of-bounds ignored. | | .remove(id, x, y) | O(k) | Unlink from cell. k = items in that cell. | | .queryBox(minX, minY, maxX, maxY, out, dedupe?) | O(cells × k) | Fill out buffer with IDs. Returns count. | | .queryRadius(x, y, r, out, dedupe?) | O(cells × k) | Box approximation of circle query. | | .destroy() | O(1) | Null all typed arrays. |


Recipes

import { SpatialGrid } from '@zakkster/lite-spatial';
import { testPolygonPolygon, translatePoly } from '@zakkster/lite-sat';

const grid = new SpatialGrid(800, 600, 64, 1000);
const buf = new Int32Array(64);
const mtv = new Float32Array(2);

// Per frame:
grid.clear();
for (let i = 0; i < count; i++) grid.insert(i, x[i], y[i]);

for (let i = 0; i < count; i++) {
    const n = grid.queryRadius(x[i], y[i], 32, buf);
    for (let j = 0; j < n; j++) {
        const other = buf[j];
        if (other <= i) continue;
        if (testPolygonPolygon(polys[i], polys[other], mtv)) {
            translatePoly(polys[i], mtv[0] * 0.5, mtv[1] * 0.5);
            translatePoly(polys[other], -mtv[0] * 0.5, -mtv[1] * 0.5);
        }
    }
}
grid.clear();
for (const a of agents) grid.insert(a.id, a.x, a.y);

for (const a of agents) {
    const n = grid.queryRadius(a.x, a.y, 60, buf, true);
    // separation, alignment, cohesion with buf[0..n-1]
}

License

MIT — Part of the @zakkster ecosystem.