New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@manubb/union-find

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@manubb/union-find

a disjoint-set data structure

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

Union-Find

A JS implementation of disjoint-set data structure for node and browsers.

Installation

The library is available as a npm package:

npm install @manubb/union-find

Examples

Examples directory contains implementations of:

Examples can be run with:

npm run example:components
npm run example:hk
npm run example:kruskal

API

The library uses trees to encode sets. It exposes three functions.

makeSet

makeSet();

returns an object representing a set containing one element. It has two properties: parent and rank. You can then safely add other properties that suit to your needs.

Note that you can also use your own custom function that should return an object obj with:

obj.rank === 0
obj.parent === obj

At any time, you can check if obj is the root of a tree with:

obj.parent === obj

find

find(obj)

returns the root of the tree that contains obj. Checking if two objects belong to the same set can be done with:

find(obj1) === find(obj2)

union

union(obj1, obj2)

merges the sets containing obj1 and obj2 and returns undefined.

Complexity

makeSet run in constant time. If n is the total number of elements, find and union run in amortized time O(α(n)) where α is the inverse Ackermann function. It is a very slowly increasing function: α(10^35164)=5. For all practical purposes, one can consider that find and union run in constant amortized time.

Usage

import { makeSet, find, union } from '@manubb/union-find';

or

const { makeSet, find, union } = require('@manubb/union-find');

Keywords

FAQs

Package last updated on 02 Feb 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc