Skip to main content
Module

x/collections/mod.ts>RBTree

Collection data structures that are not standard built-in objects in JavaScript. This includes a vector (double-ended queue), binary heap (priority queue), binary search tree, and a red black tree.
Very Popular
Go to Latest
class RBTree
extends BSTree<T>
import { RBTree } from "https://deno.land/x/collections@0.11.2/mod.ts";

A red-black tree. The values are in ascending order by default, using JavaScript's built in comparison operators to sort the values.

Constructors

new
RBTree(compare?: compare<Partial<T>> | compareDefined<Partial<T>>)

Properties

protected
root: RBNode<T> | null

Methods

private
removeFixup(parent: RBNode<T> | null, current: RBNode<T> | null)
insert(value: T): boolean

Adds the value to the binary search tree if it does not already exist in it. Returns true if successful.

remove(value: T): boolean

Removes node value from the binary search tree if found. Returns true if found and removed.

Static Methods

from<T, U>(collection: ArrayLike<T> | Iterable<T> | RBTree<T>): RBTree<U>

Creates a new red-black tree from an array like or iterable object.

from<T, U>(collection: ArrayLike<T> | Iterable<T> | RBTree<T>, options: { Node?: RBNode; compare?: compare<Partial<U>> | compareDefined<Partial<U>>; }): RBTree<U>
from<T, U, V>(collection: ArrayLike<T> | Iterable<T> | RBTree<T>, options: { Node?: RBNode; compare?: compare<Partial<U>> | compareDefined<Partial<U>>; map: mapDefined<T, U>; thisArg?: V; }): RBTree<U>