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

@windfish-studio/rbush-ext

v2.1.2

Published

Fork of @mourner's rBush package, allows for meaningful use of the internal tree groupings/nodes.

Downloads

1

Readme

RBush-Ext

RBush-Ext is a fork of @mourner's brilliant rBush package, allows for meaningful use of the internal tree groupings/nodes.

Please refer to @mourner's rBush github page for the original documentation. Here I will only document the new functionality in rbush-ext.

Here's a [jsfiddle demo]: https://jsfiddle.net/sikanrong/4tjs1z8v/

RBush-Ext Features

getNode

RBush-Ext assigns an eight-digit alphanumeric ID to each node in the tree. This allows users to more easily make use of the internal tree structure for grouping. Nodes in the tree are indexed by UUID and can be retreived using getNode.

    var uuid = 'ksJ2Q1O5';
    // will return node that corresponds to this UUID, if one exists.
    var node = tree.getNode(uuid);

walk

This function walks through all nodes in the tree.

    tree.walk(function(node){
        //do stuff with each node.
        console.log(node.id);
    });

all(node)

RBush-Ext adds an optional node parameter to #all, which allows to return all leaf nodes in the subtree.

    var uuid = 'ksJ2Q1O5';
    var node = tree.getNode(uuid);
    tree.all(node); //returns all leaf-nodes of this 'branch' (subtree) in an array.

search

RBush-Ext modifies the return data from #search. Instead of just returning an array of leaf-nodes that correspond with the searched area, it now also returns all parentNodes that coincide with the search, organized by height in the tree.

This facilitates working with groupings by the parent rtree nodes (and their UUIDs) for a given height H.

    var results = tree.search({minX: 0, minY: 0, maxX: 100, maxY: 100});
    
    //now the normal results array from classic RBush
    console.log(results.leafNodes);
    
    //parent nodes by height; array index is (parent_node.height - 1)
    console.log(results.parentNodes); 
    
    //Example output
    /*
        [
            0: [
                <Node>,
                <Node>,
                <Node>
            ],

            1: [
                <Node>,
                <Node>
            ],

            2: [
                <Node>
            ]
        ]
    */

setDeterminism

Rbush-Ext adds an option to generate deterministic IDs. This means that each node in the tree will have an ID generated based on the IDs of its children. All changes to the underlying data will also cause deterministic ID changes that bubble up the tree.

var tree = rbush()
    .setDeterminism(true)
    .load(data);

setDeterminismSeedFunc

For the user-entered leaf-node data in the tree, there may not be a straightforward way to get a unique identifier for each node. By default rbush-ext uses the required bounding box of each child node, however a different function can be provided to calculate seed functions for the leaf nodes of the tree. Example:

var tree = rbush()
    .setDeterminism(true)
    .setDeterminismSeedFunc(function(_n) {
        //if the leaf nodes have a UUID key, use it to generate the IDs of the tree's nodes
        return _n.id || _n.uuid
    })
    .load(data);

Performance

Both benchmarks performed with Node.js v6.2.2 on a Macbook Pro (mid-2012 A1278), with Samsung EVO SSD disk.

(Note: these numbers hugely improved in version 2.0.5)

Test | RBush (classic) | RBush-Ext ---------------------------- | ------ | ------ insert 1M items one by one | 3.71s | 7.47s 1000 searches of 0.01% area | 0.03s | 0.06s 1000 searches of 1% area | 0.34s | 0.73s 1000 searches of 10% area | 2.30s | 4.14s remove 1000 items one by one | 0.02s | 0.22s bulk-insert 1M items | 1.58s | 3.23s

Tests

RBush-Ext updates the tape-based test suite to work with the new #search return format. Also adds new tests for the new RBush-Ext functionality.

# #search should return parent nodes of all leaf nodes, sorted by height
ok 25 should be equivalent
ok 26 should be equivalent
ok 27 should be equivalent

# #all returns all points in subtree if passed a node
ok 28 should be equivalent

# #getNode returns the correct node when passed the corresponding UUID
ok 31 should be equivalent

# #walk should iterate over all nodes
ok 32 should be equivalent

1..47
# tests 47
# pass  47

# ok