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

78 lines (77 loc) 2.77 kB
import { Comparator } from "../../util/Comparator"; import { Element } from "../Collection"; import { BinaryTreeNode } from "./BinaryTreeNode"; /** * In computer science, binary search trees (BST), sometimes called ordered or sorted binary trees, * are a particular type of container: data structures that store "items" (such as numbers, names etc.) * in memory. They allow fast lookup, addition and removal of items, and can be used to implement * either dynamic sets of items, or lookup tables that allow finding an item by its key * (e.g., finding the phone number of a person by name). */ export declare class BinarySearchTree<K, V = K> { protected root: BinaryTreeNode<K, V> | null; readonly keyComparator: Comparator<K>; constructor(comparator?: Comparator<K>); clear(): void; count(): number; height(): number; /** * Test the tree for empness * @returns _true_ if the tree doesn't have child nodes, else _false_ */ isEmpty(): boolean; /** * Inserts a new element to the tree * @param {K} key * @param {*} value * @returns {BinaryTreeNode} */ add(key: K, value: Element<V>): BinaryTreeNode<K, V>; /** * @param {*} key * @return {boolean} */ contains(key: K): boolean; /** * * @param key * @returns */ get(key: K): Element<V> | undefined; /** * @param {K} key * @returns {Element|undefined} */ remove(key: K): Element<V> | undefined; /** * @return {string} */ toString(): string; /** * Executes a `callBack` function for each entry in this dictionary * @param callBack Function to call on each tree item * @param thisArg An object to which the `this` keyword can refer in the `callBack` function. If `thisArg` is omitted, undefined is used as the `this` value */ forEach(callBack: (value: Element<V>, key: K, node: BinaryTreeNode<K, V>) => void, thisArg?: any): void; /** * Gets an array of the children keys for the specified `key` * @param key * @returns */ childrenKeys(key: K): Array<K>; /** * Gets an array of the parent keys for the specified `key` * @param key * @returns */ parentKeys(key: K): Array<K>; /** Returns the first (lowest) key currently in this map */ firstKey(): K | undefined; /** Returns the last (highest) key currently in this map */ lastKey(): K | undefined; keySet(): Set<K>; keys(): Array<K>; values(): Array<Element<V>>; [Symbol.iterator](): IterableIterator<BinaryTreeNode<K, V>>; print(parentNode?: BinaryTreeNode<K, V> | null, indent?: number): string; }