Skip to content

Commit

Permalink
fix: #110
Browse files Browse the repository at this point in the history
  • Loading branch information
zrwusa committed Oct 31, 2024
1 parent 761c1c6 commit 0a8b926
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/data-structures/binary-tree/avl-tree-multi-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ export class AVLTreeMultiMap<
*
* The function overrides the delete method in a binary tree data structure, handling deletion of
* nodes and maintaining balance in the tree.
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
* parameter in the `delete` method is used to specify the condition for deleting a node from the
* binary tree. It can be a key, node, entry, or a custom predicate function that determines which
* binary tree. It can be a key, node, or entry that determines which
* node(s) should be deleted.
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
* boolean flag that determines whether to ignore the count of the node being deleted. If
Expand All @@ -246,13 +246,13 @@ export class AVLTreeMultiMap<
* deleted node and whether balancing is needed in the tree.
*/
override delete(
predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>,
keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
ignoreCount = false
): BinaryTreeDeleteResult<NODE>[] {
const deletedResult: BinaryTreeDeleteResult<NODE>[] = [];
if (!this.root) return deletedResult;

const curr: NODE | undefined = this.getNode(predicate) ?? undefined;
const curr: NODE | undefined = this.getNode(keyOrNodeOrEntryOrRaw) ?? undefined;
if (!curr) return deletedResult;

const parent: NODE | undefined = curr?.parent ? curr.parent : undefined;
Expand Down
6 changes: 3 additions & 3 deletions src/data-structures/binary-tree/avl-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ export class AVLTree<
*
* The function overrides the delete method in a TypeScript class, performs deletion, and then
* balances the tree if necessary.
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
* parameter in the `override delete` method can be one of the following types:
* @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
* method from the superclass (presumably a parent class) with the provided `predicate`, which could
* be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
* `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
*/
override delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[] {
const deletedResults = super.delete(predicate);
override delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[] {
const deletedResults = super.delete(keyOrNodeOrEntryOrRaw);
for (const { needBalanced } of deletedResults) {
if (needBalanced) {
this._balancePath(needBalanced);
Expand Down
10 changes: 4 additions & 6 deletions src/data-structures/binary-tree/binary-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,22 +515,20 @@ export class BinaryTree<
*
* The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
* the deleted node along with information for tree balancing.
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRawOr
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw
* - The `delete` method you provided is used to delete a node from a binary tree based on the key,
* node, entry, raw data, or a custom predicate. The method returns an array of
* node, entry or raw data. The method returns an array of
* `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
* balancing is needed.
* @returns The `delete` method returns an array of `BinaryTreeDeleteResult` objects. Each object in
* the array contains information about the node that was deleted (`deleted`) and the node that may
* need to be balanced (`needBalanced`).
*/
delete(
keyOrNodeOrEntryOrRawOr: BTNKeyOrNodeOrEntry<K, V, NODE> | R
): BinaryTreeDeleteResult<NODE>[] {
delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[] {
const deletedResult: BinaryTreeDeleteResult<NODE>[] = [];
if (!this._root) return deletedResult;

const curr = this.getNode(keyOrNodeOrEntryOrRawOr);
const curr = this.getNode(keyOrNodeOrEntryOrRaw);
if (!curr) return deletedResult;

const parent: NODE | undefined = curr?.parent;
Expand Down
13 changes: 8 additions & 5 deletions src/data-structures/binary-tree/rb-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,24 @@ export class RedBlackTree<
*
* The function overrides the delete method in a binary tree data structure to remove a node based on
* a given predicate and maintain the binary search tree properties.
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
* parameter in the `override delete` method is used to specify the condition or key based on which a
* node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
* function that determines which node(s) should be deleted.
* @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<NODE>`
* objects. Each object in the array contains information about the deleted node and whether
* balancing is needed.
*/
override delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[] {
if (predicate === null) return [];
override delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[] {
if (keyOrNodeOrEntryOrRaw === null) return [];

const results: BinaryTreeDeleteResult<NODE>[] = [];
let nodeToDelete: OptBSTN<NODE>;
if (this._isPredicated(predicate)) nodeToDelete = this.getNode(predicate);
else nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
if (this._isPredicated(keyOrNodeOrEntryOrRaw)) nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw);
else
nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw)
? keyOrNodeOrEntryOrRaw
: this.getNode(keyOrNodeOrEntryOrRaw);

if (!nodeToDelete) {
return results;
Expand Down
16 changes: 9 additions & 7 deletions src/data-structures/binary-tree/tree-multi-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,27 +232,29 @@ export class TreeMultiMap<
*
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
* structure, handling cases where nodes have children and maintaining balance in the tree.
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
* parameter in the `delete` method is used to specify the condition or key based on which a node
* should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
* function.
* should be deleted from the binary tree. It can be a key, a node, or an entry.
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
* boolean flag that determines whether to ignore the count of nodes when performing deletion. If
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
* `ignoreCount` is `false
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
*/
override delete(
predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>,
keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
ignoreCount = false
): BinaryTreeDeleteResult<NODE>[] {
if (predicate === null) return [];
if (keyOrNodeOrEntryOrRaw === null) return [];

const results: BinaryTreeDeleteResult<NODE>[] = [];

let nodeToDelete: OptBSTN<NODE>;
if (this._isPredicated(predicate)) nodeToDelete = this.getNode(predicate);
else nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
if (this._isPredicated(keyOrNodeOrEntryOrRaw)) nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw);
else
nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw)
? keyOrNodeOrEntryOrRaw
: this.getNode(keyOrNodeOrEntryOrRaw);

if (!nodeToDelete) {
return results;
Expand Down

0 comments on commit 0a8b926

Please sign in to comment.