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

disjoint-set

v1.1.9

Published

Data structure that helps to solve network connectivity problem using two operations: 1) connect two objects; 2) check or two objects are connected.

Downloads

119

Readme

Disjoint-set

Disjoint-set is a data structure that keeps track of a set of elements partitioned into a number of disjoint (non overlapping) subsets. A union–find algorithm is an algorithm that performs two useful operations on such a data structure:

  • Find: Determine which subset a particular element is in. This can be used for determining if two elements are in the same subset;
  • Union: Join two subsets into a single subset.

Use to solve network connectivity problem.

API

Creation

Methods

Usage example

var set = disjointSet(); // instantiate disjoint-set data structure

var person1 = {
    name: 'Volodymyr',
    surname: 'Velykyj'
}
var person2 = {
    name: 'Yaroslav',
    surname: 'Mydryi'
}
var person3 = {
    name: 'Bohdan',
    surname: 'Khmelnytskyi'
}
var person4 = {
    name: 'Ivan',
    surname: 'Mazepa'
}
var person5 = {
    name: 'Jim',
    surname: 'Morrison'
}
var person6 = {
    name: 'Ray',
    surname: 'Manzarek'
}

// add objects to the set
set.add(person1)
    .add(person2)
    .add(person3)
    .add(person4)
    .add(person5)
    .add(person6);

// connect some objects to each other
set.union(person1, person2);
set.union(person2, person3);
set.union(person3, person4);
set.union(person5, person6);

// check connections
console.log(set.connected(person1, person2)); // returns true. Direct connection
console.log(set.connected(person1, person4)); // returns true. Indirect connection
console.log(set.connected(person5, person6)); // returns true. Another direct connection
console.log(set.connected(person4, person5)); // returns false. No connection

/**
 * returns two arrays grouped by connection:
 * [
 *     [person1, person2, person3, person4],
 *     [person5, person6]
 * ]
 */
console.log(set.extract());

Development

npm install # install dependencies
npm test    # check the code with JSHint and run tests

Papers

  • Robert Sedgewick and Kevin Wayne, Algorithms, 4th edition, page 216

Changelog

1.1.9 — 22.02.2024

  • minor fixes (readme, package.json)

1.1.8 — 04.02.2015

  • minor fixes (readme, package.json)

1.1.7 — 04.02.2015

  • minor fixes (readme, package.json)

1.1.6 — 21.10.2014

  • minor fixes (readme, package.json)

1.1.5 — 01.05.2014

  • critical bug (wrong subtree connections) fixed

1.1.4 — 25.04.2014

  • performance optimization: stringify key generator changed to Numerical ids

1.1.3 — 10.04.2014

  • quick-union algorithm changed to weighted quick-union

1.1.2 — 08.04.2014

  • quick-find algorithm changed to quick-union

1.1.1 — 08.04.2014

  • unit tests done

1.1.0 — 07.04.2014

  • connected() method added
  • find() method changed

1.0.0 — 06.04.2014

  • First Disjoint-set release