For the sake of API simplicity, if val is not provided, id can be used in its place.

This commit is contained in:
Revone 2023-08-24 00:01:44 +08:00
parent 6bc894c5c1
commit 2ea57d26ae
14 changed files with 185 additions and 102 deletions

View file

@ -1,6 +1,6 @@
{
"name": "data-structure-typed",
"version": "1.18.6",
"version": "1.18.7",
"description": "Explore our comprehensive Javascript Data Structure / TypeScript Data Structure Library, meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures, such as Binary Tree, AVL Tree, Binary Search Tree (BST), Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Singly Linked List, Hash, CoordinateSet, CoordinateMap, Heap, Doubly Linked List, Priority Queue, Max Priority Queue, Min Priority Queue, Queue, ObjectDeque, ArrayDeque, Stack, and Trie. Each data structure is thoughtfully designed and implemented using TypeScript to provide efficient, reliable, and easy-to-use solutions for your programming needs. Whether you're optimizing algorithms, managing data, or enhancing performance, our TypeScript Data Structure Library is your go-to resource. Elevate your coding experience with these fundamental building blocks for software development.",
"main": "dist/index.js",
"scripts": {

View file

@ -8,9 +8,9 @@
import {trampoline} from '../../utils';
import type {
AbstractRecursiveBinaryTreeNode,
AbstractBinaryTreeNodeProperty,
AbstractBinaryTreeNodeProperties,
AbstractBinaryTreeNodeProperty,
AbstractRecursiveBinaryTreeNode,
BinaryTreeDeletedResult,
BinaryTreeNodeId,
BinaryTreeNodePropertyName,
@ -21,9 +21,18 @@ import type {
import {AbstractBinaryTreeOptions, FamilyPosition, LoopType} from '../types';
import {IAbstractBinaryTree, IAbstractBinaryTreeNode} from '../interfaces';
export abstract class AbstractBinaryTreeNode<T, FAMILY extends AbstractBinaryTreeNode<T, FAMILY> = AbstractRecursiveBinaryTreeNode<T>> implements IAbstractBinaryTreeNode<T, FAMILY> {
export abstract class AbstractBinaryTreeNode<T = number, FAMILY extends AbstractBinaryTreeNode<T, FAMILY> = AbstractRecursiveBinaryTreeNode<T>> implements IAbstractBinaryTreeNode<T, FAMILY> {
constructor(id: BinaryTreeNodeId, val: T, count?: number) {
/**
* The constructor function initializes a BinaryTreeNode object with an id, value, and count.
* @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
* for the binary tree node.
* @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value of the binary
* tree node. If no value is provided, it will be `undefined`.
* @param {number} [count] - The `count` parameter is an optional parameter that represents the number of times the
* value `val` appears in the binary tree node. If the `count` parameter is not provided, it defaults to 1.
*/
constructor(id: BinaryTreeNodeId, val?: T, count?: number) {
this._id = id;
this._val = val;
this._count = count ?? 1;
@ -39,14 +48,14 @@ export abstract class AbstractBinaryTreeNode<T, FAMILY extends AbstractBinaryTre
this._id = v;
}
private _val: T;
private _val: T | undefined;
get val(): T {
return this._val;
get val(): T | undefined {
return this._val as T;
}
set val(v: T) {
this._val = v;
set val(value: T | undefined) {
this._val = value;
}
private _left?: FAMILY | null;
@ -117,8 +126,13 @@ export abstract class AbstractBinaryTreeNode<T, FAMILY extends AbstractBinaryTre
this._height = v;
}
abstract createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null
abstract createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY
/**
* The function swaps the location of two nodes in a binary tree.
* @param {FAMILY} swapNode - The `swapNode` parameter is of type `FAMILY`, which represents a node in a family tree.
* @returns the `swapNode` object after swapping its properties with the properties of `this` object.
*/
swapLocation(swapNode: FAMILY): FAMILY {
const {val, count, height} = swapNode;
const tempNode = this.createNode(swapNode.id, val);
@ -140,6 +154,11 @@ export abstract class AbstractBinaryTreeNode<T, FAMILY extends AbstractBinaryTre
return swapNode;
}
/**
* The `clone` function returns a new instance of the `FAMILY` class with the same `id`, `val`, and `count` properties.
* @returns The `clone()` method is returning a new instance of the `FAMILY` class with the same `id`, `val`, and
* `count` values as the current instance.
*/
clone(): FAMILY | null {
return this.createNode(this.id, this.val, this.count);
}
@ -310,12 +329,13 @@ export abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val
}
/**
* The function inserts a new node into a binary tree as the left or right child of a given parent node.
* @param {N | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
* `null`. It represents the node that needs to be inserted into the binary tree.
* @param parent - The `parent` parameter is a BinaryTreeNode object representing the parent node to which the new node
* will be inserted as a child.
* @returns The method returns the newly inserted node, either as the left child or the right child of the parent node.
* The function adds a new node to a binary tree as the left or right child of a given parent node.
* @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to the tree. It can be
* either a node object (`N`) or `null`.
* @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
* child.
* @returns either the left or right child node that was added to the parent node. It can also return `null` or
* `undefined` in certain cases.
*/
addTo(newNode: N | null, parent: N): N | null | undefined {
if (parent) {
@ -749,16 +769,14 @@ export abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val
}
}
/**
* The `isBST` function checks if a binary tree is a binary search tree.
* @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
* | null`. It represents the root node of the binary search tree (BST) that we want to check for validity. If no node
* is provided, the function will default to using the root node of the BST instance that
* @returns The `isBST` function returns a boolean value. It returns `true` if the binary tree is a valid binary search
* tree, and `false` otherwise.
* The function `isBSTByRooted` checks if a binary tree is a binary search tree (BST) by rooted traversal.
* @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
* @returns a boolean value.
*/
isBST(node?: N | null): boolean {
node = node ?? this.root;
isBSTByRooted(node: N | null): boolean {
if (!node) return true;
if (this._loopType === LoopType.RECURSIVE) {
@ -786,6 +804,16 @@ export abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val
}
}
/**
* The function checks if a binary tree is a binary search tree.
* @param {N | null} [node] - The `node` parameter is of type `N` or `null`. It represents the root node of a binary
* search tree (BST).
* @returns a boolean value.
*/
isBST(node?: N | null): boolean {
return this.isBSTByRooted(this.root);
}
/**
* The function calculates the size and count of a subtree in a binary tree using either recursive or iterative
* traversal.

View file

@ -10,7 +10,9 @@ import type {AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId, Recursiv
import {IAVLTree, IAVLTreeNode} from '../interfaces';
export class AVLTreeNode<T, FAMILY extends AVLTreeNode<T, FAMILY> = RecursiveAVLTreeNode<T>> extends BSTNode<T, FAMILY> implements IAVLTreeNode<T, FAMILY> {
override createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY {
return new AVLTreeNode(id, (val === undefined ? id : val) as T, count) as FAMILY;
}
}
export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<number>> extends BST<N> implements IAVLTree<N> {
@ -18,9 +20,8 @@ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<number>> e
super(options);
}
override createNode(id: BinaryTreeNodeId, val: N['val'], count?: number): N {
const node = new AVLTreeNode<N['val'], N>(id, val, count);
return node as N;
override createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N {
return new AVLTreeNode<N['val'], N>(id, (val === undefined ? id : val), count) as N;
}
/**

View file

@ -8,14 +8,23 @@
import type {BinaryTreeNodeId, RecursiveBinaryTreeNode} from '../types';
import {BinaryTreeOptions} from '../types';
import {IAbstractBinaryTree, IAbstractBinaryTreeNode} from '../interfaces';
import {AbstractBinaryTree, AbstractBinaryTreeNode} from './abstract-binary-tree';
import {IBinaryTree, IBinaryTreeNode} from '../interfaces/binary-tree';
export class BinaryTreeNode<T = number, FAMILY extends BinaryTreeNode<T, FAMILY> = RecursiveBinaryTreeNode<T>> extends AbstractBinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null {
return val !== null ? new BinaryTreeNode<T, FAMILY>(id, val, count) as FAMILY : null;
/**
* The function creates a new binary tree node with an optional value and count, and returns it as a specified type.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
* `BinaryTreeNodeId`, which could be a string or a number depending on how you want to identify your nodes.
* @param {T} [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the
* value stored in the node.
* @param {number} [count] - The count parameter is an optional parameter that represents the number of times the value
* appears in the binary tree node.
* @returns a new instance of the BinaryTreeNode class, casted as the FAMILY type.
*/
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY {
return new BinaryTreeNode<T, FAMILY>(id, (val === undefined ? id : val) as T, count) as FAMILY;
}
}
@ -43,9 +52,8 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
* of occurrences of the value in the binary tree node. If not provided, the default value is `undefined`.
* @returns a BinaryTreeNode object if the value is not null, otherwise it returns null.
*/
createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null {
const node = new BinaryTreeNode<N['val'], N>(id, val, count);
return node as N | null;
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N {
return new BinaryTreeNode<N['val'], N>(id, val === undefined ? id : val, count) as N;
}
}

View file

@ -8,10 +8,22 @@
import type {BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, RecursiveBSTNode} from '../types';
import {BinaryTreeDeletedResult, BSTOptions, CP, FamilyPosition, LoopType} from '../types';
import {BinaryTree, BinaryTreeNode} from './binary-tree';
import {IAbstractBinaryTree, IAbstractBinaryTreeNode, IBST, IBSTNode} from '../interfaces';
import {IBST, IBSTNode} from '../interfaces';
export class BSTNode<T, FAMILY extends BSTNode<T, FAMILY> = RecursiveBSTNode<T>> extends BinaryTreeNode<T, FAMILY> implements IBSTNode<T, FAMILY> {
/**
* The function creates a new binary search tree node with the specified id, value, and count.
* @param {BinaryTreeNodeId} id - The id parameter is the identifier for the binary tree node. It is used to uniquely
* identify each node in the tree.
* @param {T} [val] - The "val" parameter represents the value that will be stored in the binary tree node. It is an
* optional parameter, meaning it can be omitted when calling the "createNode" function.
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary
* search tree node. It is an optional parameter, so it can be omitted when calling the `createNode` method.
* @returns The method is returning a new instance of the BSTNode class, casted as the FAMILY type.
*/
override createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY {
return new BSTNode<T, FAMILY>(id, (val === undefined ? id : val) as T, count) as FAMILY;
}
}
export class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BinaryTree<N> implements IBST<N> {
@ -29,9 +41,18 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> extends Binar
}
}
override createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null {
const node = val !== null ? new BSTNode<N['val'], N>(id, val, count) : null;
return node as N;
/**
* The function creates a new binary search tree node with the given id, value, and count.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
* `BinaryTreeNodeId`.
* @param {N['val'] | null} [val] - The `val` parameter is the value that will be stored in the node. It can be of any
* type `N['val']` or `null`.
* @param {number} [count] - The `count` parameter is an optional parameter that represents the number of occurrences
* of a particular value in the binary search tree node.
* @returns a new instance of the BSTNode class, casted as type N.
*/
override createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N {
return new BSTNode<N['val'], N>(id, val === undefined ? id : val, count) as N;
}
/**

View file

@ -1,14 +1,9 @@
import {BinaryTreeNode} from './binary-tree';
import {RBColor, RBTreeOptions} from '../types';
import {BinaryTreeNodeId, RBColor, RBTreeOptions} from '../types';
import {IRBTree, IRBTreeNode} from '../interfaces/rb-tree';
import {BST} from './bst';
import {BST, BSTNode} from './bst';
export class RBTreeNode<T, FAMILY extends RBTreeNode<T, FAMILY>> extends BinaryTreeNode<T, FAMILY> implements IRBTreeNode<T, FAMILY> {
// override createNode(id: BinaryTreeNodeId, val: T | null, count?: number): RBNode<T> | null {
// return val !== null ? new RBNode<T>(id, val, count) : null;
// }
export class RBTreeNode<T, FAMILY extends RBTreeNode<T, FAMILY>> extends BSTNode<T, FAMILY> implements IRBTreeNode<T, FAMILY> {
constructor(id: number, val: T, count?: number) {
super(id, val, count);
}
@ -23,6 +18,20 @@ export class RBTreeNode<T, FAMILY extends RBTreeNode<T, FAMILY>> extends BinaryT
this._color = value;
}
/**
* The function creates a new RBTreeNode with the given id, value, and count and returns it as a FAMILY object.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
* identify each node in the tree.
* @param {T | null} [val] - The "val" parameter represents the value to be stored in the node. It can be of type T
* (generic type) or null.
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary tree
* node.
* @returns The method is returning a new instance of the RBTreeNode class, casted as a FAMILY type.
*/
override createNode(id: BinaryTreeNodeId, val?: T | null, count?: number): FAMILY {
return new RBTreeNode(id, val, count) as FAMILY;
}
// private override _parent: RBNode<T> | null;
// override set parent(v: RBNode<T> | null) {
// this._parent = v;
@ -64,9 +73,9 @@ export class RBTree<N extends RBTreeNode<N['val'], N>> extends BST<N> implements
super(options);
}
// override createNode(id: BinaryTreeNodeId, val: N | null, count?: number): RBNode<N> | null {
// return val !== null ? new RBNode<N>(id, val, count) : null;
// }
override createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N {
return new RBTreeNode(id, val, count) as N;
}
// private override _root: BinaryTreeNode<N> | null = null;
//

View file

@ -7,10 +7,22 @@
*/
import {BST, BSTNode} from './bst';
import type {BinaryTreeNodeId, RecursiveTreeMultiSetNode, TreeMultiSetOptions} from '../types';
import {IAbstractBinaryTree, IAbstractBinaryTreeNode, IBST, IBSTNode} from '../interfaces';
import {IBST, IBSTNode} from '../interfaces';
export class TreeMultiSetNode<T, FAMILY extends TreeMultiSetNode<T, FAMILY> = RecursiveTreeMultiSetNode<T>> extends BSTNode<T, FAMILY> implements IBSTNode<T, FAMILY> {
/**
* The function creates a new node in a binary tree with an optional value and count.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
* identify each node in the tree.
* @param {T} [val] - The `val` parameter represents the value to be stored in the node. It is an optional parameter,
* meaning it can be omitted when calling the `createNode` method.
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary tree
* node. It is an optional parameter, so it can be omitted when calling the `createNode` method.
* @returns The method is returning a new instance of the TreeMultiSetNode class, casted as the FAMILY type.
*/
override createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY {
return new TreeMultiSetNode(id, (val === undefined ? id : val) as T, count) as FAMILY;
}
}
/**
@ -30,8 +42,7 @@ export class TreeMultiSet<N extends BSTNode<N['val'], N> = BSTNode<number>> exte
* occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
* @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
*/
override createNode(id: BinaryTreeNodeId, val: N['val'], count?: number): N {
const node = new TreeMultiSetNode<N['val'], N>(id, val, count);
return node as N;
override createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N {
return new TreeMultiSetNode(id, val === undefined ? id : val, count) as N;
}
}

View file

@ -123,19 +123,10 @@ export abstract class AbstractGraph<V extends AbstractVertex<any>, E extends Abs
abstract removeEdge(edge: E): E | null;
protected _getVertex(vertexOrId: VertexId | V): V | null {
const vertexId = this._getVertexId(vertexOrId);
return this._vertices.get(vertexId) || null;
}
getVertex(vertexId: VertexId): V | null {
return this._vertices.get(vertexId) || null;
}
protected _getVertexId(vertexOrId: V | VertexId): VertexId {
return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
}
/**
* The function checks if a vertex exists in a graph.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
@ -666,12 +657,6 @@ export abstract class AbstractGraph<V extends AbstractVertex<any>, E extends Abs
return {distMap, preMap, seen, paths, minDist, minPath};
}
/**
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
*/
/**
* Dijkstra algorithm time: O(logVE) space: O(V + E)
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
@ -784,10 +769,9 @@ export abstract class AbstractGraph<V extends AbstractVertex<any>, E extends Abs
}
/**
* BellmanFord time:O(VE) space:O(V)
* one to rest pairs
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
*/
/**
@ -837,12 +821,6 @@ export abstract class AbstractGraph<V extends AbstractVertex<any>, E extends Abs
}
/**
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
* all pairs
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
*/
/**
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
* Tarjan can find cycles in directed or undirected graph
@ -967,6 +945,27 @@ export abstract class AbstractGraph<V extends AbstractVertex<any>, E extends Abs
return {dfnMap, lowMap, bridges, articulationPoints, SCCs, cycles};
}
/**
* BellmanFord time:O(VE) space:O(V)
* one to rest pairs
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
*/
protected _getVertex(vertexOrId: VertexId | V): V | null {
const vertexId = this._getVertexId(vertexOrId);
return this._vertices.get(vertexId) || null;
}
/**
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
* all pairs
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
*/
protected _getVertexId(vertexOrId: V | VertexId): VertexId {
return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
}
/**--- start find cycles --- */

View file

@ -8,7 +8,7 @@
import {arrayRemove} from '../../utils';
import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
import type {TopologicalStatus, VertexId} from '../types';
import {IDirectedGraph, IAbstractGraph} from '../interfaces';
import {IDirectedGraph} from '../interfaces';
export class DirectedVertex<T = number> extends AbstractVertex<T> {
/**

View file

@ -50,7 +50,7 @@ export class UndirectedEdge<T = number> extends AbstractEdge<T> {
}
}
export class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IUNDirectedGraph<V, E>{
export class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IUNDirectedGraph<V, E> {
constructor() {
super();

View file

@ -1,6 +1,6 @@
import {
AbstractBinaryTreeNodeProperty,
AbstractBinaryTreeNodeProperties,
AbstractBinaryTreeNodeProperty,
BinaryTreeDeletedResult,
BinaryTreeNodeId,
BinaryTreeNodePropertyName,
@ -13,44 +13,36 @@ import {AbstractBinaryTreeNode} from '../binary-tree';
export interface IAbstractBinaryTreeNode<T, FAMILY extends IAbstractBinaryTreeNode<T, FAMILY>> {
createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
get id(): BinaryTreeNodeId
set id(v: BinaryTreeNodeId)
get val(): T | undefined
get val(): T
set val(v: T)
set val(v: T | undefined)
get left(): FAMILY | null | undefined
set left(v: FAMILY | null | undefined)
get right(): FAMILY | null | undefined
set right(v: FAMILY | null | undefined)
get parent(): FAMILY | null | undefined
set parent(v: FAMILY | null | undefined)
get familyPosition(): FamilyPosition
set familyPosition(v: FamilyPosition)
get count(): number
set count(v: number)
get height(): number
set height(v: number)
@ -64,18 +56,29 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null
get loopType(): LoopType
get visitedId(): BinaryTreeNodeId[]
get visitedVal(): Array<N['val']>
get visitedNode(): N[]
get visitedCount(): number[]
get visitedLeftSum(): number[]
get autoIncrementId(): boolean
get maxId(): number
get isDuplicatedVal(): boolean
get root(): N | null
get size(): number
get count(): number
clear(): void
isEmpty(): boolean
@ -118,6 +121,8 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
getRightMost(node?: N | null): N | null
isBSTByRooted(node: N | null): boolean
isBST(node?: N | null): boolean
getSubTreeSizeAndCount(subTreeRoot: N | null | undefined): [number, number]

View file

@ -1,13 +1,13 @@
import {BSTNode} from '../binary-tree';
import {IBinaryTree, IBinaryTreeNode} from './binary-tree';
import {BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, CP} from '../types';
import {BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName} from '../types';
export interface IBSTNode<T, FAMILY extends IBSTNode<T, FAMILY>> extends IBinaryTreeNode<T, FAMILY> {
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY
}
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null
createNode(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N
add(id: BinaryTreeNodeId, val: N['val'] | null, count: number): N | null

View file

@ -1,11 +1,12 @@
import {RBTreeNode} from '../binary-tree';
import {IBST, IBSTNode} from './bst';
import {BinaryTreeNodeId} from '../types';
export interface IRBTreeNode<T, FAMILY extends IRBTreeNode<T, FAMILY>> extends IBSTNode<T, FAMILY> {
createNode(id: BinaryTreeNodeId, val?: T | null, count?: number): FAMILY
}
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
createNode(id: BinaryTreeNodeId, val?: N | null, count?: number): N
}

View file

@ -1,6 +1,6 @@
import {VertexId} from '../types';
import {IAbstractGraph} from './abstract-graph';
export interface IUNDirectedGraph<V, E> extends IAbstractGraph<V, E>{
export interface IUNDirectedGraph<V, E> extends IAbstractGraph<V, E> {
removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
}