From 8db8976503558cd2cc34175e95e4cbc35d6bddcd Mon Sep 17 00:00:00 2001 From: Revone Date: Thu, 24 Aug 2023 11:13:28 +0800 Subject: [PATCH] All the RecursiveNodes renamed as NodeNested pattern. TreeMultiSet extended from AVLTree --- .../binary-tree/abstract-binary-tree.ts | 6 +++--- src/data-structures/binary-tree/avl-tree.ts | 6 +++--- src/data-structures/binary-tree/binary-tree.ts | 4 ++-- src/data-structures/binary-tree/bst.ts | 6 +++--- src/data-structures/binary-tree/rb-tree.ts | 6 +++--- src/data-structures/binary-tree/tree-multiset.ts | 12 ++++++------ src/data-structures/interfaces/tree-multiset.ts | 13 ++++++++++++- src/data-structures/types/abstract-binary-tree.ts | 2 +- src/data-structures/types/avl-tree.ts | 2 +- src/data-structures/types/binary-tree.ts | 2 +- src/data-structures/types/bst.ts | 2 +- src/data-structures/types/rb-tree.ts | 3 +++ src/data-structures/types/tree-multiset.ts | 6 +++--- 13 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/data-structures/binary-tree/abstract-binary-tree.ts b/src/data-structures/binary-tree/abstract-binary-tree.ts index 1f4f02a..25956eb 100644 --- a/src/data-structures/binary-tree/abstract-binary-tree.ts +++ b/src/data-structures/binary-tree/abstract-binary-tree.ts @@ -10,7 +10,7 @@ import {trampoline} from '../../utils'; import type { AbstractBinaryTreeNodeProperties, AbstractBinaryTreeNodeProperty, - AbstractRecursiveBinaryTreeNode, + AbstractBinaryTreeNodeNested, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, @@ -21,7 +21,7 @@ import type { import {AbstractBinaryTreeOptions, FamilyPosition, LoopType} from '../types'; import {IAbstractBinaryTree, IAbstractBinaryTreeNode} from '../interfaces'; -export abstract class AbstractBinaryTreeNode = AbstractRecursiveBinaryTreeNode> implements IAbstractBinaryTreeNode { +export abstract class AbstractBinaryTreeNode = AbstractBinaryTreeNodeNested> implements IAbstractBinaryTreeNode { /** * The constructor function initializes a BinaryTreeNode object with an id, value, and count. @@ -164,7 +164,7 @@ export abstract class AbstractBinaryTreeNode = AbstractBinaryTreeNode> implements IAbstractBinaryTree { +export abstract class AbstractBinaryTree = AbstractBinaryTreeNode> implements IAbstractBinaryTree { /** * The protected constructor initializes the options for an abstract binary tree. diff --git a/src/data-structures/binary-tree/avl-tree.ts b/src/data-structures/binary-tree/avl-tree.ts index b60aa52..8eb8aa8 100644 --- a/src/data-structures/binary-tree/avl-tree.ts +++ b/src/data-structures/binary-tree/avl-tree.ts @@ -6,16 +6,16 @@ * @license MIT License */ import {BST, BSTNode} from './bst'; -import type {AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId, RecursiveAVLTreeNode} from '../types'; +import type {AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId, AVLTreeNodeNested} from '../types'; import {IAVLTree, IAVLTreeNode} from '../interfaces'; -export class AVLTreeNode = RecursiveAVLTreeNode> extends BSTNode implements IAVLTreeNode { +export class AVLTreeNode = AVLTreeNodeNested> extends BSTNode implements IAVLTreeNode { 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 = AVLTreeNode> extends BST implements IAVLTree { +export class AVLTree = AVLTreeNode> extends BST implements IAVLTree { constructor(options?: AVLTreeOptions) { super(options); } diff --git a/src/data-structures/binary-tree/binary-tree.ts b/src/data-structures/binary-tree/binary-tree.ts index 745949d..3aa34a3 100644 --- a/src/data-structures/binary-tree/binary-tree.ts +++ b/src/data-structures/binary-tree/binary-tree.ts @@ -6,12 +6,12 @@ * @license MIT License */ -import type {BinaryTreeNodeId, RecursiveBinaryTreeNode} from '../types'; +import type {BinaryTreeNodeId, BinaryTreeNodeNested} from '../types'; import {BinaryTreeOptions} from '../types'; import {AbstractBinaryTree, AbstractBinaryTreeNode} from './abstract-binary-tree'; import {IBinaryTree, IBinaryTreeNode} from '../interfaces/binary-tree'; -export class BinaryTreeNode = RecursiveBinaryTreeNode> extends AbstractBinaryTreeNode implements IBinaryTreeNode { +export class BinaryTreeNode = BinaryTreeNodeNested> extends AbstractBinaryTreeNode implements IBinaryTreeNode { /** * The function creates a new binary tree node with an optional value and count, and returns it as a specified type. diff --git a/src/data-structures/binary-tree/bst.ts b/src/data-structures/binary-tree/bst.ts index 59a955a..d3dd827 100644 --- a/src/data-structures/binary-tree/bst.ts +++ b/src/data-structures/binary-tree/bst.ts @@ -5,12 +5,12 @@ * @copyright Copyright (c) 2022 Tyler Zeng * @license MIT License */ -import type {BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, RecursiveBSTNode} from '../types'; +import type {BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTNodeNested} from '../types'; import {BinaryTreeDeletedResult, BSTOptions, CP, FamilyPosition, LoopType} from '../types'; import {BinaryTree, BinaryTreeNode} from './binary-tree'; import {IBST, IBSTNode} from '../interfaces'; -export class BSTNode = RecursiveBSTNode> extends BinaryTreeNode implements IBSTNode { +export class BSTNode = BSTNodeNested> extends BinaryTreeNode implements IBSTNode { /** * 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 @@ -26,7 +26,7 @@ export class BSTNode = RecursiveBSTNode> } } -export class BST = BSTNode> extends BinaryTree implements IBST { +export class BST = BSTNode> extends BinaryTree implements IBST { /** * The constructor function accepts an optional options object and sets the comparator property if provided. * @param [options] - An optional object that can contain the following properties: diff --git a/src/data-structures/binary-tree/rb-tree.ts b/src/data-structures/binary-tree/rb-tree.ts index 6495a1c..2870c31 100644 --- a/src/data-structures/binary-tree/rb-tree.ts +++ b/src/data-structures/binary-tree/rb-tree.ts @@ -1,9 +1,9 @@ -import {BinaryTreeNodeId, RBColor, RBTreeOptions} from '../types'; +import {BinaryTreeNodeId, RBColor, RBTreeOptions, RBTreeNodeNested} from '../types'; import {IRBTree, IRBTreeNode} from '../interfaces/rb-tree'; import {BST, BSTNode} from './bst'; -export class RBTreeNode> extends BSTNode implements IRBTreeNode { +export class RBTreeNode =RBTreeNodeNested> extends BSTNode implements IRBTreeNode { constructor(id: number, val: T, count?: number) { super(id, val, count); } @@ -68,7 +68,7 @@ export class RBTreeNode> extends BSTNode // } } -export class RBTree> extends BST implements IRBTree { +export class RBTree = RBTreeNode> extends BST implements IRBTree { constructor(options?: RBTreeOptions) { super(options); } diff --git a/src/data-structures/binary-tree/tree-multiset.ts b/src/data-structures/binary-tree/tree-multiset.ts index 8797f5f..9d15067 100644 --- a/src/data-structures/binary-tree/tree-multiset.ts +++ b/src/data-structures/binary-tree/tree-multiset.ts @@ -5,11 +5,11 @@ * @copyright Copyright (c) 2022 Tyler Zeng * @license MIT License */ -import {BST, BSTNode} from './bst'; -import type {BinaryTreeNodeId, RecursiveTreeMultiSetNode, TreeMultiSetOptions} from '../types'; -import {IBST, IBSTNode} from '../interfaces'; +import type {BinaryTreeNodeId, TreeMultiSetNodeNested, TreeMultiSetOptions} from '../types'; +import {ITreeMultiSet, ITreeMultiSetNode} from '../interfaces'; +import {AVLTree, AVLTreeNode} from './avl-tree'; -export class TreeMultiSetNode = RecursiveTreeMultiSetNode> extends BSTNode implements IBSTNode { +export class TreeMultiSetNode = TreeMultiSetNodeNested> extends AVLTreeNode implements ITreeMultiSetNode { /** * 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 @@ -26,9 +26,9 @@ export class TreeMultiSetNode = Re } /** - * The only distinction between a TreeMultiSet and a BST lies in the ability of the former to store duplicate nodes through the utilization of counters. + * The only distinction between a TreeMultiSet and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters. */ -export class TreeMultiSet = BSTNode> extends BST implements IBST { +export class TreeMultiSet = TreeMultiSetNode> extends AVLTree implements ITreeMultiSet { constructor(options?: TreeMultiSetOptions) { super({...options, isDuplicatedVal: true}); } diff --git a/src/data-structures/interfaces/tree-multiset.ts b/src/data-structures/interfaces/tree-multiset.ts index 693da49..72d9c3e 100644 --- a/src/data-structures/interfaces/tree-multiset.ts +++ b/src/data-structures/interfaces/tree-multiset.ts @@ -1 +1,12 @@ -export {} \ No newline at end of file +import {TreeMultiSetNode} from '../binary-tree'; +import {IBSTNode} from './bst'; +import {IAVLTree} from './avl-tree'; + +export interface ITreeMultiSetNode> extends IBSTNode { + +} + +export interface ITreeMultiSet> extends IAVLTree { + + +} \ No newline at end of file diff --git a/src/data-structures/types/abstract-binary-tree.ts b/src/data-structures/types/abstract-binary-tree.ts index 854f6d9..604dd98 100644 --- a/src/data-structures/types/abstract-binary-tree.ts +++ b/src/data-structures/types/abstract-binary-tree.ts @@ -23,7 +23,7 @@ export type AbstractBinaryTreeNodeProperty> = AbstractBinaryTreeNodeProperty[]; -export type AbstractRecursiveBinaryTreeNode = AbstractBinaryTreeNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +export type AbstractBinaryTreeNodeNested = AbstractBinaryTreeNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> export type AbstractBinaryTreeOptions = { loopType?: LoopType, autoIncrementId?: boolean, diff --git a/src/data-structures/types/avl-tree.ts b/src/data-structures/types/avl-tree.ts index 444be2b..3fd4dc8 100644 --- a/src/data-structures/types/avl-tree.ts +++ b/src/data-structures/types/avl-tree.ts @@ -1,5 +1,5 @@ import {AVLTreeNode} from '../binary-tree'; import {BSTOptions} from './bst'; -export type RecursiveAVLTreeNode = AVLTreeNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +export type AVLTreeNodeNested = AVLTreeNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> export type AVLTreeOptions = BSTOptions & {}; \ No newline at end of file diff --git a/src/data-structures/types/binary-tree.ts b/src/data-structures/types/binary-tree.ts index 32299d2..d63afe9 100644 --- a/src/data-structures/types/binary-tree.ts +++ b/src/data-structures/types/binary-tree.ts @@ -5,5 +5,5 @@ import {AbstractBinaryTreeOptions} from './abstract-binary-tree'; // export type BinaryTreeDeleted = { deleted: N | null | undefined, needBalanced: N | null }; // export type ResultByProperty> = N['val'] | N | number | BinaryTreeNodeId; // export type ResultsByProperty> = ResultByProperty[]; -export type RecursiveBinaryTreeNode = BinaryTreeNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +export type BinaryTreeNodeNested = BinaryTreeNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> export type BinaryTreeOptions = AbstractBinaryTreeOptions & {} \ No newline at end of file diff --git a/src/data-structures/types/bst.ts b/src/data-structures/types/bst.ts index da8cfb0..df3ee8d 100644 --- a/src/data-structures/types/bst.ts +++ b/src/data-structures/types/bst.ts @@ -4,7 +4,7 @@ import {BinaryTreeNodeId} from './abstract-binary-tree'; export type BSTComparator = (a: BinaryTreeNodeId, b: BinaryTreeNodeId) => number; -export type RecursiveBSTNode = BSTNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +export type BSTNodeNested = BSTNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> export type BSTOptions = BinaryTreeOptions & { comparator?: BSTComparator, } diff --git a/src/data-structures/types/rb-tree.ts b/src/data-structures/types/rb-tree.ts index a2916db..35a7b91 100644 --- a/src/data-structures/types/rb-tree.ts +++ b/src/data-structures/types/rb-tree.ts @@ -1,5 +1,8 @@ import {BinaryTreeOptions} from './binary-tree'; +import {RBTreeNode} from '../binary-tree'; export enum RBColor { RED = 'RED', BLACK = 'BLACK'} +export type RBTreeNodeNested = RBTreeNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + export type RBTreeOptions = BinaryTreeOptions & {} \ No newline at end of file diff --git a/src/data-structures/types/tree-multiset.ts b/src/data-structures/types/tree-multiset.ts index 762a91e..3b7fa60 100644 --- a/src/data-structures/types/tree-multiset.ts +++ b/src/data-structures/types/tree-multiset.ts @@ -1,8 +1,8 @@ -import {BSTOptions} from './bst'; import {TreeMultiSetNode} from '../binary-tree'; +import {AVLTreeOptions} from './avl-tree'; -export type RecursiveTreeMultiSetNode = TreeMultiSetNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +export type TreeMultiSetNodeNested = TreeMultiSetNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -export type TreeMultiSetOptions = Omit & { +export type TreeMultiSetOptions = Omit & { isDuplicatedVal: true, }