Home Manual Reference Source

Overview

Installation

Can be managed using yarn, npm, or jspm.

yarn

yarn add @union-find/non-contiguous

npm

npm install @union-find/non-contiguous --save

jspm

jspm install npm:@union-find/non-contiguous

Usage

Import the library where needed

const implementations = await import( '@union-find/non-contiguous' ) ;
// or
import * as implementations from '@union-find/non-contiguous' ;

Examples

// can choose between 8 different implementations
//   - ForestAmortizedHalving
//   - ForestAmortizedRecursive
//   - ForestAmortizedSplitting
//   - ForestAmortizedTwoPasses
//   - Forest
//   - LinkedList
//   - LinkedListWithHeadAndLength
//   - LinkedListWithHead

import { ForestAmortizedHalving } from '@union-find/non-contiguous' ;

let { makeset , union , find } = ForestAmortizedHalving ;

let a , b , c , A , B , C ;

A = a = makeset( ) ;
B = b = makeset( ) ;
C = c = makeset( ) ;

find( a ) === find( a ) ; // true
find( a ) === find( b ) ; // false
find( a ) === find( c ) ; // false

find( b ) === find( a ) ; // false
find( b ) === find( b ) ; // true
find( b ) === find( c ) ; // false

find( c ) === find( a ) ; // false
find( c ) === find( b ) ; // false
find( c ) === find( c ) ; // true

A = union( A , B ) ; // union( B , A ) would work too

find( a ) === find( a ) ; // true
find( a ) === find( b ) ; // true
find( a ) === find( c ) ; // false

find( b ) === find( a ) ; // true
find( b ) === find( b ) ; // true
find( b ) === find( c ) ; // false

find( c ) === find( a ) ; // false
find( c ) === find( b ) ; // false
find( c ) === find( c ) ; // true