1.1.2 • Published 5 years ago

unionfind-typescript v1.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Union Find

This is a UnionFind module that use TypeScript

codecov Build Status

Document

Here

Installation

$ npm install --save unionfind-typescript

Getting started

//import UnionFind
const UnionFind = require( "unionfind-typescript").UnionFind;
//import enums
const enumUnionMode = require( "unionfind-typescript").unionMode;
const enumRepeatExistNode = require( "unionfind-typescript").repeatExistNode;

//Initialize
let nodes= ["a","b",123,{"name":"d"},"e"];
let unionFind = new UnionFind(
    //nodes
    nodes,
    //paths
    [["a","b"]],
    //configs
    {
        unionMode:enumUnionMode.normal,
        repeatExistNode:enumRepeatExistNode.ignore,
        customToString:function(node){
            return "<" + node + ">";
        }
    }
);

//union two node
unionFind.union("b","e");

//find root node
unionFind.findRoot("e") // =>"a"


unionFind.compress(); // All paths are compressed

//get UnionNode with "e"
let e = unionFind.getUnionNode("e");

console.log(e.node) // =>"e"
console.log(e.parent.node) // =>"a"

Configs

optionvaluedescription
unionModedefault : normalHow to union
normalUnion two subtrees
heightBalance the height of the tree
compressUnion two subtrees,the second tree should link to the first nodes'root
repeatExistNodedefault : ignoreHow to deal with when there are duplicate nodes detected
ignoreIgnore
warningConsole a waring message
errorThrow an error

APIs

Build documents

$ npm run doc

1.1.2

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago