Skip to content

xmhscratch/i-like-bonsai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Manipulating hierarchical BST tree

Installation

npm install i-like-bonsai

Usage

Instantiate

import bonsai from 'i-like-bonsai'
const tree = await bonsai(rootNodeId)
// or
bonsai(rootNodeId).then((tree) => { /**/ })

Generate node ID

const nodeId = bonsai.getNewID()

Node object structural

{
  id varchar(24) NOT NULL,
  root varchar(24) NOT NULL,
  parent varchar(24),
  left int(11) NOT NULL,
  right int(11) NOT NULL,
  level int(11) NOT NULL
}

API References

create

const { nodeId } = tree.create(parentId)

Back to TOC

import

tree.import(nodeCollection)

Back to TOC

moveTo

tree.moveTo(nodeId, parentId, adjacentId)

Back to TOC

delete

const errMsg = tree.delete(nodeId)

Back to TOC

getNode

const node = tree.getNode(nodeId)

Back to TOC

getRootNode

const node = tree.getRootNode()

Back to TOC

getPrevNode

const node = tree.getPrevNode(nodeId)

Back to TOC

getNodeByParentIndex

const { nodeId } = tree.getNodeByParentIndex(parentId, parentIndex)

Back to TOC

getPaths

const nodeCollection = tree.getPaths(nodeId)

Back to TOC

getLevel

const level = tree.getLevel(nodeId)

Back to TOC

getDepth

const depth = tree.getDepth(nodeId)

Back to TOC

getIndexNumber

const nodeIndex = tree.getIndexOf(nodeId)

nodeIndex -1 on none exist Back to TOC

getChildren

const nodeCollection = tree.getChildren(nodeId)

Back to TOC

getDescendants

const nodeCollection = tree.getDescendants(nodeId)

Back to TOC

countChilds

const count = tree.countChilds(nodeId)

Back to TOC

toAdjacencyList

const nestedNode = tree.toAdjacencyList(nodeId)
const childNodeCollection = nestedNode.children

Back to TOC

toLinearList

const nodeCollection = tree.toLinearList(nodeId)

Back to TOC

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published