[core] Clean up unnecessary redundancies in the interfaces and rectify any illogical interface definitions.

This commit is contained in:
Revone 2023-10-11 20:21:20 +08:00
parent dd68ba8af2
commit 4d01fa413e
10 changed files with 19 additions and 277 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "data-structure-typed",
"version": "1.34.8",
"version": "1.34.9",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "data-structure-typed",
"version": "1.34.8",
"version": "1.34.9",
"license": "MIT",
"devDependencies": {
"@types/benchmark": "^2.1.3",

View file

@ -1,176 +1,8 @@
import {
AbstractBinaryTreeNodeProperties,
AbstractBinaryTreeNodeProperty,
BinaryTreeDeletedResult,
BinaryTreeNodeKey,
BinaryTreeNodePropertyName,
DFSOrderPattern,
FamilyPosition,
LoopType,
NodeOrPropertyName
} from '../types';
import {BinaryTreeNodeKey} from '../types';
import {AbstractBinaryTreeNode} from '../data-structures';
export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
key: BinaryTreeNodeKey;
val: T | undefined;
get left(): NEIGHBOR | null | undefined;
set left(v: NEIGHBOR | null | undefined);
get right(): NEIGHBOR | null | undefined;
set right(v: NEIGHBOR | null | undefined);
parent: NEIGHBOR | null | undefined;
get familyPosition(): FamilyPosition;
}
export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {}
export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N | null;
get loopType(): LoopType;
get visitedKey(): BinaryTreeNodeKey[];
get visitedVal(): Array<N['val']>;
get visitedNode(): N[];
get root(): N | null;
get size(): number;
swapLocation(srcNode: N, destNode: N): N;
clear(): void;
isEmpty(): boolean;
add(key: BinaryTreeNodeKey | N, val?: N['val']): N | null | undefined;
addMany(keysOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N['val'][]): (N | null | undefined)[];
refill(keysOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N[] | Array<N['val']>): boolean;
remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
getDepth(node: N): number;
getHeight(beginRoot?: N | null): number;
getMinHeight(beginRoot?: N | null): number;
isPerfectlyBalanced(beginRoot?: N | null): boolean;
getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
has(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): boolean;
get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
getPathToRoot(node: N): N[];
getLeftMost(): N | null;
getLeftMost(node: N): N;
getLeftMost(node?: N | null): N | null;
getRightMost(): N | null;
getRightMost(node: N): N;
getRightMost(node?: N | null): N | null;
isSubtreeBST(node: N | null): boolean;
isBST(): boolean;
getSubTreeSize(subTreeRoot: N | null | undefined): number;
// --- start additional methods ---
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
bfs(): BinaryTreeNodeKey[];
bfs(nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
bfs(nodeOrPropertyName: 'val'): N['val'][];
bfs(nodeOrPropertyName: 'node'): N[];
bfs(nodeOrPropertyName: 'count'): number[];
bfs(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
dfs(): BinaryTreeNodeKey[];
dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
dfs(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
dfsIterative(): BinaryTreeNodeKey[];
dfsIterative(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N['val'][];
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
levelIterative(node: N | null): BinaryTreeNodeKey[];
levelIterative(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
levelIterative(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
listLevels(node: N | null): BinaryTreeNodeKey[][];
listLevels(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[][];
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
listLevels(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperty<N>[][];
getPredecessor(node: N): N;
morris(): BinaryTreeNodeKey[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
morris(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
// --- end additional methods ---
}

View file

@ -1,31 +1,7 @@
import {VertexKey} from '../types';
export interface IAbstractGraph<V, E> {
hasVertex(vertexOrKey: V | VertexKey): boolean;
createVertex(key: VertexKey, val?: V): V;
addVertex(key: VertexKey, val?: V): boolean;
removeVertex(vertexOrKey: V | VertexKey): boolean;
removeAllVertices(vertices: V[] | VertexKey[]): boolean;
degreeOf(vertexOrKey: V | VertexKey): number;
edgesOf(vertexOrKey: V | VertexKey): E[];
hasEdge(src: V | VertexKey, dest: V | VertexKey): boolean;
getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
edgeSet(): E[];
addEdge(src: V | VertexKey, dest: V | VertexKey, weight: number, val: E): boolean;
removeEdge(edge: E): E | null;
setEdgeWeight(srcOrKey: V | VertexKey, destOrKey: V | VertexKey, weight: number): boolean;
getMinPathBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): V[] | null;
getNeighbors(vertexOrKey: V | VertexKey): V[];
createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E;
}

View file

@ -1,27 +1,8 @@
import {AVLTreeNode} from '../data-structures';
import {IBST, IBSTNode} from './bst';
import {BinaryTreeDeletedResult, BinaryTreeNodeKey} from '../types';
export interface IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
height: number;
}
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
add(key: BinaryTreeNodeKey, val?: N['val'] | null): N | null | undefined;
remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
// _balanceFactor(node: N): number
//
// _updateHeight(node: N): void
//
// _balancePath(node: N): void
//
// _balanceLL(A: N): void
//
// _balanceLR(A: N): void
//
// _balanceRR(A: N): void
//
// _balanceRL(A: N): void
}
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {}

View file

@ -1,6 +1,7 @@
import {BinaryTreeNode} from '../data-structures';
import {IAbstractBinaryTree, IAbstractBinaryTreeNode} from './abstract-binary-tree';
export type IBinaryTreeNode<T, NEIGHBOR extends IBinaryTreeNode<T, NEIGHBOR>> = IAbstractBinaryTreeNode<T, NEIGHBOR>;
export interface IBinaryTreeNode<T, NEIGHBOR extends IBinaryTreeNode<T, NEIGHBOR>>
extends IAbstractBinaryTreeNode<T, NEIGHBOR> {}
export type IBinaryTree<N extends BinaryTreeNode<N['val'], N>> = IAbstractBinaryTree<N>;
export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> extends IAbstractBinaryTree<N> {}

View file

@ -1,31 +1,6 @@
import {BSTNode} from '../data-structures';
import {IBinaryTree, IBinaryTreeNode} from './binary-tree';
import {BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodePropertyName} from '../types';
export interface IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> extends IBinaryTreeNode<T, NEIGHBOR> {}
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
add(key: BinaryTreeNodeKey, val?: N['val'] | null, count?: number): N | null | undefined;
get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
lastKey(): BinaryTreeNodeKey;
remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
// --- start additional functions
lesserSum(key: BinaryTreeNodeKey, propertyName?: BinaryTreeNodePropertyName): number;
allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
perfectlyBalance(): boolean;
isAVLBalanced(): boolean;
// --- end additional functions
}
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {}

View file

@ -1,20 +1,3 @@
import {VertexKey} from '../types';
import {IAbstractGraph} from './abstract-graph';
export interface IDirectedGraph<V, E> extends IAbstractGraph<V, E> {
incomingEdgesOf(vertex: V): E[];
outgoingEdgesOf(vertex: V): E[];
inDegreeOf(vertexOrKey: V | VertexKey): number;
outDegreeOf(vertexOrKey: V | VertexKey): number;
getEdgeSrc(e: E): V | null;
getEdgeDest(e: E): V | null;
removeEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
removeEdgesBetween(v1: V | VertexKey, v2: V | VertexKey): E[];
}
export interface IDirectedGraph<V, E> extends IAbstractGraph<V, E> {}

View file

@ -1,9 +1,6 @@
import {RBTreeNode} from '../data-structures';
import {IBST, IBSTNode} from './bst';
import {BinaryTreeNodeKey} from '../types';
export type IRBTreeNode<T, NEIGHBOR extends IRBTreeNode<T, NEIGHBOR>> = IBSTNode<T, NEIGHBOR>;
export interface IRBTreeNode<T, NEIGHBOR extends IRBTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {}
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
}
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {}

View file

@ -1,7 +1,7 @@
import {TreeMultisetNode} from '../data-structures';
import {IBSTNode} from './bst';
import {IAVLTree} from './avl-tree';
import {IAVLTree, IAVLTreeNode} from './avl-tree';
export type ITreeMultisetNode<T, NEIGHBOR extends ITreeMultisetNode<T, NEIGHBOR>> = IBSTNode<T, NEIGHBOR>;
export interface ITreeMultisetNode<T, NEIGHBOR extends ITreeMultisetNode<T, NEIGHBOR>>
extends IAVLTreeNode<T, NEIGHBOR> {}
export type ITreeMultiset<N extends TreeMultisetNode<N['val'], N>> = IAVLTree<N>;
export interface ITreeMultiset<N extends TreeMultisetNode<N['val'], N>> extends IAVLTree<N> {}

View file

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