mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-14 01:24:03 +00:00
fix: #110
This commit is contained in:
parent
761c1c6af4
commit
0a8b9265cc
|
@ -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
|
||||
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -230,7 +230,7 @@ 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.
|
||||
|
@ -238,13 +238,16 @@ export class RedBlackTree<
|
|||
* 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;
|
||||
|
|
|
@ -232,10 +232,9 @@ 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
|
||||
|
@ -243,16 +242,19 @@ export class TreeMultiMap<
|
|||
* @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;
|
||||
|
|
Loading…
Reference in a new issue