std/collections/rb_tree.ts

Deno standard library
Go to Latest
class RBTree
extends BSTree<T>
import { RBTree } from "https://deno.land/std@0.145.0/collections/rb_tree.ts?s=RBTree";

A red-black tree. This is a kind of self-balancing binary search tree. The values are in ascending order by default, using JavaScript's built in comparison operators to sort the values.

Constructors

new
RBTree(compare?: (a: T, b: T) => number)
[src]

Properties

protected
root: RBNode<T> | null
[src]

Methods

protected
removeFixup(parent: RBNode<T> | null, current: RBNode<T> | null)
[src]
insert(value: T): boolean[src]

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

remove(value: T): boolean[src]

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

Static Methods

from<T>(collection: ArrayLike<T> | Iterable<T> | RBTree<T>): RBTree<T>[src]

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

from<T>(collection: ArrayLike<T> | Iterable<T> | RBTree<T>, options: { Node?: RBNode; compare?: (a: T, b: T) => number; }): RBTree<T>[src]
from<T, U, V>(collection: ArrayLike<T> | Iterable<T> | RBTree<T>, options: { compare?: (a: U, b: U) => number; map: (value: T, index: number) => U; thisArg?: V; }): RBTree<U>[src]
from<T, U, V>(collection: ArrayLike<T> | Iterable<T> | RBTree<T>, options?: { compare?: (a: U, b: U) => number; map?: (value: T, index: number) => U; thisArg?: V; }): RBTree<U>[src]