šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

disjoint-set-ds

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

disjoint-set-ds

Implementation of Disjoint sets data structure.

1.0.1
latest
Source
npm
Version published
Weekly downloads
3.6K
-28.56%
Maintainers
1
Weekly downloads
Ā 
Created
Source

npm version Build Status Coverage Status Dependencies Status CI workflow

Disjoint Set data structure

A disjoint-set data structure stores a collection of disjoint (non-overlapping) sets. It provides operations for adding new sets, merging sets (replacing them by their union), and finding a representative member of a set. Disjoint-set data structures play a key role in Kruskal's algorithm for finding the minimum spanning tree of a graph.

For more information read: https://en.wikipedia.org/wiki/Disjoint-set_data_structure

In contrast to other available implementations of the data structure, the data structure does not assume that the elements stored are 0, 1, 2, ... but the actual elements are provided to makeSet and are being stored. The elements can be of any type.

Usage

import { DisjointSet } from 'disjoint-set-ds';

var ds = new DisjointSet();

ds.makeSet('Alice');
ds.makeSet('Bob');

console.log(ds.find('Alice')); // Alice
console.log(ds.find('Bob')); // Bob

ds.union('Bob', 'Alice');

console.log(ds.find('Alice')); // Bob <---
console.log(ds.find('Bob')); // Bob

An auxiliary data structure DisjointSetArray is also provided for the simple case that the stored elements are the numbers 0, 1, 2, ...

import { DisjointSetArray } from "disjoint-set-ds";

var ds = new DisjointSetArray(3);

console.log(ds.find(0)); // 0
console.log(ds.find(1)); // 1
console.log(ds.find(2)); // 2

ds.union(0, 2);

console.log(ds.find(0)); // 0
console.log(ds.find(1)); // 1
console.log(ds.find(2)); // 0 <---

Keywords

Disjoint sets

FAQs

Package last updated on 15 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts