UNPKG

@cute-dw/core

Version:

This TypeScript library is the main part of a more powerfull package designed for the fast WEB software development. The cornerstone of the library is the **DataStore** class, which might be useful when you need a full control of the data, but do not need

138 lines (137 loc) 5.05 kB
import { Comparator } from "../../util/Comparator"; import { Compare } from "../../util/function/Compare"; import { Element } from "../Collection"; export declare class BinaryTreeNode<K = any, V = any> { left: BinaryTreeNode<K, V> | null; right: BinaryTreeNode<K, V> | null; parent: BinaryTreeNode<K, V> | null; key: K; value: Element<V>; readonly data: Map<any, any>; protected nodeCompare: Compare<Readonly<BinaryTreeNode<K, V>>>; protected keyComparator: Comparator<K>; constructor(key: K, value?: Element<V>, comparator?: Comparator<K>); /** * @param {BinaryTreeNode} sourceNode * @param {BinaryTreeNode} targetNode * @static */ static copyNode(sourceNode: BinaryTreeNode, targetNode: BinaryTreeNode): void; get height(): number; get leftHeight(): number; get rightHeight(): number; get balanceFactor(): number; /** * Get current node's sibling node if exists * @returns {BinaryTreeNode} */ get sibling(): BinaryTreeNode<K, V> | undefined; /** * Get parent's sibling if it exists. * @returns {BinaryTreeNode} */ get uncle(): BinaryTreeNode<K, V> | undefined; /** * Gets the child direction of the current node relative to the parent node * @returns `0` - if the node is the _left_ child, `1` - if the node is the _right_ child, `NaN` - node hasn't the parent node */ get direction(): number; /** * @param {*} value * @returns {boolean} */ setValue(value: Element<V>): boolean; /** * Sets a node as a left child node * @param {BinaryTreeNode} node A new node to attach * @returns {this} `this` */ setLeft(node: BinaryTreeNode<K, V> | null): this; /** * Sets a node as a right child node * @param {BinaryTreeNode} node A new node to attach * @returns `this` */ setRight(node: BinaryTreeNode<K, V> | null): this; /** * Removes a specified node if it was attached to this node as a child * @param {BinaryTreeNode} nodeToRemove A node to remove if it is a child node * @returns {boolean} _true_ if a node is a child node and it was removed successfully, else _false_ */ removeChild(nodeToRemove: BinaryTreeNode<K, V>): boolean; /** * Replaces a child node * @param {BinaryTreeNode} nodeToReplace * @param {BinaryTreeNode} replacementNode * @returns {boolean} */ replaceChild(nodeToReplace: BinaryTreeNode<K, V>, replacementNode: BinaryTreeNode<K, V>): boolean; /** * @param {*} key * @returns {boolean} */ contains(key: K): boolean; /** * Finds right most child node * @returns {BinaryTreeNode} The node with the maximum key value * @readonly */ findMax(): BinaryTreeNode<K, V>; /** * Finds left most child node * @returns {BinaryTreeNode} The node with the minimum key value * @readonly */ findMin(): BinaryTreeNode<K, V>; /** * Finds a node by its `key` value * @param {K} key Key of the searching node * @returns {BinaryTreeNode|null} Node object or _null_ if the node was not found */ findNode(key: K): BinaryTreeNode<K, V> | null; /** * Traverses tree nodes up starting from the current node * @returns {BinaryTreeNode[]} Readonly array of nodes * @readonly */ traverseUpIterator(): IterableIterator<BinaryTreeNode<K, V>>; /** * Traverses tree nodes and generate a stream of the node objects * @param orderType */ traverseDownIterator(orderType?: "PreOrder!" | "InOrder!" | "PostOrder!"): IterableIterator<BinaryTreeNode<K, V>>; /** * Traverses tree nodes down starting from the current node * @returns {BinaryTreeNode[]} Readonly array of nodes * @readonly */ traverse(orderType?: "PreOrder!" | "InOrder!" | "PostOrder!"): ReadonlyArray<BinaryTreeNode<K, V>>; /** * Iterator */ [Symbol.iterator](): IterableIterator<BinaryTreeNode<K, V>>; /** * Adds a new node to this node * @param node New node object * @returns New node reference or `this` node if its `key` is identical to the key of `node` */ addNode(node: BinaryTreeNode<K, V>): BinaryTreeNode<K, V>; /** * Adds a new node to the current node * @param key Key of the node * @param value Node's value * @returns {BinaryTreeNode} */ add(key: K, value: Element<V>): BinaryTreeNode<K, V>; /** * Removes the node with the key `key` from the current node * @param {K} key A key of the node to remove * @returns {BinaryTreeNode|null} Removed node or `null` if the node was not found */ remove(key: K): Readonly<BinaryTreeNode<K, V>> | null; /** * Returns the comma delimited string of tree keys * @returns {string} String */ toString(): string; }