undirected-graph-typed
Advanced tools
Comparing version 1.50.6 to 1.50.7
@@ -49,2 +49,3 @@ /** | ||
get count(): number; | ||
getMutableCount(): number; | ||
/** | ||
@@ -51,0 +52,0 @@ * The function creates a new BSTNode with the given key, value, and count. |
@@ -56,2 +56,5 @@ "use strict"; | ||
get count() { | ||
return this._count; | ||
} | ||
getMutableCount() { | ||
let sum = 0; | ||
@@ -58,0 +61,0 @@ this.dfs(node => (sum += node.count)); |
@@ -365,3 +365,3 @@ "use strict"; | ||
getNodeByKey(key, iterationType = types_1.IterationType.ITERATIVE) { | ||
if (!this.root) | ||
if (!this.isRealNode(this.root)) | ||
return undefined; | ||
@@ -372,7 +372,7 @@ if (iterationType === types_1.IterationType.RECURSIVE) { | ||
return cur; | ||
if (!cur.left && !cur.right) | ||
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right)) | ||
return; | ||
if (this._compare(cur.key, key) === types_1.CP.gt && cur.left) | ||
if (this._compare(cur.key, key) === types_1.CP.gt && this.isRealNode(cur.left)) | ||
return _dfs(cur.left); | ||
if (this._compare(cur.key, key) === types_1.CP.lt && cur.right) | ||
if (this._compare(cur.key, key) === types_1.CP.lt && this.isRealNode(cur.right)) | ||
return _dfs(cur.right); | ||
@@ -386,9 +386,9 @@ }; | ||
const cur = queue.shift(); | ||
if (cur) { | ||
if (this.isRealNode(cur)) { | ||
if (this._compare(cur.key, key) === types_1.CP.eq) | ||
return cur; | ||
if (this._compare(cur.key, key) === types_1.CP.gt) | ||
cur.left && queue.push(cur.left); | ||
this.isRealNode(cur.left) && queue.push(cur.left); | ||
if (this._compare(cur.key, key) === types_1.CP.lt) | ||
cur.right && queue.push(cur.right); | ||
this.isRealNode(cur.right) && queue.push(cur.right); | ||
} | ||
@@ -439,3 +439,3 @@ } | ||
} | ||
if (!cur.left && !cur.right) | ||
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right)) | ||
return; | ||
@@ -445,9 +445,9 @@ // TODO potential bug | ||
if (this._compare(cur.key, identifier) === types_1.CP.gt) | ||
cur.left && _traverse(cur.left); | ||
this.isRealNode(cur.left) && _traverse(cur.left); | ||
if (this._compare(cur.key, identifier) === types_1.CP.lt) | ||
cur.right && _traverse(cur.right); | ||
this.isRealNode(cur.right) && _traverse(cur.right); | ||
} | ||
else { | ||
cur.left && _traverse(cur.left); | ||
cur.right && _traverse(cur.right); | ||
this.isRealNode(cur.left) && _traverse(cur.left); | ||
this.isRealNode(cur.right) && _traverse(cur.right); | ||
} | ||
@@ -461,3 +461,3 @@ }; | ||
const cur = queue.shift(); | ||
if (cur) { | ||
if (this.isRealNode(cur)) { | ||
const callbackResult = callback(cur); | ||
@@ -472,9 +472,9 @@ if (callbackResult === identifier) { | ||
if (this._compare(cur.key, identifier) === types_1.CP.gt) | ||
cur.left && queue.push(cur.left); | ||
this.isRealNode(cur.left) && queue.push(cur.left); | ||
if (this._compare(cur.key, identifier) === types_1.CP.lt) | ||
cur.right && queue.push(cur.right); | ||
this.isRealNode(cur.right) && queue.push(cur.right); | ||
} | ||
else { | ||
cur.left && queue.push(cur.left); | ||
cur.right && queue.push(cur.right); | ||
this.isRealNode(cur.left) && queue.push(cur.left); | ||
this.isRealNode(cur.right) && queue.push(cur.right); | ||
} | ||
@@ -481,0 +481,0 @@ } |
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types'; | ||
import { RBTNColor } from '../../types'; | ||
import { CRUD, RBTNColor } from '../../types'; | ||
import { BST, BSTNode } from './bst'; | ||
@@ -54,9 +54,3 @@ import { IBinaryTree } from '../../interfaces'; | ||
get root(): NODE | undefined; | ||
protected _size: number; | ||
/** | ||
* The function returns the size of an object. | ||
* @returns The size of the object, which is a number. | ||
*/ | ||
get size(): number; | ||
/** | ||
* The function creates a new Red-Black Tree node with the specified key, value, and color. | ||
@@ -240,3 +234,3 @@ * @param {K} key - The key parameter represents the key of the node being created. It is of type K, | ||
*/ | ||
protected _insert(node: NODE): 'inserted' | 'updated'; | ||
protected _insert(node: NODE): CRUD; | ||
/** | ||
@@ -243,0 +237,0 @@ * Time Complexity: O(1) |
@@ -52,3 +52,2 @@ "use strict"; | ||
this._SENTINEL = new RedBlackTreeNode(NaN); | ||
this._size = 0; | ||
this._root = this.SENTINEL; | ||
@@ -74,9 +73,2 @@ if (keysOrNodesOrEntries) { | ||
/** | ||
* The function returns the size of an object. | ||
* @returns The size of the object, which is a number. | ||
*/ | ||
get size() { | ||
return this._size; | ||
} | ||
/** | ||
* The function creates a new Red-Black Tree node with the specified key, value, and color. | ||
@@ -175,3 +167,3 @@ * @param {K} key - The key parameter represents the key of the node being created. It is of type K, | ||
isRealNode(node) { | ||
if (node === this._SENTINEL || node === undefined) | ||
if (node === this.SENTINEL || node === undefined) | ||
return false; | ||
@@ -209,4 +201,3 @@ return node instanceof RedBlackTreeNode; | ||
callback = (node => node); | ||
beginRoot = this.ensureNode(beginRoot); | ||
return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : undefined; | ||
return (_a = super.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : undefined; | ||
} | ||
@@ -225,4 +216,4 @@ /** | ||
clear() { | ||
super.clear(); | ||
this._root = this.SENTINEL; | ||
this._size = 0; | ||
} | ||
@@ -251,3 +242,3 @@ /** | ||
const insertStatus = this._insert(newNode); | ||
if (insertStatus === 'inserted') { | ||
if (insertStatus === types_1.CRUD.CREATED) { | ||
// Ensure the root is black | ||
@@ -264,3 +255,3 @@ if (this.isRealNode(this._root)) { | ||
else | ||
return insertStatus === 'updated'; | ||
return insertStatus === types_1.CRUD.UPDATED; | ||
} | ||
@@ -398,3 +389,3 @@ /** | ||
this._replaceNode(current, node); | ||
return 'updated'; | ||
return types_1.CRUD.UPDATED; | ||
} | ||
@@ -416,3 +407,3 @@ } | ||
this._insertFixup(node); | ||
return 'inserted'; | ||
return types_1.CRUD.CREATED; | ||
} | ||
@@ -419,0 +410,0 @@ /** |
@@ -55,1 +55,7 @@ export declare enum BSTVariant { | ||
}; | ||
export declare enum CRUD { | ||
CREATED = "CREATED", | ||
READ = "READ", | ||
UPDATED = "UPDATED", | ||
DELETED = "DELETED" | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FamilyPosition = exports.IterationType = exports.CP = exports.BSTVariant = void 0; | ||
exports.CRUD = exports.FamilyPosition = exports.IterationType = exports.CP = exports.BSTVariant = void 0; | ||
var BSTVariant; | ||
@@ -36,1 +36,8 @@ (function (BSTVariant) { | ||
})(FamilyPosition = exports.FamilyPosition || (exports.FamilyPosition = {})); | ||
var CRUD; | ||
(function (CRUD) { | ||
CRUD["CREATED"] = "CREATED"; | ||
CRUD["READ"] = "READ"; | ||
CRUD["UPDATED"] = "UPDATED"; | ||
CRUD["DELETED"] = "DELETED"; | ||
})(CRUD = exports.CRUD || (exports.CRUD = {})); |
{ | ||
"name": "undirected-graph-typed", | ||
"version": "1.50.6", | ||
"version": "1.50.7", | ||
"description": "Undirected Graph. Javascript & Typescript Data Structure.", | ||
@@ -148,4 +148,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"data-structure-typed": "^1.50.6" | ||
"data-structure-typed": "^1.50.7" | ||
} | ||
} |
@@ -86,2 +86,6 @@ /** | ||
get count(): number { | ||
return this._count; | ||
} | ||
getMutableCount(): number { | ||
let sum = 0; | ||
@@ -418,3 +422,3 @@ this.dfs(node => (sum += node.count)); | ||
*/ | ||
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE { | ||
protected override _replaceNode(oldNode: NODE, newNode: NODE): NODE { | ||
newNode.count = oldNode.count + newNode.count; | ||
@@ -421,0 +425,0 @@ return super._replaceNode(oldNode, newNode); |
@@ -525,3 +525,3 @@ /** | ||
*/ | ||
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE { | ||
protected override _replaceNode(oldNode: NODE, newNode: NODE): NODE { | ||
newNode.height = oldNode.height; | ||
@@ -528,0 +528,0 @@ |
@@ -429,10 +429,10 @@ /** | ||
override getNodeByKey(key: K, iterationType = IterationType.ITERATIVE): NODE | undefined { | ||
if (!this.root) return undefined; | ||
if (!this.isRealNode(this.root)) return undefined; | ||
if (iterationType === IterationType.RECURSIVE) { | ||
const _dfs = (cur: NODE): NODE | undefined => { | ||
if (cur.key === key) return cur; | ||
if (!cur.left && !cur.right) return; | ||
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right)) return; | ||
if (this._compare(cur.key, key) === CP.gt && cur.left) return _dfs(cur.left); | ||
if (this._compare(cur.key, key) === CP.lt && cur.right) return _dfs(cur.right); | ||
if (this._compare(cur.key, key) === CP.gt && this.isRealNode(cur.left)) return _dfs(cur.left); | ||
if (this._compare(cur.key, key) === CP.lt && this.isRealNode(cur.right)) return _dfs(cur.right); | ||
}; | ||
@@ -445,6 +445,6 @@ | ||
const cur = queue.shift(); | ||
if (cur) { | ||
if (this.isRealNode(cur)) { | ||
if (this._compare(cur.key, key) === CP.eq) return cur; | ||
if (this._compare(cur.key, key) === CP.gt) cur.left && queue.push(cur.left); | ||
if (this._compare(cur.key, key) === CP.lt) cur.right && queue.push(cur.right); | ||
if (this._compare(cur.key, key) === CP.gt) this.isRealNode(cur.left) && queue.push(cur.left); | ||
if (this._compare(cur.key, key) === CP.lt) this.isRealNode(cur.right) && queue.push(cur.right); | ||
} | ||
@@ -502,10 +502,10 @@ } | ||
if (!cur.left && !cur.right) return; | ||
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right)) return; | ||
// TODO potential bug | ||
if (callback === this._defaultOneParamCallback) { | ||
if (this._compare(cur.key, identifier as K) === CP.gt) cur.left && _traverse(cur.left); | ||
if (this._compare(cur.key, identifier as K) === CP.lt) cur.right && _traverse(cur.right); | ||
if (this._compare(cur.key, identifier as K) === CP.gt) this.isRealNode(cur.left) && _traverse(cur.left); | ||
if (this._compare(cur.key, identifier as K) === CP.lt) this.isRealNode(cur.right) && _traverse(cur.right); | ||
} else { | ||
cur.left && _traverse(cur.left); | ||
cur.right && _traverse(cur.right); | ||
this.isRealNode(cur.left) && _traverse(cur.left); | ||
this.isRealNode(cur.right) && _traverse(cur.right); | ||
} | ||
@@ -519,3 +519,3 @@ }; | ||
const cur = queue.shift(); | ||
if (cur) { | ||
if (this.isRealNode(cur)) { | ||
const callbackResult = callback(cur); | ||
@@ -528,7 +528,7 @@ if (callbackResult === identifier) { | ||
if (callback === this._defaultOneParamCallback) { | ||
if (this._compare(cur.key, identifier as K) === CP.gt) cur.left && queue.push(cur.left); | ||
if (this._compare(cur.key, identifier as K) === CP.lt) cur.right && queue.push(cur.right); | ||
if (this._compare(cur.key, identifier as K) === CP.gt) this.isRealNode(cur.left) && queue.push(cur.left); | ||
if (this._compare(cur.key, identifier as K) === CP.lt) this.isRealNode(cur.right) && queue.push(cur.right); | ||
} else { | ||
cur.left && queue.push(cur.left); | ||
cur.right && queue.push(cur.right); | ||
this.isRealNode(cur.left) && queue.push(cur.left); | ||
this.isRealNode(cur.right) && queue.push(cur.right); | ||
} | ||
@@ -864,3 +864,3 @@ } | ||
*/ | ||
protected _setRoot(v: NODE | undefined) { | ||
protected override _setRoot(v: NODE | undefined) { | ||
if (v) { | ||
@@ -867,0 +867,0 @@ v.parent = undefined; |
@@ -10,3 +10,3 @@ import type { | ||
} from '../../types'; | ||
import { RBTNColor } from '../../types'; | ||
import { CRUD, RBTNColor } from '../../types'; | ||
import { BST, BSTNode } from './bst'; | ||
@@ -93,3 +93,3 @@ import { IBinaryTree } from '../../interfaces'; | ||
protected _root: NODE | undefined; | ||
protected override _root: NODE | undefined; | ||
@@ -100,17 +100,7 @@ /** | ||
*/ | ||
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. | ||
@@ -214,3 +204,3 @@ * @param {K} key - The key parameter represents the key of the node being created. It is of type K, | ||
override isRealNode(node: NODE | undefined): node is NODE { | ||
if (node === this._SENTINEL || node === undefined) return false; | ||
if (node === this.SENTINEL || node === undefined) return false; | ||
return node instanceof RedBlackTreeNode; | ||
@@ -252,4 +242,3 @@ } | ||
if ((identifier as any) instanceof RedBlackTreeNode) callback = (node => node) as C; | ||
beginRoot = this.ensureNode(beginRoot); | ||
return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined; | ||
return super.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined; | ||
} | ||
@@ -270,4 +259,4 @@ | ||
override clear() { | ||
super.clear(); | ||
this._root = this.SENTINEL; | ||
this._size = 0; | ||
} | ||
@@ -299,3 +288,3 @@ | ||
if (insertStatus === 'inserted') { | ||
if (insertStatus === CRUD.CREATED) { | ||
// Ensure the root is black | ||
@@ -309,3 +298,3 @@ if (this.isRealNode(this._root)) { | ||
return true; | ||
} else return insertStatus === 'updated'; | ||
} else return insertStatus === CRUD.UPDATED; | ||
} | ||
@@ -445,3 +434,3 @@ | ||
*/ | ||
protected _insert(node: NODE): 'inserted' | 'updated' { | ||
protected _insert(node: NODE): CRUD { | ||
let current = this.root; | ||
@@ -458,3 +447,3 @@ let parent: NODE | undefined = undefined; | ||
this._replaceNode(current, node); | ||
return 'updated'; | ||
return CRUD.UPDATED; | ||
} | ||
@@ -478,3 +467,3 @@ } | ||
this._insertFixup(node); | ||
return 'inserted'; | ||
return CRUD.CREATED; | ||
} | ||
@@ -481,0 +470,0 @@ |
@@ -66,1 +66,8 @@ export enum BSTVariant { | ||
export type BinaryTreeDeleteResult<N> = { deleted: N | null | undefined; needBalanced: N | null | undefined }; | ||
export enum CRUD { | ||
CREATED = 'CREATED', | ||
READ = 'READ', | ||
UPDATED = 'UPDATED', | ||
DELETED = 'DELETED' | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2037859
40185
Updateddata-structure-typed@^1.50.7