diff --git a/src/data-structures/binary-tree/avl-tree-multi-map.ts b/src/data-structures/binary-tree/avl-tree-multi-map.ts index 07bec46..ce63d90 100644 --- a/src/data-structures/binary-tree/avl-tree-multi-map.ts +++ b/src/data-structures/binary-tree/avl-tree-multi-map.ts @@ -83,6 +83,10 @@ export class AVLTreeMultiMap< * @returns the sum of the count property of all nodes in the tree. */ get count(): number { + return this._count; + } + + getMutableCount(): number { let sum = 0; this.dfs(node => (sum += node.count)); return sum; @@ -414,7 +418,7 @@ export class AVLTreeMultiMap< * @returns The method is returning the result of calling the `_replaceNode` method from the * superclass, after updating the `count` property of the `newNode` object. */ - protected _replaceNode(oldNode: NODE, newNode: NODE): NODE { + protected override _replaceNode(oldNode: NODE, newNode: NODE): NODE { newNode.count = oldNode.count + newNode.count; return super._replaceNode(oldNode, newNode); } diff --git a/src/data-structures/binary-tree/avl-tree.ts b/src/data-structures/binary-tree/avl-tree.ts index 2737cd3..b8e5074 100644 --- a/src/data-structures/binary-tree/avl-tree.ts +++ b/src/data-structures/binary-tree/avl-tree.ts @@ -522,7 +522,7 @@ export class AVLTree< * @returns the result of calling the `_replaceNode` method on the superclass, passing in the * `oldNode` and `newNode` as arguments. */ - protected _replaceNode(oldNode: NODE, newNode: NODE): NODE { + protected override _replaceNode(oldNode: NODE, newNode: NODE): NODE { newNode.height = oldNode.height; return super._replaceNode(oldNode, newNode); diff --git a/src/data-structures/binary-tree/binary-tree.ts b/src/data-structures/binary-tree/binary-tree.ts index 54441ef..f6fa66b 100644 --- a/src/data-structures/binary-tree/binary-tree.ts +++ b/src/data-structures/binary-tree/binary-tree.ts @@ -1837,7 +1837,7 @@ export class BinaryTree< * following types: * @param {BinaryTreePrintOptions} [options={ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false}] - Options object that controls printing behavior. You can specify whether to display undefined, null, or sentinel nodes. */ - print(beginRoot: KeyOrNodeOrEntry = this.root, options?: BinaryTreePrintOptions): void { + override print(beginRoot: KeyOrNodeOrEntry = this.root, options?: BinaryTreePrintOptions): void { const opts = { isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false, ...options }; beginRoot = this.ensureNode(beginRoot); if (!beginRoot) return; diff --git a/src/data-structures/binary-tree/bst.ts b/src/data-structures/binary-tree/bst.ts index d8366f1..73448b2 100644 --- a/src/data-structures/binary-tree/bst.ts +++ b/src/data-structures/binary-tree/bst.ts @@ -856,7 +856,7 @@ export class BST< * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. This means that it * can either be an object of type `NODE` or it can be `undefined`. */ - protected _setRoot(v: NODE | undefined) { + protected override _setRoot(v: NODE | undefined) { if (v) { v.parent = undefined; } diff --git a/src/data-structures/binary-tree/rb-tree.ts b/src/data-structures/binary-tree/rb-tree.ts index bfb958f..479193a 100644 --- a/src/data-structures/binary-tree/rb-tree.ts +++ b/src/data-structures/binary-tree/rb-tree.ts @@ -89,26 +89,16 @@ export class RedBlackTree< return this._SENTINEL; } - protected _root: NODE | undefined; + protected override _root: NODE | undefined; /** * The function returns the root node of a tree or undefined if there is no root. * @returns The root node of the tree structure, or undefined if there is no root node. */ - get root(): NODE | undefined { + override get root(): NODE | undefined { return this._root; } - protected _size: number = 0; - - /** - * The function returns the size of an object. - * @returns The size of the object, which is a number. - */ - get size(): number { - return this._size; - } - /** * The function creates a new Red-Black Tree node with the specified key, value, and color. * @param {K} key - The key parameter represents the key of the node being created. It is of type K, @@ -262,8 +252,8 @@ export class RedBlackTree< * size counter to zero. */ override clear() { + super.clear(); this._root = this.SENTINEL; - this._size = 0; } /** diff --git a/src/types/common.ts b/src/types/common.ts index 79a4e90..fce4da0 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -69,4 +69,4 @@ export enum CRUD { READ = 'READ', UPDATED = 'UPDATED', DELETED = 'DELETED' -} \ No newline at end of file +} diff --git a/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts b/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts index d49a28b..ec3165f 100644 --- a/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +++ b/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts @@ -35,8 +35,11 @@ describe('AVLTreeMultiMap count', () => { [2, 2], [3, 3] ]); + tm.add([2, 2], undefined, 10) tm.lesserOrGreaterTraverse(node => (node.count += 2), CP.gt, 1); - expect(tm.count).toBe(7); + tm.delete(2); + expect(tm.count).toBe(12); + expect(tm.getMutableCount()).toBe(16); }); });