functional-red-black-tree
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The functional-red-black-tree npm package is a fully persistent red-black tree implementation written completely in JavaScript. This package works in both node.js and in the browser through browserify. Its functional data structure allows for non-destructive updates where inserting an element into the tree returns a new tree with the inserted element, instead of destructively updating the existing tree in place. The functional-red-black-tree aims to use memory optimally by recycling references to previously allocated subtrees. The package is particularly useful in applications that require this non-destructive update behavior despite the tradeoff of slower speed compared to an imperative version.
Here's a simple step by step guide on how to install and use the functional-red-black-tree in your JavaScript project.
Step 1: Install the functional-red-black-tree package via npm:
npm install functional-red-black-tree
Step 2: You can use the functions of the package in your code as follows:
//Load the library
var createTree = require("functional-red-black-tree")
//Create a tree
var t1 = createTree()
//Insert some items into the tree
var t2 = t1.insert(1, "foo")
var t3 = t2.insert(2, "bar")
//Remove something
var t4 = t3.remove(1)
In the above example, a red-black tree is created and then updated with various insertions and deletions of items.
The documentation for functional-red-black-tree is in the README file of the package hosted on GitHub. The link to the package is https://github.com/mikolalysenko/functional-red-black-tree.
The documentation covers installation and usage examples as well as an extensive API guide. This API guide comprehensively explains tree methods, node properties, and iterator methods. Each function in the documentation is explained along with its parameters, return values, and examples where necessary for a better understanding of its functioning.