From 4d01fa413ed8d6b6343e071944cc9c26e6122d96 Mon Sep 17 00:00:00 2001 From: Revone Date: Wed, 11 Oct 2023 20:21:20 +0800 Subject: [PATCH] [core] Clean up unnecessary redundancies in the interfaces and rectify any illogical interface definitions. --- package-lock.json | 4 +- src/interfaces/abstract-binary-tree.ts | 172 +------------------------ src/interfaces/abstract-graph.ts | 28 +--- src/interfaces/avl-tree.ts | 21 +-- src/interfaces/binary-tree.ts | 5 +- src/interfaces/bst.ts | 27 +--- src/interfaces/directed-graph.ts | 19 +-- src/interfaces/rb-tree.ts | 7 +- src/interfaces/tree-multiset.ts | 8 +- src/interfaces/undirected-graph.ts | 5 +- 10 files changed, 19 insertions(+), 277 deletions(-) diff --git a/package-lock.json b/package-lock.json index 540e380..3dcf290 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/src/interfaces/abstract-binary-tree.ts b/src/interfaces/abstract-binary-tree.ts index e39f6da..b3fd59d 100644 --- a/src/interfaces/abstract-binary-tree.ts +++ b/src/interfaces/abstract-binary-tree.ts @@ -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> { - 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> {} export interface IAbstractBinaryTree> { createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N | null; - - get loopType(): LoopType; - - get visitedKey(): BinaryTreeNodeKey[]; - - get visitedVal(): Array; - - 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): boolean; - - remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult[]; - - 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; - - 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; - - 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; - - 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; - - 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[][]; - - 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; - - // --- end additional methods --- } diff --git a/src/interfaces/abstract-graph.ts b/src/interfaces/abstract-graph.ts index 484d7ac..73addcd 100644 --- a/src/interfaces/abstract-graph.ts +++ b/src/interfaces/abstract-graph.ts @@ -1,31 +1,7 @@ import {VertexKey} from '../types'; export interface IAbstractGraph { - 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; } diff --git a/src/interfaces/avl-tree.ts b/src/interfaces/avl-tree.ts index a98d421..a2ce1d4 100644 --- a/src/interfaces/avl-tree.ts +++ b/src/interfaces/avl-tree.ts @@ -1,27 +1,8 @@ import {AVLTreeNode} from '../data-structures'; import {IBST, IBSTNode} from './bst'; -import {BinaryTreeDeletedResult, BinaryTreeNodeKey} from '../types'; export interface IAVLTreeNode> extends IBSTNode { height: number; } -export interface IAVLTree> extends IBST { - add(key: BinaryTreeNodeKey, val?: N['val'] | null): N | null | undefined; - - remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult[]; - - // _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> extends IBST {} diff --git a/src/interfaces/binary-tree.ts b/src/interfaces/binary-tree.ts index d21cfd3..45d9ac6 100644 --- a/src/interfaces/binary-tree.ts +++ b/src/interfaces/binary-tree.ts @@ -1,6 +1,7 @@ import {BinaryTreeNode} from '../data-structures'; import {IAbstractBinaryTree, IAbstractBinaryTreeNode} from './abstract-binary-tree'; -export type IBinaryTreeNode> = IAbstractBinaryTreeNode; +export interface IBinaryTreeNode> + extends IAbstractBinaryTreeNode {} -export type IBinaryTree> = IAbstractBinaryTree; +export interface IBinaryTree> extends IAbstractBinaryTree {} diff --git a/src/interfaces/bst.ts b/src/interfaces/bst.ts index 29fd7f2..50bac41 100644 --- a/src/interfaces/bst.ts +++ b/src/interfaces/bst.ts @@ -1,31 +1,6 @@ import {BSTNode} from '../data-structures'; import {IBinaryTree, IBinaryTreeNode} from './binary-tree'; -import {BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodePropertyName} from '../types'; export interface IBSTNode> extends IBinaryTreeNode {} -export interface IBST> extends IBinaryTree { - 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[]; - - 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> extends IBinaryTree {} diff --git a/src/interfaces/directed-graph.ts b/src/interfaces/directed-graph.ts index 0347e18..e6b38ba 100644 --- a/src/interfaces/directed-graph.ts +++ b/src/interfaces/directed-graph.ts @@ -1,20 +1,3 @@ -import {VertexKey} from '../types'; import {IAbstractGraph} from './abstract-graph'; -export interface IDirectedGraph extends IAbstractGraph { - 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 extends IAbstractGraph {} diff --git a/src/interfaces/rb-tree.ts b/src/interfaces/rb-tree.ts index 0a1eb05..5c2ead5 100644 --- a/src/interfaces/rb-tree.ts +++ b/src/interfaces/rb-tree.ts @@ -1,9 +1,6 @@ import {RBTreeNode} from '../data-structures'; import {IBST, IBSTNode} from './bst'; -import {BinaryTreeNodeKey} from '../types'; -export type IRBTreeNode> = IBSTNode; +export interface IRBTreeNode> extends IBSTNode {} -export interface IRBTree> extends IBST { - createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N; -} +export interface IRBTree> extends IBST {} diff --git a/src/interfaces/tree-multiset.ts b/src/interfaces/tree-multiset.ts index a46449f..f3955ac 100644 --- a/src/interfaces/tree-multiset.ts +++ b/src/interfaces/tree-multiset.ts @@ -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> = IBSTNode; +export interface ITreeMultisetNode> + extends IAVLTreeNode {} -export type ITreeMultiset> = IAVLTree; +export interface ITreeMultiset> extends IAVLTree {} diff --git a/src/interfaces/undirected-graph.ts b/src/interfaces/undirected-graph.ts index 6e52eb2..bc08f80 100644 --- a/src/interfaces/undirected-graph.ts +++ b/src/interfaces/undirected-graph.ts @@ -1,6 +1,3 @@ -import {VertexKey} from '../types'; import {IAbstractGraph} from './abstract-graph'; -export interface IUNDirectedGraph extends IAbstractGraph { - removeEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null; -} +export interface IUNDirectedGraph extends IAbstractGraph {}