@types/functional-red-black-tree

  • Version 1.0.6
  • Published
  • 8.6 kB
  • No dependencies
  • MIT license

Install

npm i @types/functional-red-black-tree
yarn add @types/functional-red-black-tree
pnpm add @types/functional-red-black-tree

Overview

TypeScript definitions for functional-red-black-tree

Index

Functions

function createRBTree

createRBTree: <K, V>(
compare?: (key1: K, key2: K) => number
) => createRBTree.Tree<K, V>;
  • Creates an empty red-black tree.

    Parameter compare

    Optional comparison function, same semantics as array.sort().

    Returns

    An empty tree ordered by compare.

Interfaces

interface Iterator

interface Iterator<K, V> {}
  • Iterates through the nodes in a red-black tree.

property clone

clone: () => Iterator<K, V>;
  • Makes a copy of the iterator.

property hasNext

readonly hasNext: boolean;
  • If true, then the iterator is not at the end of the sequence.

property hasPrev

readonly hasPrev: boolean;
  • If true, then the iterator is not at the beginning of the sequence.

property index

readonly index: number;
  • Returns the position of the iterator in the sequence.

property key

readonly key?: K | undefined;
  • The key of the iterator's current item.

property next

next: () => void;
  • Advances the iterator to the next position.

property node

readonly node: Node<K, V> | null;
  • The value of the node at the iterator's current position, or null if the iterator is invalid.

property prev

prev: () => void;
  • Moves the iterator backward one element.

property remove

remove: () => Tree<K, V>;
  • Removes the iterator's current item form the tree.

    Returns

    A new binary search tree with the item removed.

property tree

tree: Tree<K, V>;
  • The tree associated with the iterator.

property update

update: (value: V) => Tree<K, V>;
  • Updates the value of the iterator's current item.

    Returns

    A new binary search tree with the corresponding node updated.

property valid

readonly valid: boolean;
  • Checks if the iterator is valid.

property value

readonly value?: V | undefined;
  • The value of the iterator's current item.

interface Node

interface Node<K, V> {}
  • Represents a node in a red-black tree.

property key

key: K;
  • The key associated with the node.

property left

left: Tree<K, V>;
  • The left subtree of the node.

property right

right: Tree<K, V>;
  • The right subtree of the node.

property value

value: V;
  • The value associated with the node.

interface Tree

interface Tree<K, V> {}
  • Represents a functional red-black tree.

property at

at: (idx: number) => Iterator<K, V>;
  • Finds an iterator starting at the given element.

    Parameter position

    The index at which the iterator gets created.

    Returns

    An iterator starting at position.

property begin

readonly begin: Iterator<K, V>;
  • An iterator pointing to the first element in the tree.

property end

readonly end: Iterator<K, V>;
  • An iterator pointing to the last element in the tree.

property find

find: (key: K) => Iterator<K, V>;
  • Returns

    An iterator pointing to the first item in the tree with key, otherwise null.

property forEach

forEach: {
<T>(visitor: (key: K, value: V) => T): T;
// tslint:disable-next-line:unified-signatures
<T>(visitor: (key: K, value: V) => T, lo: K, hi?: K): T;
};
  • Walks a visitor function over the nodes of the tree in order.

    Parameter visitor

    The callback to be executed on each node. If a truthy value is returned from the visitor, then iteration is stopped.

    Parameter lo

    An optional start of the range to visit (inclusive).

    Parameter hi

    An optional end of the range to visit (non-inclusive).

    Returns

    The last value returned by the callback.

property ge

ge: (key: K) => Iterator<K, V>;
  • Finds the first item in the tree whose key is >= key.

    Parameter key

    The key to search for.

    Returns

    An iterator at the given element.

property get

get: (key: K) => V | void;
  • Retrieves the value associated with key.

    Parameter key

    The key of the item to look up.

    Returns

    The value of the first node associated with key.

property gt

gt: (key: K) => Iterator<K, V>;
  • Finds the first item in the tree whose key is > key.

    Parameter key

    The key to search for.

    Returns

    An iterator at the given element.

property insert

insert: (key: K, value: V) => Tree<K, V>;
  • Creates a new tree with the new key/value pair inserted.

    Parameter key

    The key of the item to insert.

    Parameter value

    The value of the item to insert.

    Returns

    A new tree with key and value inserted.

property keys

readonly keys: K[];
  • A sorted array of all keys in the tree.

property le

le: (key: K) => Iterator<K, V>;
  • Finds the last item in the tree whose key is <= key.

    Parameter key

    The key to search for.

    Returns

    An iterator at the given element.

property length

readonly length: number;
  • The number of items in the tree.

property lt

lt: (key: K) => Iterator<K, V>;
  • Finds the last item in the tree whose key is < key.

    Parameter key

    The key to search for.

    Returns

    An iterator at the given element.

property remove

remove: (key: K) => Tree<K, V>;
  • Removes the first item with key in the tree.

    Parameter key

    The key of the item to remove.

    Returns

    A new tree with the given item removed, if it exists.

property root

root: Node<K, V>;
  • Returns the root node of the tree.

property values

readonly values: V[];
  • An array of all values in the tree, sorted by key.

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (0)

No dev dependencies.

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/functional-red-black-tree.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/functional-red-black-tree)
  • HTML
    <a href="https://www.jsdocs.io/package/@types/functional-red-black-tree"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>