Socket
Socket
Sign inDemoInstall

data-structure-typed

Package Overview
Dependencies
Maintainers
1
Versions
201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-structure-typed - npm Package Compare versions

Comparing version 1.34.7 to 1.34.8

scripts/rename_clear_files.sh

2

CHANGELOG.md

@@ -11,3 +11,3 @@ # Changelog

## [v1.34.7](https://github.com/zrwusa/data-structure-typed/compare/v1.34.1...main) (upcoming)
## [v1.34.8](https://github.com/zrwusa/data-structure-typed/compare/v1.34.1...main) (upcoming)

@@ -14,0 +14,0 @@ ## [v1.34.1](https://github.com/zrwusa/data-structure-typed/compare/v1.33.4...v1.34.1) (6 October 2023)

@@ -23,13 +23,13 @@ "use strict";

var AbstractBinaryTreeNode = (function () {
function AbstractBinaryTreeNode(id, val) {
function AbstractBinaryTreeNode(key, val) {
this._height = 0;
this._id = id;
this._key = key;
this._val = val;
}
Object.defineProperty(AbstractBinaryTreeNode.prototype, "id", {
Object.defineProperty(AbstractBinaryTreeNode.prototype, "key", {
get: function () {
return this._id;
return this._key;
},
set: function (v) {
this._id = v;
this._key = v;
},

@@ -139,3 +139,3 @@ enumerable: false,

this._loopType = types_1.LoopType.ITERATIVE;
this._visitedId = [];
this._visitedKey = [];
this._visitedVal = [];

@@ -170,5 +170,5 @@ this._visitedNode = [];

});
Object.defineProperty(AbstractBinaryTree.prototype, "visitedId", {
Object.defineProperty(AbstractBinaryTree.prototype, "visitedKey", {
get: function () {
return this._visitedId;
return this._visitedKey;
},

@@ -193,10 +193,10 @@ enumerable: false,

AbstractBinaryTree.prototype.swapLocation = function (srcNode, destNode) {
var id = destNode.id, val = destNode.val, height = destNode.height;
var tempNode = this.createNode(id, val);
var key = destNode.key, val = destNode.val, height = destNode.height;
var tempNode = this.createNode(key, val);
if (tempNode) {
tempNode.height = height;
destNode.id = srcNode.id;
destNode.key = srcNode.key;
destNode.val = srcNode.val;
destNode.height = srcNode.height;
srcNode.id = tempNode.id;
srcNode.key = tempNode.key;
srcNode.val = tempNode.val;

@@ -215,3 +215,3 @@ srcNode.height = tempNode.height;

};
AbstractBinaryTree.prototype.add = function (idOrNode, val) {
AbstractBinaryTree.prototype.add = function (keyOrNode, val) {
var _this = this;

@@ -223,3 +223,3 @@ var _bfs = function (root, newNode) {

if (cur) {
if (newNode && cur.id === newNode.id)
if (newNode && cur.key === newNode.key)
return;

@@ -240,10 +240,10 @@ var inserted_1 = _this._addTo(newNode, cur);

var inserted, needInsert;
if (idOrNode === null) {
if (keyOrNode === null) {
needInsert = null;
}
else if (typeof idOrNode === 'number') {
needInsert = this.createNode(idOrNode, val);
else if (typeof keyOrNode === 'number') {
needInsert = this.createNode(keyOrNode, val);
}
else if (idOrNode instanceof AbstractBinaryTreeNode) {
needInsert = idOrNode;
else if (keyOrNode instanceof AbstractBinaryTreeNode) {
needInsert = keyOrNode;
}

@@ -253,3 +253,3 @@ else {

}
var existNode = idOrNode ? this.get(idOrNode, 'id') : undefined;
var existNode = keyOrNode ? this.get(keyOrNode, 'key') : undefined;
if (this.root) {

@@ -279,8 +279,8 @@ if (existNode) {

for (var i = 0; i < idsOrNodes.length; i++) {
var idOrNode = idsOrNodes[i];
if (idOrNode instanceof AbstractBinaryTreeNode) {
inserted.push(this.add(idOrNode.id, idOrNode.val));
var keyOrNode = idsOrNodes[i];
if (keyOrNode instanceof AbstractBinaryTreeNode) {
inserted.push(this.add(keyOrNode.key, keyOrNode.val));
continue;
}
if (idOrNode === null) {
if (keyOrNode === null) {
inserted.push(this.add(null));

@@ -290,3 +290,3 @@ continue;

var val = data === null || data === void 0 ? void 0 : data[i];
inserted.push(this.add(idOrNode, val));
inserted.push(this.add(keyOrNode, val));
}

@@ -299,7 +299,7 @@ return inserted;

};
AbstractBinaryTree.prototype.remove = function (nodeOrId) {
AbstractBinaryTree.prototype.remove = function (nodeOrKey) {
var bstDeletedResult = [];
if (!this.root)
return bstDeletedResult;
var curr = typeof nodeOrId === 'number' ? this.get(nodeOrId) : nodeOrId;
var curr = typeof nodeOrKey === 'number' ? this.get(nodeOrKey) : nodeOrKey;
if (!curr)

@@ -345,3 +345,3 @@ return bstDeletedResult;

if (typeof beginRoot === 'number')
beginRoot = this.get(beginRoot, 'id');
beginRoot = this.get(beginRoot, 'key');
var depth = 0;

@@ -357,3 +357,3 @@ while (beginRoot === null || beginRoot === void 0 ? void 0 : beginRoot.parent) {

if (typeof beginRoot === 'number')
beginRoot = this.get(beginRoot, 'id');
beginRoot = this.get(beginRoot, 'key');
if (!beginRoot)

@@ -442,3 +442,3 @@ return -1;

return [];
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
var result = [];

@@ -471,3 +471,3 @@ if (this.loopType === types_1.LoopType.RECURSIVE) {

AbstractBinaryTree.prototype.has = function (nodeProperty, propertyName) {
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
return this.getNodes(nodeProperty, propertyName).length > 0;

@@ -477,3 +477,3 @@ };

var _a;
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;

@@ -493,3 +493,3 @@ };

if (typeof beginRoot === 'number')
beginRoot = this.get(beginRoot, 'id');
beginRoot = this.get(beginRoot, 'key');
beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;

@@ -543,5 +543,5 @@ if (!beginRoot)

return true;
if (cur.id <= min || cur.id >= max)
if (cur.key <= min || cur.key >= max)
return false;
return dfs_1(cur.left, min, cur.id) && dfs_1(cur.right, cur.id, max);
return dfs_1(cur.left, min, cur.key) && dfs_1(cur.right, cur.key, max);
};

@@ -559,5 +559,5 @@ return dfs_1(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);

curr = stack.pop();
if (!curr || prev >= curr.id)
if (!curr || prev >= curr.key)
return false;
prev = curr.id;
prev = curr.key;
curr = curr.right;

@@ -596,5 +596,5 @@ }

AbstractBinaryTree.prototype.subTreeSum = function (subTreeRoot, propertyName) {
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
if (typeof subTreeRoot === 'number')
subTreeRoot = this.get(subTreeRoot, 'id');
subTreeRoot = this.get(subTreeRoot, 'key');
if (!subTreeRoot)

@@ -606,4 +606,4 @@ return 0;

switch (propertyName) {
case 'id':
needSum = cur.id;
case 'key':
needSum = cur.key;
break;

@@ -614,3 +614,3 @@ case 'val':

default:
needSum = cur.id;
needSum = cur.key;
break;

@@ -640,5 +640,5 @@ }

AbstractBinaryTree.prototype.subTreeAdd = function (subTreeRoot, delta, propertyName) {
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
if (typeof subTreeRoot === 'number')
subTreeRoot = this.get(subTreeRoot, 'id');
subTreeRoot = this.get(subTreeRoot, 'key');
if (!subTreeRoot)

@@ -648,7 +648,7 @@ return false;

switch (propertyName) {
case 'id':
cur.id += delta;
case 'key':
cur.key += delta;
break;
default:
cur.id += delta;
cur.key += delta;
break;

@@ -677,3 +677,3 @@ }

AbstractBinaryTree.prototype.BFS = function (nodeOrPropertyName) {
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
this._clearResults();

@@ -696,3 +696,3 @@ var queue = [this.root];

pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
this._clearResults();

@@ -729,3 +729,3 @@ var _traverse = function (node) {

pattern = pattern || 'in';
nodeOrPropertyName = nodeOrPropertyName || 'id';
nodeOrPropertyName = nodeOrPropertyName || 'key';
this._clearResults();

@@ -770,3 +770,3 @@ if (!this.root)

AbstractBinaryTree.prototype.levelIterative = function (node, nodeOrPropertyName) {
nodeOrPropertyName = nodeOrPropertyName || 'id';
nodeOrPropertyName = nodeOrPropertyName || 'key';
node = node || this.root;

@@ -792,3 +792,3 @@ if (!node)

AbstractBinaryTree.prototype.listLevels = function (node, nodeOrPropertyName) {
nodeOrPropertyName = nodeOrPropertyName || 'id';
nodeOrPropertyName = nodeOrPropertyName || 'key';
node = node || this.root;

@@ -800,4 +800,4 @@ if (!node)

switch (nodeOrPropertyName) {
case 'id':
levelsNodes[level].push(node.id);
case 'key':
levelsNodes[level].push(node.key);
break;

@@ -811,3 +811,3 @@ case 'val':

default:
levelsNodes[level].push(node.id);
levelsNodes[level].push(node.key);
break;

@@ -863,3 +863,3 @@ }

pattern = pattern || 'in';
nodeOrPropertyName = nodeOrPropertyName || 'id';
nodeOrPropertyName = nodeOrPropertyName || 'key';
this._clearResults();

@@ -973,4 +973,4 @@ var cur = this.root;

};
AbstractBinaryTree.prototype._setVisitedId = function (value) {
this._visitedId = value;
AbstractBinaryTree.prototype._setVisitedKey = function (value) {
this._visitedKey = value;
};

@@ -993,3 +993,3 @@ AbstractBinaryTree.prototype._setVisitedVal = function (value) {

AbstractBinaryTree.prototype._clearResults = function () {
this._visitedId = [];
this._visitedKey = [];
this._visitedVal = [];

@@ -1000,4 +1000,4 @@ this._visitedNode = [];

switch (propertyName) {
case 'id':
if (cur.id === nodeProperty) {
case 'key':
if (cur.key === nodeProperty) {
result.push(cur);

@@ -1014,3 +1014,3 @@ return !!onlyOne;

default:
if (cur.id === nodeProperty) {
if (cur.key === nodeProperty) {
result.push(cur);

@@ -1023,6 +1023,6 @@ return !!onlyOne;

AbstractBinaryTree.prototype._accumulatedByPropertyName = function (node, nodeOrPropertyName) {
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
switch (nodeOrPropertyName) {
case 'id':
this._visitedId.push(node.id);
case 'key':
this._visitedKey.push(node.key);
break;

@@ -1036,3 +1036,3 @@ case 'val':

default:
this._visitedId.push(node.id);
this._visitedKey.push(node.key);
break;

@@ -1042,6 +1042,6 @@ }

AbstractBinaryTree.prototype._getResultByPropertyName = function (nodeOrPropertyName) {
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
switch (nodeOrPropertyName) {
case 'id':
return this._visitedId;
case 'key':
return this._visitedKey;
case 'val':

@@ -1052,3 +1052,3 @@ return this._visitedVal;

default:
return this._visitedId;
return this._visitedKey;
}

@@ -1055,0 +1055,0 @@ };

@@ -33,4 +33,4 @@ "use strict";

__extends(AVLTreeNode, _super);
function AVLTreeNode(id, val) {
return _super.call(this, id, val) || this;
function AVLTreeNode(key, val) {
return _super.call(this, key, val) || this;
}

@@ -45,7 +45,7 @@ return AVLTreeNode;

}
AVLTree.prototype.createNode = function (id, val) {
return new AVLTreeNode(id, val);
AVLTree.prototype.createNode = function (key, val) {
return new AVLTreeNode(key, val);
};
AVLTree.prototype.add = function (id, val) {
var inserted = _super.prototype.add.call(this, id, val);
AVLTree.prototype.add = function (key, val) {
var inserted = _super.prototype.add.call(this, key, val);
if (inserted)

@@ -55,5 +55,5 @@ this._balancePath(inserted);

};
AVLTree.prototype.remove = function (id) {
AVLTree.prototype.remove = function (key) {
var e_1, _a;
var deletedResults = _super.prototype.remove.call(this, id);
var deletedResults = _super.prototype.remove.call(this, key);
try {

@@ -60,0 +60,0 @@ for (var deletedResults_1 = __values(deletedResults), deletedResults_1_1 = deletedResults_1.next(); !deletedResults_1_1.done; deletedResults_1_1 = deletedResults_1.next()) {

@@ -22,4 +22,4 @@ "use strict";

__extends(BinaryTreeNode, _super);
function BinaryTreeNode(id, val) {
return _super.call(this, id, val) || this;
function BinaryTreeNode(key, val) {
return _super.call(this, key, val) || this;
}

@@ -34,4 +34,4 @@ return BinaryTreeNode;

}
BinaryTree.prototype.createNode = function (id, val) {
return new BinaryTreeNode(id, val);
BinaryTree.prototype.createNode = function (key, val) {
return new BinaryTreeNode(key, val);
};

@@ -38,0 +38,0 @@ return BinaryTree;

@@ -50,4 +50,4 @@ "use strict";

__extends(BSTNode, _super);
function BSTNode(id, val) {
return _super.call(this, id, val) || this;
function BSTNode(key, val) {
return _super.call(this, key, val) || this;
}

@@ -70,15 +70,15 @@ return BSTNode;

}
BST.prototype.createNode = function (id, val) {
return new BSTNode(id, val);
BST.prototype.createNode = function (key, val) {
return new BSTNode(key, val);
};
BST.prototype.add = function (idOrNode, val) {
BST.prototype.add = function (keyOrNode, val) {
var inserted = null;
var newNode = null;
if (idOrNode instanceof BSTNode) {
newNode = idOrNode;
if (keyOrNode instanceof BSTNode) {
newNode = keyOrNode;
}
else if (typeof idOrNode === 'number') {
newNode = this.createNode(idOrNode, val);
else if (typeof keyOrNode === 'number') {
newNode = this.createNode(keyOrNode, val);
}
else if (idOrNode === null) {
else if (keyOrNode === null) {
newNode = null;

@@ -96,3 +96,3 @@ }

if (cur !== null && newNode !== null) {
if (this._compare(cur.id, newNode.id) === types_1.CP.eq) {
if (this._compare(cur.key, newNode.key) === types_1.CP.eq) {
if (newNode) {

@@ -104,3 +104,3 @@ cur.val = newNode.val;

}
else if (this._compare(cur.id, newNode.id) === types_1.CP.gt) {
else if (this._compare(cur.key, newNode.key) === types_1.CP.gt) {
if (cur.left === undefined) {

@@ -120,3 +120,3 @@ if (newNode) {

}
else if (this._compare(cur.id, newNode.id) === types_1.CP.lt) {
else if (this._compare(cur.key, newNode.key) === types_1.CP.lt) {
if (cur.right === undefined) {

@@ -160,4 +160,4 @@ if (newNode) {

for (var arr_1 = __values(arr), arr_1_1 = arr_1.next(); !arr_1_1.done; arr_1_1 = arr_1.next()) {
var _b = __read(arr_1_1.value, 1), idOrNode = _b[0];
if (idOrNode instanceof BSTNode)
var _b = __read(arr_1_1.value, 1), keyOrNode = _b[0];
if (keyOrNode instanceof BSTNode)
return true;

@@ -175,8 +175,8 @@ }

}
function isBinaryTreeIdOrNullTuple(arr) {
function isBinaryTreeKeyOrNullTuple(arr) {
var e_2, _a;
try {
for (var arr_2 = __values(arr), arr_2_1 = arr_2.next(); !arr_2_1.done; arr_2_1 = arr_2.next()) {
var _b = __read(arr_2_1.value, 1), idOrNode = _b[0];
if (typeof idOrNode === 'number')
var _b = __read(arr_2_1.value, 1), keyOrNode = _b[0];
if (typeof keyOrNode === 'number')
return true;

@@ -194,7 +194,7 @@ }

}
var sortedIdsOrNodes = [], sortedData = [];
var sortedKeysOrNodes = [], sortedData = [];
if (isNodeOrNullTuple(combinedArr)) {
sorted = combinedArr.sort(function (a, b) { return a[0].id - b[0].id; });
sorted = combinedArr.sort(function (a, b) { return a[0].key - b[0].key; });
}
else if (isBinaryTreeIdOrNullTuple(combinedArr)) {
else if (isBinaryTreeKeyOrNullTuple(combinedArr)) {
sorted = combinedArr.sort(function (a, b) { return a[0] - b[0]; });

@@ -205,5 +205,5 @@ }

}
sortedIdsOrNodes = sorted.map(function (_a) {
var _b = __read(_a, 1), idOrNode = _b[0];
return idOrNode;
sortedKeysOrNodes = sorted.map(function (_a) {
var _b = __read(_a, 1), keyOrNode = _b[0];
return keyOrNode;
});

@@ -232,3 +232,3 @@ sortedData = sorted.map(function (_a) {

var m = l + Math.floor((r - l) / 2);
var newNode = _this.add(sortedIdsOrNodes[m], sortedData === null || sortedData === void 0 ? void 0 : sortedData[m]);
var newNode = _this.add(sortedKeysOrNodes[m], sortedData === null || sortedData === void 0 ? void 0 : sortedData[m]);
inserted.push(newNode);

@@ -242,3 +242,3 @@ stack.push([m + 1, r]);

if (this.loopType === types_1.LoopType.RECURSIVE) {
recursive(sortedIdsOrNodes, sortedData);
recursive(sortedKeysOrNodes, sortedData);
}

@@ -252,3 +252,3 @@ else {

var _a;
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;

@@ -259,11 +259,11 @@ };

if (this._compare(0, 1) === types_1.CP.lt)
return (_b = (_a = this.getRightMost()) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : 0;
return (_b = (_a = this.getRightMost()) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : 0;
else if (this._compare(0, 1) === types_1.CP.gt)
return (_d = (_c = this.getLeftMost()) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : 0;
return (_d = (_c = this.getLeftMost()) === null || _c === void 0 ? void 0 : _c.key) !== null && _d !== void 0 ? _d : 0;
else
return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : 0;
return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.key) !== null && _f !== void 0 ? _f : 0;
};
BST.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
var _this = this;
if (propertyName === void 0) { propertyName = 'id'; }
if (propertyName === void 0) { propertyName = 'key'; }
if (!this.root)

@@ -278,6 +278,6 @@ return [];

return;
if (propertyName === 'id') {
if (_this._compare(cur.id, nodeProperty) === types_1.CP.gt)
if (propertyName === 'key') {
if (_this._compare(cur.key, nodeProperty) === types_1.CP.gt)
cur.left && _traverse_1(cur.left);
if (_this._compare(cur.id, nodeProperty) === types_1.CP.lt)
if (_this._compare(cur.key, nodeProperty) === types_1.CP.lt)
cur.right && _traverse_1(cur.right);

@@ -299,6 +299,6 @@ }

return result;
if (propertyName === 'id') {
if (this._compare(cur.id, nodeProperty) === types_1.CP.gt)
if (propertyName === 'key') {
if (this._compare(cur.key, nodeProperty) === types_1.CP.gt)
cur.left && queue.push(cur.left);
if (this._compare(cur.id, nodeProperty) === types_1.CP.lt)
if (this._compare(cur.key, nodeProperty) === types_1.CP.lt)
cur.right && queue.push(cur.right);

@@ -317,5 +317,5 @@ }

var _this = this;
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
if (typeof beginNode === 'number')
beginNode = this.get(beginNode, 'id');
beginNode = this.get(beginNode, 'key');
if (!beginNode)

@@ -325,11 +325,11 @@ return 0;

return 0;
var id = beginNode.id;
var key = beginNode.key;
var getSumByPropertyName = function (cur) {
var needSum;
switch (propertyName) {
case 'id':
needSum = cur.id;
case 'key':
needSum = cur.key;
break;
default:
needSum = cur.id;
needSum = cur.key;
break;

@@ -342,3 +342,3 @@ }

var _traverse_2 = function (cur) {
var compared = _this._compare(cur.id, id);
var compared = _this._compare(cur.key, key);
if (compared === types_1.CP.eq) {

@@ -372,3 +372,3 @@ if (cur.right)

if (cur) {
var compared = this._compare(cur.id, id);
var compared = this._compare(cur.key, key);
if (compared === types_1.CP.eq) {

@@ -401,8 +401,8 @@ if (cur.right)

var _this = this;
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
if (typeof node === 'number')
node = this.get(node, 'id');
node = this.get(node, 'key');
if (!node)
return false;
var id = node.id;
var key = node.key;
if (!this.root)

@@ -412,7 +412,7 @@ return false;

switch (propertyName) {
case 'id':
cur.id += delta;
case 'key':
cur.key += delta;
break;
default:
cur.id += delta;
cur.key += delta;
break;

@@ -423,3 +423,3 @@ }

var _traverse_3 = function (cur) {
var compared = _this._compare(cur.id, id);
var compared = _this._compare(cur.key, key);
if (compared === types_1.CP.gt)

@@ -429,5 +429,5 @@ _sumByPropertyName(cur);

return;
if (cur.left && _this._compare(cur.left.id, id) === types_1.CP.gt)
if (cur.left && _this._compare(cur.left.key, key) === types_1.CP.gt)
_traverse_3(cur.left);
if (cur.right && _this._compare(cur.right.id, id) === types_1.CP.gt)
if (cur.right && _this._compare(cur.right.key, key) === types_1.CP.gt)
_traverse_3(cur.right);

@@ -443,8 +443,8 @@ };

if (cur) {
var compared = this._compare(cur.id, id);
var compared = this._compare(cur.key, key);
if (compared === types_1.CP.gt)
_sumByPropertyName(cur);
if (cur.left && this._compare(cur.left.id, id) === types_1.CP.gt)
if (cur.left && this._compare(cur.left.key, key) === types_1.CP.gt)
queue.push(cur.left);
if (cur.right && this._compare(cur.right.id, id) === types_1.CP.gt)
if (cur.right && this._compare(cur.right.key, key) === types_1.CP.gt)
queue.push(cur.right);

@@ -468,3 +468,3 @@ }

var midNode = sorted[m];
_this.add(midNode.id, midNode.val);
_this.add(midNode.key, midNode.val);
buildBalanceBST_1(l, m - 1);

@@ -485,3 +485,3 @@ buildBalanceBST_1(m + 1, r);

var midNode = sorted[m];
this.add(midNode.id, midNode.val);
this.add(midNode.key, midNode.val);
stack.push([m + 1, r]);

@@ -488,0 +488,0 @@ stack.push([l, m - 1]);

@@ -23,4 +23,4 @@ "use strict";

__extends(RBTreeNode, _super);
function RBTreeNode(id, val) {
var _this = _super.call(this, id, val) || this;
function RBTreeNode(key, val) {
var _this = _super.call(this, key, val) || this;
_this._color = types_1.RBColor.RED;

@@ -47,4 +47,4 @@ return _this;

}
RBTree.prototype.createNode = function (id, val) {
return new RBTreeNode(id, val);
RBTree.prototype.createNode = function (key, val) {
return new RBTreeNode(key, val);
};

@@ -51,0 +51,0 @@ return RBTree;

@@ -50,5 +50,5 @@ "use strict";

__extends(TreeMultisetNode, _super);
function TreeMultisetNode(id, val, count) {
function TreeMultisetNode(key, val, count) {
if (count === void 0) { count = 1; }
var _this = _super.call(this, id, val) || this;
var _this = _super.call(this, key, val) || this;
_this._count = count;

@@ -84,15 +84,15 @@ return _this;

});
TreeMultiset.prototype.createNode = function (id, val, count) {
return new TreeMultisetNode(id, val, count);
TreeMultiset.prototype.createNode = function (key, val, count) {
return new TreeMultisetNode(key, val, count);
};
TreeMultiset.prototype.swapLocation = function (srcNode, destNode) {
var id = destNode.id, val = destNode.val, count = destNode.count, height = destNode.height;
var tempNode = this.createNode(id, val, count);
var key = destNode.key, val = destNode.val, count = destNode.count, height = destNode.height;
var tempNode = this.createNode(key, val, count);
if (tempNode) {
tempNode.height = height;
destNode.id = srcNode.id;
destNode.key = srcNode.key;
destNode.val = srcNode.val;
destNode.count = srcNode.count;
destNode.height = srcNode.height;
srcNode.id = tempNode.id;
srcNode.key = tempNode.key;
srcNode.val = tempNode.val;

@@ -104,13 +104,13 @@ srcNode.count = tempNode.count;

};
TreeMultiset.prototype.add = function (idOrNode, val, count) {
TreeMultiset.prototype.add = function (keyOrNode, val, count) {
count = count !== null && count !== void 0 ? count : 1;
var inserted = undefined, newNode;
if (idOrNode instanceof TreeMultisetNode) {
newNode = this.createNode(idOrNode.id, idOrNode.val, idOrNode.count);
if (keyOrNode instanceof TreeMultisetNode) {
newNode = this.createNode(keyOrNode.key, keyOrNode.val, keyOrNode.count);
}
else if (idOrNode === null) {
else if (keyOrNode === null) {
newNode = null;
}
else {
newNode = this.createNode(idOrNode, val, count);
newNode = this.createNode(keyOrNode, val, count);
}

@@ -129,3 +129,3 @@ if (!this.root) {

if (newNode) {
if (this._compare(cur.id, newNode.id) === types_1.CP.eq) {
if (this._compare(cur.key, newNode.key) === types_1.CP.eq) {
cur.val = newNode.val;

@@ -137,3 +137,3 @@ cur.count += newNode.count;

}
else if (this._compare(cur.id, newNode.id) === types_1.CP.gt) {
else if (this._compare(cur.key, newNode.key) === types_1.CP.gt) {
if (cur.left === undefined) {

@@ -151,3 +151,3 @@ cur.left = newNode;

}
else if (this._compare(cur.id, newNode.id) === types_1.CP.lt) {
else if (this._compare(cur.key, newNode.key) === types_1.CP.lt) {
if (cur.right === undefined) {

@@ -207,12 +207,12 @@ cur.right = newNode;

for (var i = 0; i < idsOrNodes.length; i++) {
var idOrNode = idsOrNodes[i];
if (idOrNode instanceof TreeMultisetNode) {
inserted.push(this.add(idOrNode.id, idOrNode.val, idOrNode.count));
var keyOrNode = idsOrNodes[i];
if (keyOrNode instanceof TreeMultisetNode) {
inserted.push(this.add(keyOrNode.key, keyOrNode.val, keyOrNode.count));
continue;
}
if (idOrNode === null) {
if (keyOrNode === null) {
inserted.push(this.add(NaN, null, 0));
continue;
}
inserted.push(this.add(idOrNode, data === null || data === void 0 ? void 0 : data[i], 1));
inserted.push(this.add(keyOrNode, data === null || data === void 0 ? void 0 : data[i], 1));
}

@@ -233,3 +233,3 @@ return inserted;

var midNode = sorted[m];
_this.add(midNode.id, midNode.val, midNode.count);
_this.add(midNode.key, midNode.val, midNode.count);
buildBalanceBST_1(l, m - 1);

@@ -250,3 +250,3 @@ buildBalanceBST_1(m + 1, r);

var midNode = sorted[m];
this.add(midNode.id, midNode.val, midNode.count);
this.add(midNode.key, midNode.val, midNode.count);
stack.push([m + 1, r]);

@@ -260,7 +260,7 @@ stack.push([l, m - 1]);

};
TreeMultiset.prototype.remove = function (nodeOrId, ignoreCount) {
TreeMultiset.prototype.remove = function (nodeOrKey, ignoreCount) {
var bstDeletedResult = [];
if (!this.root)
return bstDeletedResult;
var curr = this.get(nodeOrId);
var curr = this.get(nodeOrKey);
if (!curr)

@@ -344,3 +344,3 @@ return bstDeletedResult;

if (typeof subTreeRoot === 'number')
subTreeRoot = this.get(subTreeRoot, 'id');
subTreeRoot = this.get(subTreeRoot, 'key');
if (!subTreeRoot)

@@ -371,3 +371,3 @@ return 0;

if (typeof subTreeRoot === 'number')
subTreeRoot = this.get(subTreeRoot, 'id');
subTreeRoot = this.get(subTreeRoot, 'key');
if (!subTreeRoot)

@@ -459,3 +459,3 @@ return false;

if (typeof beginNode === 'number')
beginNode = this.get(beginNode, 'id');
beginNode = this.get(beginNode, 'key');
if (!beginNode)

@@ -465,7 +465,7 @@ return 0;

return 0;
var id = beginNode.id;
var key = beginNode.key;
var sum = 0;
if (this.loopType === types_1.LoopType.RECURSIVE) {
var _traverse_5 = function (cur) {
var compared = _this._compare(cur.id, id);
var compared = _this._compare(cur.key, key);
if (compared === types_1.CP.eq) {

@@ -499,3 +499,3 @@ if (cur.right)

if (cur) {
var compared = this._compare(cur.id, id);
var compared = this._compare(cur.key, key);
if (compared === types_1.CP.eq) {

@@ -529,6 +529,6 @@ if (cur.right)

if (typeof node === 'number')
node = this.get(node, 'id');
node = this.get(node, 'key');
if (!node)
return false;
var id = node.id;
var key = node.key;
if (!this.root)

@@ -538,3 +538,3 @@ return false;

var _traverse_6 = function (cur) {
var compared = _this._compare(cur.id, id);
var compared = _this._compare(cur.key, key);
if (compared === types_1.CP.gt)

@@ -544,5 +544,5 @@ cur.count += delta;

return;
if (cur.left && _this._compare(cur.left.id, id) === types_1.CP.gt)
if (cur.left && _this._compare(cur.left.key, key) === types_1.CP.gt)
_traverse_6(cur.left);
if (cur.right && _this._compare(cur.right.id, id) === types_1.CP.gt)
if (cur.right && _this._compare(cur.right.key, key) === types_1.CP.gt)
_traverse_6(cur.right);

@@ -558,8 +558,8 @@ };

if (cur) {
var compared = this._compare(cur.id, id);
var compared = this._compare(cur.key, key);
if (compared === types_1.CP.gt)
cur.count += delta;
if (cur.left && this._compare(cur.left.id, id) === types_1.CP.gt)
if (cur.left && this._compare(cur.left.key, key) === types_1.CP.gt)
queue.push(cur.left);
if (cur.right && this._compare(cur.right.id, id) === types_1.CP.gt)
if (cur.right && this._compare(cur.right.key, key) === types_1.CP.gt)
queue.push(cur.right);

@@ -566,0 +566,0 @@ }

@@ -43,12 +43,12 @@ "use strict";

var AbstractVertex = (function () {
function AbstractVertex(id, val) {
this._id = id;
function AbstractVertex(key, val) {
this._key = key;
this._val = val;
}
Object.defineProperty(AbstractVertex.prototype, "id", {
Object.defineProperty(AbstractVertex.prototype, "key", {
get: function () {
return this._id;
return this._key;
},
set: function (v) {
this._id = v;
this._key = v;
},

@@ -121,20 +121,20 @@ enumerable: false,

});
AbstractGraph.prototype.getVertex = function (vertexId) {
return this._vertices.get(vertexId) || null;
AbstractGraph.prototype.getVertex = function (vertexKey) {
return this._vertices.get(vertexKey) || null;
};
AbstractGraph.prototype.hasVertex = function (vertexOrId) {
return this._vertices.has(this._getVertexId(vertexOrId));
AbstractGraph.prototype.hasVertex = function (vertexOrKey) {
return this._vertices.has(this._getVertexKey(vertexOrKey));
};
AbstractGraph.prototype.addVertex = function (idOrVertex, val) {
if (idOrVertex instanceof AbstractVertex) {
return this._addVertexOnly(idOrVertex);
AbstractGraph.prototype.addVertex = function (keyOrVertex, val) {
if (keyOrVertex instanceof AbstractVertex) {
return this._addVertexOnly(keyOrVertex);
}
else {
var newVertex = this.createVertex(idOrVertex, val);
var newVertex = this.createVertex(keyOrVertex, val);
return this._addVertexOnly(newVertex);
}
};
AbstractGraph.prototype.removeVertex = function (vertexOrId) {
var vertexId = this._getVertexId(vertexOrId);
return this._vertices.delete(vertexId);
AbstractGraph.prototype.removeVertex = function (vertexOrKey) {
var vertexKey = this._getVertexKey(vertexOrKey);
return this._vertices.delete(vertexKey);
};

@@ -172,5 +172,5 @@ AbstractGraph.prototype.removeAllVertices = function (vertices) {

if (srcOrEdge instanceof AbstractVertex)
srcOrEdge = srcOrEdge.id;
srcOrEdge = srcOrEdge.key;
if (dest instanceof AbstractVertex)
dest = dest.id;
dest = dest.key;
var newEdge = this.createEdge(srcOrEdge, dest, weight, val);

@@ -180,8 +180,8 @@ return this._addEdgeOnly(newEdge);

else {
throw new Error('dest must be a Vertex or vertex id while srcOrEdge is an Edge');
throw new Error('dest must be a Vertex or vertex key while srcOrEdge is an Edge');
}
}
};
AbstractGraph.prototype.setEdgeWeight = function (srcOrId, destOrId, weight) {
var edge = this.getEdge(srcOrId, destOrId);
AbstractGraph.prototype.setEdgeWeight = function (srcOrKey, destOrKey, weight) {
var edge = this.getEdge(srcOrKey, destOrKey);
if (edge) {

@@ -401,5 +401,5 @@ edge.weight = weight;

var vertex = vertices_2_1.value;
var vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex)
distMap.set(vertexOrId, Infinity);
var vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex)
distMap.set(vertexOrKey, Infinity);
}

@@ -445,6 +445,6 @@ }

var vertex = vertices_3_1.value;
var vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex) {
var path = [vertexOrId];
var parent = preMap.get(vertexOrId);
var vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex) {
var path = [vertexOrKey];
var parent = preMap.get(vertexOrKey);
while (parent) {

@@ -547,5 +547,5 @@ path.push(parent);

var vertex = vertices_4_1.value;
var vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex)
distMap.set(vertexOrId, Infinity);
var vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex)
distMap.set(vertexOrKey, Infinity);
}

@@ -561,5 +561,5 @@ }

var heap = new priority_queue_1.PriorityQueue({
comparator: function (a, b) { return a.id - b.id; }
comparator: function (a, b) { return a.key - b.key; }
});
heap.add({ id: 0, val: srcVertex });
heap.add({ key: 0, val: srcVertex });
distMap.set(srcVertex, 0);

@@ -572,6 +572,6 @@ preMap.set(srcVertex, null);

var vertex = vertices_5_1.value;
var vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex) {
var path = [vertexOrId];
var parent = preMap.get(vertexOrId);
var vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex) {
var path = [vertexOrKey];
var parent = preMap.get(vertexOrKey);
while (parent) {

@@ -598,3 +598,3 @@ path.push(parent);

var curHeapNode = heap.poll();
var dist = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.id;
var dist = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.key;
var cur = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.val;

@@ -623,3 +623,3 @@ if (dist !== undefined) {

if (dist + weight < distSrcToNeighbor) {
heap.add({ id: dist + weight, val: neighbor });
heap.add({ key: dist + weight, val: neighbor });
preMap.set(neighbor, cur);

@@ -717,6 +717,6 @@ distMap.set(neighbor, dist + weight);

var vertex = vertices_6_1.value;
var vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex) {
var path = [vertexOrId];
var parent = preMap.get(vertexOrId);
var vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex) {
var path = [vertexOrKey];
var parent = preMap.get(vertexOrKey);
while (parent !== undefined) {

@@ -890,11 +890,11 @@ path.push(parent);

}
this._vertices.set(newVertex.id, newVertex);
this._vertices.set(newVertex.key, newVertex);
return true;
};
AbstractGraph.prototype._getVertex = function (vertexOrId) {
var vertexId = this._getVertexId(vertexOrId);
return this._vertices.get(vertexId) || null;
AbstractGraph.prototype._getVertex = function (vertexOrKey) {
var vertexKey = this._getVertexKey(vertexOrKey);
return this._vertices.get(vertexKey) || null;
};
AbstractGraph.prototype._getVertexId = function (vertexOrId) {
return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
AbstractGraph.prototype._getVertexKey = function (vertexOrKey) {
return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
};

@@ -901,0 +901,0 @@ AbstractGraph.prototype._setVertices = function (value) {

@@ -59,4 +59,4 @@ "use strict";

__extends(DirectedVertex, _super);
function DirectedVertex(id, val) {
return _super.call(this, id, val) || this;
function DirectedVertex(key, val) {
return _super.call(this, key, val) || this;
}

@@ -119,4 +119,4 @@ return DirectedVertex;

});
DirectedGraph.prototype.createVertex = function (id, val) {
return new DirectedVertex(id, val !== null && val !== void 0 ? val : id);
DirectedGraph.prototype.createVertex = function (key, val) {
return new DirectedVertex(key, val !== null && val !== void 0 ? val : key);
};

@@ -126,11 +126,11 @@ DirectedGraph.prototype.createEdge = function (src, dest, weight, val) {

};
DirectedGraph.prototype.getEdge = function (srcOrId, destOrId) {
DirectedGraph.prototype.getEdge = function (srcOrKey, destOrKey) {
var edges = [];
if (srcOrId !== null && destOrId !== null) {
var src = this._getVertex(srcOrId);
var dest_1 = this._getVertex(destOrId);
if (srcOrKey !== null && destOrKey !== null) {
var src = this._getVertex(srcOrKey);
var dest_1 = this._getVertex(destOrKey);
if (src && dest_1) {
var srcOutEdges = this._outEdgeMap.get(src);
if (srcOutEdges) {
edges = srcOutEdges.filter(function (edge) { return edge.dest === dest_1.id; });
edges = srcOutEdges.filter(function (edge) { return edge.dest === dest_1.key; });
}

@@ -141,5 +141,5 @@ }

};
DirectedGraph.prototype.removeEdgeSrcToDest = function (srcOrId, destOrId) {
var src = this._getVertex(srcOrId);
var dest = this._getVertex(destOrId);
DirectedGraph.prototype.removeEdgeSrcToDest = function (srcOrKey, destOrKey) {
var src = this._getVertex(srcOrKey);
var dest = this._getVertex(destOrKey);
var removed = null;

@@ -151,7 +151,7 @@ if (!src || !dest) {

if (srcOutEdges) {
(0, utils_1.arrayRemove)(srcOutEdges, function (edge) { return edge.dest === dest.id; });
(0, utils_1.arrayRemove)(srcOutEdges, function (edge) { return edge.dest === dest.key; });
}
var destInEdges = this._inEdgeMap.get(dest);
if (destInEdges) {
removed = (0, utils_1.arrayRemove)(destInEdges, function (edge) { return edge.src === src.id; })[0] || null;
removed = (0, utils_1.arrayRemove)(destInEdges, function (edge) { return edge.src === src.key; })[0] || null;
}

@@ -167,7 +167,7 @@ return removed;

if (srcOutEdges && srcOutEdges.length > 0) {
(0, utils_1.arrayRemove)(srcOutEdges, function (edge) { return edge.src === src.id; });
(0, utils_1.arrayRemove)(srcOutEdges, function (edge) { return edge.src === src.key; });
}
var destInEdges = this._inEdgeMap.get(dest);
if (destInEdges && destInEdges.length > 0) {
removed = (0, utils_1.arrayRemove)(destInEdges, function (edge) { return edge.dest === dest.id; })[0];
removed = (0, utils_1.arrayRemove)(destInEdges, function (edge) { return edge.dest === dest.key; })[0];
}

@@ -187,4 +187,4 @@ }

};
DirectedGraph.prototype.incomingEdgesOf = function (vertexOrId) {
var target = this._getVertex(vertexOrId);
DirectedGraph.prototype.incomingEdgesOf = function (vertexOrKey) {
var target = this._getVertex(vertexOrKey);
if (target) {

@@ -195,4 +195,4 @@ return this.inEdgeMap.get(target) || [];

};
DirectedGraph.prototype.outgoingEdgesOf = function (vertexOrId) {
var target = this._getVertex(vertexOrId);
DirectedGraph.prototype.outgoingEdgesOf = function (vertexOrKey) {
var target = this._getVertex(vertexOrKey);
if (target) {

@@ -203,13 +203,13 @@ return this._outEdgeMap.get(target) || [];

};
DirectedGraph.prototype.degreeOf = function (vertexOrId) {
return this.outDegreeOf(vertexOrId) + this.inDegreeOf(vertexOrId);
DirectedGraph.prototype.degreeOf = function (vertexOrKey) {
return this.outDegreeOf(vertexOrKey) + this.inDegreeOf(vertexOrKey);
};
DirectedGraph.prototype.inDegreeOf = function (vertexOrId) {
return this.incomingEdgesOf(vertexOrId).length;
DirectedGraph.prototype.inDegreeOf = function (vertexOrKey) {
return this.incomingEdgesOf(vertexOrKey).length;
};
DirectedGraph.prototype.outDegreeOf = function (vertexOrId) {
return this.outgoingEdgesOf(vertexOrId).length;
DirectedGraph.prototype.outDegreeOf = function (vertexOrKey) {
return this.outgoingEdgesOf(vertexOrKey).length;
};
DirectedGraph.prototype.edgesOf = function (vertexOrId) {
return __spreadArray(__spreadArray([], __read(this.outgoingEdgesOf(vertexOrId)), false), __read(this.incomingEdgesOf(vertexOrId)), false);
DirectedGraph.prototype.edgesOf = function (vertexOrKey) {
return __spreadArray(__spreadArray([], __read(this.outgoingEdgesOf(vertexOrKey)), false), __read(this.incomingEdgesOf(vertexOrKey)), false);
};

@@ -250,3 +250,3 @@ DirectedGraph.prototype.getEdgeSrc = function (e) {

var _this = this;
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
var statusMap = new Map();

@@ -311,4 +311,4 @@ try {

return null;
if (propertyName === 'id')
sorted = sorted.map(function (vertex) { return (vertex instanceof DirectedVertex ? vertex.id : vertex); });
if (propertyName === 'key')
sorted = sorted.map(function (vertex) { return (vertex instanceof DirectedVertex ? vertex.key : vertex); });
return sorted.reverse();

@@ -323,6 +323,6 @@ };

};
DirectedGraph.prototype.getNeighbors = function (vertexOrId) {
DirectedGraph.prototype.getNeighbors = function (vertexOrKey) {
var e_5, _a;
var neighbors = [];
var vertex = this._getVertex(vertexOrId);
var vertex = this._getVertex(vertexOrKey);
if (vertex) {

@@ -329,0 +329,0 @@ var outEdges = this.outgoingEdgesOf(vertex);

@@ -22,4 +22,4 @@ "use strict";

__extends(MapVertex, _super);
function MapVertex(id, lat, long, val) {
var _this = _super.call(this, id, val) || this;
function MapVertex(key, lat, long, val) {
var _this = _super.call(this, key, val) || this;
_this._lat = lat;

@@ -89,6 +89,6 @@ _this._long = long;

});
MapGraph.prototype.createVertex = function (id, val, lat, long) {
MapGraph.prototype.createVertex = function (key, val, lat, long) {
if (lat === void 0) { lat = this.origin[0]; }
if (long === void 0) { long = this.origin[1]; }
return new MapVertex(id, lat, long, val);
return new MapVertex(key, lat, long, val);
};

@@ -95,0 +95,0 @@ MapGraph.prototype.createEdge = function (src, dest, weight, val) {

@@ -59,4 +59,4 @@ "use strict";

__extends(UndirectedVertex, _super);
function UndirectedVertex(id, val) {
return _super.call(this, id, val) || this;
function UndirectedVertex(key, val) {
return _super.call(this, key, val) || this;
}

@@ -100,4 +100,4 @@ return UndirectedVertex;

});
UndirectedGraph.prototype.createVertex = function (id, val) {
return new UndirectedVertex(id, val !== null && val !== void 0 ? val : id);
UndirectedGraph.prototype.createVertex = function (key, val) {
return new UndirectedVertex(key, val !== null && val !== void 0 ? val : key);
};

@@ -114,3 +114,3 @@ UndirectedGraph.prototype.createEdge = function (v1, v2, weight, val) {

if (vertex1 && vertex2_1) {
edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(function (e) { return e.vertices.includes(vertex2_1.id); });
edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(function (e) { return e.vertices.includes(vertex2_1.key); });
}

@@ -129,7 +129,7 @@ }

if (v1Edges) {
removed = (0, utils_1.arrayRemove)(v1Edges, function (e) { return e.vertices.includes(vertex2.id); })[0] || null;
removed = (0, utils_1.arrayRemove)(v1Edges, function (e) { return e.vertices.includes(vertex2.key); })[0] || null;
}
var v2Edges = this._edges.get(vertex2);
if (v2Edges) {
(0, utils_1.arrayRemove)(v2Edges, function (e) { return e.vertices.includes(vertex1.id); });
(0, utils_1.arrayRemove)(v2Edges, function (e) { return e.vertices.includes(vertex1.key); });
}

@@ -141,5 +141,5 @@ return removed;

};
UndirectedGraph.prototype.degreeOf = function (vertexOrId) {
UndirectedGraph.prototype.degreeOf = function (vertexOrKey) {
var _a;
var vertex = this._getVertex(vertexOrId);
var vertex = this._getVertex(vertexOrKey);
if (vertex) {

@@ -152,4 +152,4 @@ return ((_a = this._edges.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;

};
UndirectedGraph.prototype.edgesOf = function (vertexOrId) {
var vertex = this._getVertex(vertexOrId);
UndirectedGraph.prototype.edgesOf = function (vertexOrKey) {
var vertex = this._getVertex(vertexOrKey);
if (vertex) {

@@ -171,6 +171,6 @@ return this._edges.get(vertex) || [];

};
UndirectedGraph.prototype.getNeighbors = function (vertexOrId) {
UndirectedGraph.prototype.getNeighbors = function (vertexOrKey) {
var e_1, _a;
var neighbors = [];
var vertex = this._getVertex(vertexOrId);
var vertex = this._getVertex(vertexOrKey);
if (vertex) {

@@ -181,3 +181,3 @@ var neighborEdges = this.edgesOf(vertex);

var edge = neighborEdges_1_1.value;
var neighbor = this._getVertex(edge.vertices.filter(function (e) { return e !== vertex.id; })[0]);
var neighbor = this._getVertex(edge.vertices.filter(function (e) { return e !== vertex.key; })[0]);
if (neighbor) {

@@ -184,0 +184,0 @@ neighbors.push(neighbor);

@@ -5,13 +5,13 @@ "use strict";

var TreeNode = (function () {
function TreeNode(id, value, children) {
this._id = id;
function TreeNode(key, value, children) {
this._key = key;
this._value = value || undefined;
this._children = children || [];
}
Object.defineProperty(TreeNode.prototype, "id", {
Object.defineProperty(TreeNode.prototype, "key", {
get: function () {
return this._id;
return this._key;
},
set: function (value) {
this._id = value;
this._key = value;
},

@@ -18,0 +18,0 @@ enumerable: false,

@@ -8,3 +8,3 @@ /**

*/
import type { AbstractBinaryTreeNodeNested, AbstractBinaryTreeNodeProperties, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, NodeOrPropertyName } from '../../types';
import type { AbstractBinaryTreeNodeNested, AbstractBinaryTreeNodeProperties, BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodePropertyName, DFSOrderPattern, NodeOrPropertyName } from '../../types';
import { AbstractBinaryTreeOptions, FamilyPosition, LoopType } from '../../types';

@@ -14,4 +14,4 @@ import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from '../../interfaces';

/**
* The constructor function initializes a BinaryTreeNode object with an id and an optional value.
* @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
* The constructor function initializes a BinaryTreeNode object with an key and an optional value.
* @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
* of the binary tree node. It is used to distinguish one node from another in the binary tree.

@@ -21,6 +21,6 @@ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It represents the value that will be

*/
protected constructor(id: BinaryTreeNodeId, val?: V);
private _id;
get id(): BinaryTreeNodeId;
set id(v: BinaryTreeNodeId);
protected constructor(key: BinaryTreeNodeKey, val?: V);
private _key;
get key(): BinaryTreeNodeKey;
set key(v: BinaryTreeNodeKey);
private _val;

@@ -60,4 +60,4 @@ get val(): V | undefined;

get loopType(): LoopType;
private _visitedId;
get visitedId(): BinaryTreeNodeId[];
private _visitedKey;
get visitedKey(): BinaryTreeNodeKey[];
private _visitedVal;

@@ -67,3 +67,3 @@ get visitedVal(): N['val'][];

get visitedNode(): N[];
abstract createNode(id: BinaryTreeNodeId, val?: N['val']): N | null;
abstract createNode(key: BinaryTreeNodeKey, val?: N['val']): N | null;
/**

@@ -78,3 +78,3 @@ * The `swapLocation` function swaps the location of two nodes in a binary tree.

/**
* The clear() function resets the root, size, and maxId properties to their initial values.
* The clear() function resets the root, size, and maxKey properties to their initial values.
*/

@@ -93,3 +93,3 @@ clear(): void;

* The `add` function adds a new node to a binary tree, either by ID or by creating a new node with a given value.
* @param {BinaryTreeNodeId | N | null} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId`, which
* @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey`, which
* is a number representing the ID of a binary tree node, or it can be a `N` object, which represents a binary tree

@@ -101,7 +101,7 @@ * node itself. It can also be `null` if no node is specified.

*/
add(idOrNode: BinaryTreeNodeId | N | null, val?: N['val']): N | null | undefined;
add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
/**
* The `addMany` function takes an array of binary tree node IDs or nodes, and optionally an array of corresponding data
* values, and adds them to the binary tree.
* @param {(BinaryTreeNodeId | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeId or BinaryTreeNode
* @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
* objects, or null values.

@@ -113,7 +113,7 @@ * @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to

*/
addMany(idsOrNodes: (BinaryTreeNodeId | null)[] | (N | null)[], data?: N['val'][]): (N | null | undefined)[];
addMany(idsOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][]): (N | null | undefined)[];
/**
* The `fill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
* @param {(BinaryTreeNodeId | N)[]} idsOrNodes - The `idsOrNodes` parameter is an array that can contain either
* `BinaryTreeNodeId` or `N` values.
* @param {(BinaryTreeNodeKey | N)[]} idsOrNodes - The `idsOrNodes` parameter is an array that can contain either
* `BinaryTreeNodeKey` or `N` values.
* @param {N[] | Array<N['val']>} [data] - The `data` parameter is an optional array of values that will be assigned to

@@ -124,25 +124,25 @@ * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `idsOrNodes`

*/
fill(idsOrNodes: (BinaryTreeNodeId | null)[] | (N | null)[], data?: N[] | Array<N['val']>): boolean;
fill(idsOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N[] | Array<N['val']>): boolean;
/**
* The `remove` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
* containing the deleted node and the node that needs to be balanced.
* @param {N | BinaryTreeNodeId} nodeOrId - The `nodeOrId` parameter can be either a node object (`N`) or a binary tree
* node ID (`BinaryTreeNodeId`).
* @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object (`N`) or a binary tree
* node ID (`BinaryTreeNodeKey`).
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(nodeOrId: N | BinaryTreeNodeId): BinaryTreeDeletedResult<N>[];
remove(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
/**
* The function calculates the depth of a node in a binary tree.
* @param {N | BinaryTreeNodeId | null} beginRoot - The `beginRoot` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter can be one of the following:
* @returns the depth of the given node or binary tree.
*/
getDepth(beginRoot: N | BinaryTreeNodeId | null): number;
getDepth(beginRoot: N | BinaryTreeNodeKey | null): number;
/**
* The `getHeight` function calculates the maximum height of a binary tree, either recursively or iteratively.
* @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
* generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
* @param {N | BinaryTreeNodeKey | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
* generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
* node), or `null`.
* @returns the height of the binary tree.
*/
getHeight(beginRoot?: N | BinaryTreeNodeId | null): number;
getHeight(beginRoot?: N | BinaryTreeNodeKey | null): number;
/**

@@ -167,6 +167,6 @@ * The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative

* The function `getNodes` returns an array of nodes that match a given property name and value in a binary tree.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
* generic type `N`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
* specifies the property name to use when searching for nodes. If not provided, it defaults to 'key'.
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to

@@ -177,24 +177,24 @@ * return only one node that matches the given `nodeProperty` or `propertyName`. If `onlyOne` is set to `true`, the

*/
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
/**
* The function checks if a binary tree node has a specific property.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or `N`.
* It represents the property of the binary tree node that you want to check.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'id'.
* specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'key'.
* @returns a boolean value.
*/
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
has(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): boolean;
/**
* The function returns the first node that matches the given property name and value, or null if no matching node is
* found.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or `N`.
* It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to be used for searching the binary tree nodes. If this parameter is not provided, the
* default value is set to `'id'`.
* default value is set to `'key'`.
* @returns either the value of the specified property of the node, or the node itself if no property name is provided.
* If no matching node is found, it returns null.
*/
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
/**

@@ -214,3 +214,3 @@ * The function `getPathToRoot` returns an array of nodes representing the path from a given node to the root node, with

* no node is specified.
* generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
* generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
* node), or `null`.

@@ -226,4 +226,4 @@ * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is

* no node is specified.
* @param {N | BinaryTreeNodeId | null} [node] - The `beginRoot` parameter is optional and can be of type `N` (a
* generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
* @param {N | BinaryTreeNodeKey | null} [node] - The `beginRoot` parameter is optional and can be of type `N` (a
* generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
* node).

@@ -273,13 +273,13 @@ * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is

* The function `subTreeSum` calculates the sum of a specified property in a binary tree or subtree.
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* tree or the ID of a binary tree node. It can also be `null` if there is no subtree.
* @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
* property of the binary tree node to use for calculating the sum. It can be either 'id' or 'val'. If propertyName is
* not provided, it defaults to 'id'.
* property of the binary tree node to use for calculating the sum. It can be either 'key' or 'val'. If propertyName is
* not provided, it defaults to 'key'.
* @returns a number, which is the sum of the values of the specified property in the subtree rooted at `subTreeRoot`.
*/
subTreeSum(subTreeRoot: N | BinaryTreeNodeId | null, propertyName?: BinaryTreeNodePropertyName): number;
subTreeSum(subTreeRoot: N | BinaryTreeNodeKey | null, propertyName?: BinaryTreeNodePropertyName): number;
/**
* The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.

@@ -289,17 +289,17 @@ * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of

* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'id'.
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'key'.
* @returns a boolean value.
*/
subTreeAdd(subTreeRoot: N | BinaryTreeNodeId | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
subTreeAdd(subTreeRoot: N | BinaryTreeNodeKey | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
/**
* Performs a breadth-first search (BFS) on a binary tree, accumulating properties of each node based on their 'id' property.
* Performs a breadth-first search (BFS) on a binary tree, accumulating properties of each node based on their 'key' property.
* @returns An array of binary tree node IDs.
*/
BFS(): BinaryTreeNodeId[];
BFS(): BinaryTreeNodeKey[];
/**
* Performs a breadth-first search (BFS) on a binary tree, accumulating properties of each node based on the specified property name.
* @param {'id'} nodeOrPropertyName - The name of the property to accumulate.
* @param {'key'} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of values corresponding to the specified property.
*/
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
BFS(nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
/**

@@ -318,6 +318,6 @@ * Performs a breadth-first search (BFS) on a binary tree, accumulating the 'val' property of each node.

/**
* Performs a depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on their 'id' property.
* Performs a depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
* @returns An array of binary tree node IDs.
*/
DFS(): BinaryTreeNodeId[];
DFS(): BinaryTreeNodeKey[];
/**

@@ -329,3 +329,3 @@ * Performs a depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on the specified property name.

*/
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
/**

@@ -346,6 +346,6 @@ * Performs a depth-first search (DFS) traversal on a binary tree and accumulates the 'val' property of each node.

/**
* Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on their 'id' property.
* Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
* @returns An array of binary tree node IDs.
*/
DFSIterative(): BinaryTreeNodeId[];
DFSIterative(): BinaryTreeNodeKey[];
/**

@@ -357,3 +357,3 @@ * Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on the specified property name.

*/
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
/**

@@ -374,7 +374,7 @@ * Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates the 'val' property of each node.

/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'id' property.
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
* @returns An array of binary tree node IDs.
*/
levelIterative(node: N | null): BinaryTreeNodeId[];
levelIterative(node: N | null): BinaryTreeNodeKey[];
/**

@@ -386,3 +386,3 @@ * Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on the specified property name.

*/
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
levelIterative(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
/**

@@ -407,10 +407,10 @@ * Performs a level-order traversal on a binary tree starting from the specified node and accumulates the 'val' property of each node.

*/
listLevels(node: N | null): BinaryTreeNodeId[][];
listLevels(node: N | null): BinaryTreeNodeKey[][];
/**
* Collects nodes from a binary tree by a specified property and organizes them into levels.
* @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
* @param {'id} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
* @param {'key} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
* @returns A 2D array of values corresponding to the specified property.
*/
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
listLevels(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[][];
/**

@@ -444,10 +444,10 @@ * Collects nodes from a binary tree by a specified property and organizes them into levels.

*/
morris(): BinaryTreeNodeId[];
morris(): BinaryTreeNodeKey[];
/**
* Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates properties of each node based on the specified property name.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {'id'} nodeOrPropertyName - The name of the property to accumulate.
* @param {'key'} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of values corresponding to the specified property.
*/
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
/**

@@ -484,6 +484,6 @@ * Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates the 'val' property of each node.

/**
* The function sets the value of the `_visitedId` property in a protected manner.
* @param {BinaryTreeNodeId[]} value - value is an array of BinaryTreeNodeId values.
* The function sets the value of the `_visitedKey` property in a protected manner.
* @param {BinaryTreeNodeKey[]} value - value is an array of BinaryTreeNodeKey values.
*/
protected _setVisitedId(value: BinaryTreeNodeId[]): void;
protected _setVisitedKey(value: BinaryTreeNodeKey[]): void;
/**

@@ -520,7 +520,7 @@ * The function sets the value of the "_visitedVal" property to the given array.

* @param {(N | null | undefined)[]} result - An array that stores the matching nodes.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeId` or a `N`
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeKey` or a `N`
* type. It represents the property value that we are comparing against in the switch statement.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'id'`
* or `'val'`. If it is not provided or is not equal to `'id'` or `'val'`, the
* specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'key'`
* or `'val'`. If it is not provided or is not equal to `'key'` or `'val'`, the
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to

@@ -531,3 +531,3 @@ * stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to

*/
protected _pushByPropertyNameStopOrNot(cur: N, result: (N | null | undefined)[], nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
protected _pushByPropertyNameStopOrNot(cur: N, result: (N | null | undefined)[], nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
/**

@@ -534,0 +534,0 @@ * The function `_accumulatedByPropertyName` accumulates values from a given node based on the specified property name.

@@ -12,4 +12,4 @@ /**

/**
* The constructor function initializes a BinaryTreeNode object with an id and an optional value.
* @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
* The constructor function initializes a BinaryTreeNode object with an key and an optional value.
* @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
* of the binary tree node. It is used to distinguish one node from another in the binary tree.

@@ -19,12 +19,12 @@ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It represents the value that will be

*/
constructor(id, val) {
constructor(key, val) {
this._height = 0;
this._id = id;
this._key = key;
this._val = val;
}
get id() {
return this._id;
get key() {
return this._key;
}
set id(v) {
this._id = v;
set key(v) {
this._key = v;
}

@@ -115,3 +115,3 @@ get val() {

this._loopType = LoopType.ITERATIVE;
this._visitedId = [];
this._visitedKey = [];
this._visitedVal = [];

@@ -134,4 +134,4 @@ this._visitedNode = [];

}
get visitedId() {
return this._visitedId;
get visitedKey() {
return this._visitedKey;
}

@@ -152,10 +152,10 @@ get visitedVal() {

swapLocation(srcNode, destNode) {
const { id, val, height } = destNode;
const tempNode = this.createNode(id, val);
const { key, val, height } = destNode;
const tempNode = this.createNode(key, val);
if (tempNode) {
tempNode.height = height;
destNode.id = srcNode.id;
destNode.key = srcNode.key;
destNode.val = srcNode.val;
destNode.height = srcNode.height;
srcNode.id = tempNode.id;
srcNode.key = tempNode.key;
srcNode.val = tempNode.val;

@@ -167,3 +167,3 @@ srcNode.height = tempNode.height;

/**
* The clear() function resets the root, size, and maxId properties to their initial values.
* The clear() function resets the root, size, and maxKey properties to their initial values.
*/

@@ -188,3 +188,3 @@ clear() {

* The `add` function adds a new node to a binary tree, either by ID or by creating a new node with a given value.
* @param {BinaryTreeNodeId | N | null} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId`, which
* @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey`, which
* is a number representing the ID of a binary tree node, or it can be a `N` object, which represents a binary tree

@@ -196,3 +196,3 @@ * node itself. It can also be `null` if no node is specified.

*/
add(idOrNode, val) {
add(keyOrNode, val) {
const _bfs = (root, newNode) => {

@@ -203,3 +203,3 @@ const queue = [root];

if (cur) {
if (newNode && cur.id === newNode.id)
if (newNode && cur.key === newNode.key)
return;

@@ -220,10 +220,10 @@ const inserted = this._addTo(newNode, cur);

let inserted, needInsert;
if (idOrNode === null) {
if (keyOrNode === null) {
needInsert = null;
}
else if (typeof idOrNode === 'number') {
needInsert = this.createNode(idOrNode, val);
else if (typeof keyOrNode === 'number') {
needInsert = this.createNode(keyOrNode, val);
}
else if (idOrNode instanceof AbstractBinaryTreeNode) {
needInsert = idOrNode;
else if (keyOrNode instanceof AbstractBinaryTreeNode) {
needInsert = keyOrNode;
}

@@ -233,3 +233,3 @@ else {

}
const existNode = idOrNode ? this.get(idOrNode, 'id') : undefined;
const existNode = keyOrNode ? this.get(keyOrNode, 'key') : undefined;
if (this.root) {

@@ -259,3 +259,3 @@ if (existNode) {

* values, and adds them to the binary tree.
* @param {(BinaryTreeNodeId | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeId or BinaryTreeNode
* @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
* objects, or null values.

@@ -271,8 +271,8 @@ * @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to

for (let i = 0; i < idsOrNodes.length; i++) {
const idOrNode = idsOrNodes[i];
if (idOrNode instanceof AbstractBinaryTreeNode) {
inserted.push(this.add(idOrNode.id, idOrNode.val));
const keyOrNode = idsOrNodes[i];
if (keyOrNode instanceof AbstractBinaryTreeNode) {
inserted.push(this.add(keyOrNode.key, keyOrNode.val));
continue;
}
if (idOrNode === null) {
if (keyOrNode === null) {
inserted.push(this.add(null));

@@ -282,3 +282,3 @@ continue;

const val = data === null || data === void 0 ? void 0 : data[i];
inserted.push(this.add(idOrNode, val));
inserted.push(this.add(keyOrNode, val));
}

@@ -289,4 +289,4 @@ return inserted;

* The `fill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
* @param {(BinaryTreeNodeId | N)[]} idsOrNodes - The `idsOrNodes` parameter is an array that can contain either
* `BinaryTreeNodeId` or `N` values.
* @param {(BinaryTreeNodeKey | N)[]} idsOrNodes - The `idsOrNodes` parameter is an array that can contain either
* `BinaryTreeNodeKey` or `N` values.
* @param {N[] | Array<N['val']>} [data] - The `data` parameter is an optional array of values that will be assigned to

@@ -304,11 +304,11 @@ * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `idsOrNodes`

* containing the deleted node and the node that needs to be balanced.
* @param {N | BinaryTreeNodeId} nodeOrId - The `nodeOrId` parameter can be either a node object (`N`) or a binary tree
* node ID (`BinaryTreeNodeId`).
* @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object (`N`) or a binary tree
* node ID (`BinaryTreeNodeKey`).
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(nodeOrId) {
remove(nodeOrKey) {
const bstDeletedResult = [];
if (!this.root)
return bstDeletedResult;
const curr = typeof nodeOrId === 'number' ? this.get(nodeOrId) : nodeOrId;
const curr = typeof nodeOrKey === 'number' ? this.get(nodeOrKey) : nodeOrKey;
if (!curr)

@@ -354,3 +354,3 @@ return bstDeletedResult;

* The function calculates the depth of a node in a binary tree.
* @param {N | BinaryTreeNodeId | null} beginRoot - The `beginRoot` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter can be one of the following:
* @returns the depth of the given node or binary tree.

@@ -360,3 +360,3 @@ */

if (typeof beginRoot === 'number')
beginRoot = this.get(beginRoot, 'id');
beginRoot = this.get(beginRoot, 'key');
let depth = 0;

@@ -371,4 +371,4 @@ while (beginRoot === null || beginRoot === void 0 ? void 0 : beginRoot.parent) {

* The `getHeight` function calculates the maximum height of a binary tree, either recursively or iteratively.
* @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
* generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
* @param {N | BinaryTreeNodeKey | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
* generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
* node), or `null`.

@@ -380,3 +380,3 @@ * @returns the height of the binary tree.

if (typeof beginRoot === 'number')
beginRoot = this.get(beginRoot, 'id');
beginRoot = this.get(beginRoot, 'key');
if (!beginRoot)

@@ -478,6 +478,6 @@ return -1;

* The function `getNodes` returns an array of nodes that match a given property name and value in a binary tree.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
* generic type `N`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
* specifies the property name to use when searching for nodes. If not provided, it defaults to 'key'.
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to

@@ -491,3 +491,3 @@ * return only one node that matches the given `nodeProperty` or `propertyName`. If `onlyOne` is set to `true`, the

return [];
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
const result = [];

@@ -521,10 +521,10 @@ if (this.loopType === LoopType.RECURSIVE) {

* The function checks if a binary tree node has a specific property.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or `N`.
* It represents the property of the binary tree node that you want to check.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'id'.
* specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'key'.
* @returns a boolean value.
*/
has(nodeProperty, propertyName) {
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
// TODO may support finding node by value equal

@@ -536,7 +536,7 @@ return this.getNodes(nodeProperty, propertyName).length > 0;

* found.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or `N`.
* It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to be used for searching the binary tree nodes. If this parameter is not provided, the
* default value is set to `'id'`.
* default value is set to `'key'`.
* @returns either the value of the specified property of the node, or the node itself if no property name is provided.

@@ -547,3 +547,3 @@ * If no matching node is found, it returns null.

var _a;
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
// TODO may support finding node by value equal

@@ -563,3 +563,3 @@ return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;

getPathToRoot(node, isReverse = true) {
// TODO to support get path through passing id
// TODO to support get path through passing key
const result = [];

@@ -578,4 +578,4 @@ while (node.parent) {

* no node is specified.
* @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
* generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
* @param {N | BinaryTreeNodeKey | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
* generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
* node), or `null`.

@@ -589,3 +589,3 @@ * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is

if (typeof beginRoot === 'number')
beginRoot = this.get(beginRoot, 'id');
beginRoot = this.get(beginRoot, 'key');
beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;

@@ -623,3 +623,3 @@ if (!beginRoot)

getRightMost(node) {
// TODO support get right most by passing id in
// TODO support get right most by passing key in
node = node !== null && node !== void 0 ? node : this.root;

@@ -659,5 +659,5 @@ if (!node)

return true;
if (cur.id <= min || cur.id >= max)
if (cur.key <= min || cur.key >= max)
return false;
return dfs(cur.left, min, cur.id) && dfs(cur.right, cur.id, max);
return dfs(cur.left, min, cur.key) && dfs(cur.right, cur.key, max);
};

@@ -675,5 +675,5 @@ return dfs(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);

curr = stack.pop();
if (!curr || prev >= curr.id)
if (!curr || prev >= curr.key)
return false;
prev = curr.id;
prev = curr.key;
curr = curr.right;

@@ -698,3 +698,3 @@ }

getSubTreeSize(subTreeRoot) {
// TODO support id passed in
// TODO support key passed in
let size = 0;

@@ -725,13 +725,13 @@ if (!subTreeRoot)

* The function `subTreeSum` calculates the sum of a specified property in a binary tree or subtree.
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* tree or the ID of a binary tree node. It can also be `null` if there is no subtree.
* @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
* property of the binary tree node to use for calculating the sum. It can be either 'id' or 'val'. If propertyName is
* not provided, it defaults to 'id'.
* property of the binary tree node to use for calculating the sum. It can be either 'key' or 'val'. If propertyName is
* not provided, it defaults to 'key'.
* @returns a number, which is the sum of the values of the specified property in the subtree rooted at `subTreeRoot`.
*/
subTreeSum(subTreeRoot, propertyName) {
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
if (typeof subTreeRoot === 'number')
subTreeRoot = this.get(subTreeRoot, 'id');
subTreeRoot = this.get(subTreeRoot, 'key');
if (!subTreeRoot)

@@ -743,4 +743,4 @@ return 0;

switch (propertyName) {
case 'id':
needSum = cur.id;
case 'key':
needSum = cur.key;
break;

@@ -751,3 +751,3 @@ case 'val':

default:
needSum = cur.id;
needSum = cur.key;
break;

@@ -778,3 +778,3 @@ }

* The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.

@@ -784,9 +784,9 @@ * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of

* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'id'.
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'key'.
* @returns a boolean value.
*/
subTreeAdd(subTreeRoot, delta, propertyName) {
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
if (typeof subTreeRoot === 'number')
subTreeRoot = this.get(subTreeRoot, 'id');
subTreeRoot = this.get(subTreeRoot, 'key');
if (!subTreeRoot)

@@ -796,7 +796,7 @@ return false;

switch (propertyName) {
case 'id':
cur.id += delta;
case 'key':
cur.key += delta;
break;
default:
cur.id += delta;
cur.key += delta;
break;

@@ -832,3 +832,3 @@ }

BFS(nodeOrPropertyName) {
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
this._clearResults();

@@ -852,3 +852,3 @@ const queue = [this.root];

* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. If no `nodeOrPropertyName` is provided, the default value is `'id'`.
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. If no `nodeOrPropertyName` is provided, the default value is `'key'`.
* @returns an instance of the AbstractBinaryTreeNodeProperties class, which contains the accumulated properties of the binary tree nodes based on the specified pattern and node or property name.

@@ -858,3 +858,3 @@ */

pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
this._clearResults();

@@ -893,3 +893,3 @@ const _traverse = (node) => {

* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. By default, it is set to `'id'`.
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. By default, it is set to `'key'`.
* @returns An object of type AbstractBinaryTreeNodeProperties<N>.

@@ -899,3 +899,3 @@ */

pattern = pattern || 'in';
nodeOrPropertyName = nodeOrPropertyName || 'id';
nodeOrPropertyName = nodeOrPropertyName || 'key';
this._clearResults();

@@ -947,9 +947,9 @@ if (!this.root)

* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
* can be either a `BinaryTreeNode` property name or the string `'id'`. If a property name is provided, the function
* can be either a `BinaryTreeNode` property name or the string `'key'`. If a property name is provided, the function
* will accumulate results based on that property. If no property name is provided, the function will default to
* accumulating results based on the 'id' property.
* accumulating results based on the 'key' property.
* @returns An object of type `AbstractBinaryTreeNodeProperties<N>`.
*/
levelIterative(node, nodeOrPropertyName) {
nodeOrPropertyName = nodeOrPropertyName || 'id';
nodeOrPropertyName = nodeOrPropertyName || 'key';
node = node || this.root;

@@ -977,7 +977,7 @@ if (!node)

* @param {N | null} node - The `node` parameter is a BinaryTreeNode object or null. It represents the root node of a binary tree. If it is null, the function will use the root node of the current binary tree instance.
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that specifies the property of the `BinaryTreeNode` object to collect at each level. It can be one of the following values: 'id', 'val', or 'node'. If not provided, it defaults to 'id'.
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that specifies the property of the `BinaryTreeNode` object to collect at each level. It can be one of the following values: 'key', 'val', or 'node'. If not provided, it defaults to 'key'.
* @returns A 2D array of `AbstractBinaryTreeNodeProperty<N>` objects.
*/
listLevels(node, nodeOrPropertyName) {
nodeOrPropertyName = nodeOrPropertyName || 'id';
nodeOrPropertyName = nodeOrPropertyName || 'key';
node = node || this.root;

@@ -989,4 +989,4 @@ if (!node)

switch (nodeOrPropertyName) {
case 'id':
levelsNodes[level].push(node.id);
case 'key':
levelsNodes[level].push(node.key);
break;

@@ -1000,3 +1000,3 @@ case 'val':

default:
levelsNodes[level].push(node.id);
levelsNodes[level].push(node.key);
break;

@@ -1055,3 +1055,3 @@ }

* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The property name of the nodes to retrieve or perform operations on during the traversal. It can be any valid property name of the nodes in the binary tree. If not provided, it defaults to 'id'.
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The property name of the nodes to retrieve or perform operations on during the traversal. It can be any valid property name of the nodes in the binary tree. If not provided, it defaults to 'key'.
* @returns An array of AbstractBinaryTreeNodeProperties<N> objects.

@@ -1063,3 +1063,3 @@ */

pattern = pattern || 'in';
nodeOrPropertyName = nodeOrPropertyName || 'id';
nodeOrPropertyName = nodeOrPropertyName || 'key';
this._clearResults();

@@ -1190,7 +1190,7 @@ let cur = this.root;

/**
* The function sets the value of the `_visitedId` property in a protected manner.
* @param {BinaryTreeNodeId[]} value - value is an array of BinaryTreeNodeId values.
* The function sets the value of the `_visitedKey` property in a protected manner.
* @param {BinaryTreeNodeKey[]} value - value is an array of BinaryTreeNodeKey values.
*/
_setVisitedId(value) {
this._visitedId = value;
_setVisitedKey(value) {
this._visitedKey = value;
}

@@ -1234,3 +1234,3 @@ /**

_clearResults() {
this._visitedId = [];
this._visitedKey = [];
this._visitedVal = [];

@@ -1244,7 +1244,7 @@ this._visitedNode = [];

* @param {(N | null | undefined)[]} result - An array that stores the matching nodes.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeId` or a `N`
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeKey` or a `N`
* type. It represents the property value that we are comparing against in the switch statement.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'id'`
* or `'val'`. If it is not provided or is not equal to `'id'` or `'val'`, the
* specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'key'`
* or `'val'`. If it is not provided or is not equal to `'key'` or `'val'`, the
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to

@@ -1257,4 +1257,4 @@ * stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to

switch (propertyName) {
case 'id':
if (cur.id === nodeProperty) {
case 'key':
if (cur.key === nodeProperty) {
result.push(cur);

@@ -1271,3 +1271,3 @@ return !!onlyOne;

default:
if (cur.id === nodeProperty) {
if (cur.key === nodeProperty) {
result.push(cur);

@@ -1287,6 +1287,6 @@ return !!onlyOne;

_accumulatedByPropertyName(node, nodeOrPropertyName) {
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
switch (nodeOrPropertyName) {
case 'id':
this._visitedId.push(node.id);
case 'key':
this._visitedKey.push(node.key);
break;

@@ -1300,3 +1300,3 @@ case 'val':

default:
this._visitedId.push(node.id);
this._visitedKey.push(node.key);
break;

@@ -1317,6 +1317,6 @@ }

_getResultByPropertyName(nodeOrPropertyName) {
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
switch (nodeOrPropertyName) {
case 'id':
return this._visitedId;
case 'key':
return this._visitedKey;
case 'val':

@@ -1327,5 +1327,5 @@ return this._visitedVal;

default:
return this._visitedId;
return this._visitedKey;
}
}
}

@@ -9,6 +9,6 @@ /**

import { BST, BSTNode } from './bst';
import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId } from '../../types';
import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../../types';
import { IAVLTree, IAVLTreeNode } from '../../interfaces';
export declare class AVLTreeNode<V = any, NEIGHBOR extends AVLTreeNode<V, NEIGHBOR> = AVLTreeNodeNested<V>> extends BSTNode<V, NEIGHBOR> implements IAVLTreeNode<V, NEIGHBOR> {
constructor(id: BinaryTreeNodeId, val?: V);
constructor(key: BinaryTreeNodeKey, val?: V);
}

@@ -24,13 +24,13 @@ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends BST<N> implements IAVLTree<N> {

/**
* The function creates a new AVL tree node with the given id and value.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
* The function creates a new AVL tree node with the given key and value.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
* identify each node in the tree.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
* that will be stored in the node.
* @returns a new AVLTreeNode object with the specified id and value.
* @returns a new AVLTreeNode object with the specified key and value.
*/
createNode(id: BinaryTreeNodeId, val?: N['val']): N;
createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
/**
* The function overrides the add method of a binary tree node and balances the tree after inserting a new node.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier of the binary tree node that we want to add.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It is of type

@@ -40,11 +40,11 @@ * `N['val']`, which means it should be of the same type as the `val` property of the nodes in the binary tree.

*/
add(id: BinaryTreeNodeId, val?: N['val']): N | null | undefined;
add(key: BinaryTreeNodeKey, val?: N['val']): N | null | undefined;
/**
* The function overrides the remove method of a binary tree and performs additional operations to balance the tree after
* deletion.
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
* @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be
* removed.
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(id: BinaryTreeNodeId): BinaryTreeDeletedResult<N>[];
remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
/**

@@ -51,0 +51,0 @@ * The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the

@@ -10,4 +10,4 @@ /**

export class AVLTreeNode extends BSTNode {
constructor(id, val) {
super(id, val);
constructor(key, val) {
super(key, val);
}

@@ -26,15 +26,15 @@ }

/**
* The function creates a new AVL tree node with the given id and value.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
* The function creates a new AVL tree node with the given key and value.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
* identify each node in the tree.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
* that will be stored in the node.
* @returns a new AVLTreeNode object with the specified id and value.
* @returns a new AVLTreeNode object with the specified key and value.
*/
createNode(id, val) {
return new AVLTreeNode(id, val);
createNode(key, val) {
return new AVLTreeNode(key, val);
}
/**
* The function overrides the add method of a binary tree node and balances the tree after inserting a new node.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier of the binary tree node that we want to add.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It is of type

@@ -44,5 +44,5 @@ * `N['val']`, which means it should be of the same type as the `val` property of the nodes in the binary tree.

*/
add(id, val) {
add(key, val) {
// TODO support node as a param
const inserted = super.add(id, val);
const inserted = super.add(key, val);
if (inserted)

@@ -55,8 +55,8 @@ this._balancePath(inserted);

* deletion.
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
* @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be
* removed.
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(id) {
const deletedResults = super.remove(id);
remove(key) {
const deletedResults = super.remove(key);
for (const { needBalanced } of deletedResults) {

@@ -63,0 +63,0 @@ if (needBalanced) {

@@ -8,7 +8,7 @@ /**

*/
import type { BinaryTreeNodeId, BinaryTreeNodeNested, BinaryTreeOptions } from '../../types';
import type { BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions } from '../../types';
import { AbstractBinaryTree, AbstractBinaryTreeNode } from './abstract-binary-tree';
import { IBinaryTree, IBinaryTreeNode } from '../../interfaces';
export declare class BinaryTreeNode<V = any, NEIGHBOR extends BinaryTreeNode<V, NEIGHBOR> = BinaryTreeNodeNested<V>> extends AbstractBinaryTreeNode<V, NEIGHBOR> implements IBinaryTreeNode<V, NEIGHBOR> {
constructor(id: BinaryTreeNodeId, val?: V);
constructor(key: BinaryTreeNodeKey, val?: V);
}

@@ -25,9 +25,9 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode> extends AbstractBinaryTree<N> implements IBinaryTree<N> {

* The function creates a new binary tree node with an optional value.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
* `BinaryTreeNodeId`, which represents the unique identifier for each node in the binary tree.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is of type
* `BinaryTreeNodeKey`, which represents the unique identifier for each node in the binary tree.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
* stored in the node.
* @returns a new instance of a BinaryTreeNode with the specified id and value.
* @returns a new instance of a BinaryTreeNode with the specified key and value.
*/
createNode(id: BinaryTreeNodeId, val?: N['val']): N;
createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
}

@@ -10,4 +10,4 @@ /**

export class BinaryTreeNode extends AbstractBinaryTreeNode {
constructor(id, val) {
super(id, val);
constructor(key, val) {
super(key, val);
}

@@ -27,11 +27,11 @@ }

* The function creates a new binary tree node with an optional value.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
* `BinaryTreeNodeId`, which represents the unique identifier for each node in the binary tree.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is of type
* `BinaryTreeNodeKey`, which represents the unique identifier for each node in the binary tree.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
* stored in the node.
* @returns a new instance of a BinaryTreeNode with the specified id and value.
* @returns a new instance of a BinaryTreeNode with the specified key and value.
*/
createNode(id, val) {
return new BinaryTreeNode(id, val);
createNode(key, val) {
return new BinaryTreeNode(key, val);
}
}

@@ -8,3 +8,3 @@ /**

*/
import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTNodeNested, BSTOptions } from '../../types';
import type { BinaryTreeNodeKey, BinaryTreeNodePropertyName, BSTComparator, BSTNodeNested, BSTOptions } from '../../types';
import { CP } from '../../types';

@@ -14,3 +14,3 @@ import { BinaryTree, BinaryTreeNode } from './binary-tree';

export declare class BSTNode<V = any, NEIGHBOR extends BSTNode<V, NEIGHBOR> = BSTNodeNested<V>> extends BinaryTreeNode<V, NEIGHBOR> implements IBSTNode<V, NEIGHBOR> {
constructor(id: BinaryTreeNodeId, val?: V);
constructor(key: BinaryTreeNodeKey, val?: V);
}

@@ -24,14 +24,14 @@ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N> implements IBST<N> {

/**
* The function creates a new binary search tree node with the given id and value.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
* The function creates a new binary search tree node with the given key and value.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
* identify each node in the binary tree.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
* that will be stored in the node.
* @returns a new instance of the BSTNode class with the specified id and value.
* @returns a new instance of the BSTNode class with the specified key and value.
*/
createNode(id: BinaryTreeNodeId, val?: N['val']): N;
createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
/**
* The `add` function adds a new node to a binary search tree, either by creating a new node or by updating an existing
* node with the same ID.
* @param {BinaryTreeNodeId | N | null} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId` or a `N`
* @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N`
* (which represents a binary tree node) or `null`.

@@ -42,8 +42,8 @@ * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node

*/
add(idOrNode: BinaryTreeNodeId | N | null, val?: N['val']): N | null | undefined;
add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
/**
* The `addMany` function overrides the base class method to add multiple nodes to a binary search tree in a balanced
* manner.
* @param {[BinaryTreeNodeId | N , N['val']][]} idsOrNodes - The `idsOrNodes` parameter in the `addMany` function is an array of
* `BinaryTreeNodeId` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
* @param {[BinaryTreeNodeKey | N , N['val']][]} idsOrNodes - The `idsOrNodes` parameter in the `addMany` function is an array of
* `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
* to the binary search tree.

@@ -54,26 +54,26 @@ * @param {N['val'][]} data - The values of tree nodes

*/
addMany(idsOrNodes: (BinaryTreeNodeId | null)[] | (N | null)[], data?: N['val'][], isBalanceAdd?: boolean): (N | null | undefined)[];
addMany(idsOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][], isBalanceAdd?: boolean): (N | null | undefined)[];
/**
* The function returns the first node in a binary tree that matches the given property name and value.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
* generic type `N`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'id'`.
* @returns The method is returning either a BinaryTreeNodeId or N (generic type) or null.
* specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
* @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
*/
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
/**
* The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
* leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
* @returns The method `lastKey()` returns the id of the rightmost node in the binary tree if the comparison between
* the values at index 0 and 1 is less than, otherwise it returns the id of the leftmost node. If the comparison is
* equal, it returns the id of the rightmost node. If there are no nodes in the tree, it returns 0.
* The function returns the key of the rightmost node if the comparison between two values is less than, the key of the
* leftmost node if the comparison is greater than, and the key of the rightmost node otherwise.
* @returns The method `lastKey()` returns the key of the rightmost node in the binary tree if the comparison between
* the values at index 0 and 1 is less than, otherwise it returns the key of the leftmost node. If the comparison is
* equal, it returns the key of the rightmost node. If there are no nodes in the tree, it returns 0.
*/
lastKey(): BinaryTreeNodeId;
lastKey(): BinaryTreeNodeKey;
/**
* The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or an
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or an
* `N` type. It represents the property of the binary tree node that you want to compare with.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use for comparison. If not provided, it defaults to `'id'`.
* specifies the property name to use for comparison. If not provided, it defaults to `'key'`.
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to

@@ -84,18 +84,18 @@ * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`

*/
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
/**
* The `lesserSum` function calculates the sum of property values in a binary tree for nodes that have a property value
* less than a given node.
* @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} beginNode - The `beginNode` parameter can be one of the following:
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use for calculating the sum. If not provided, it defaults to `'id'`.
* specifies the property name to use for calculating the sum. If not provided, it defaults to `'key'`.
* @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
* binary tree that have a lesser value than the specified `beginNode` based on the `propertyName`.
*/
lesserSum(beginNode: N | BinaryTreeNodeId | null, propertyName?: BinaryTreeNodePropertyName): number;
lesserSum(beginNode: N | BinaryTreeNodeKey | null, propertyName?: BinaryTreeNodePropertyName): number;
/**
* The `allGreaterNodesAdd` function adds a delta value to the specified property of all nodes in a binary tree that
* have a greater value than a given node.
* @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be either of type `N` (a generic type),
* `BinaryTreeNodeId`, or `null`. It represents the node in the binary tree to which the delta value will be added.
* @param {N | BinaryTreeNodeKey | null} node - The `node` parameter can be either of type `N` (a generic type),
* `BinaryTreeNodeKey`, or `null`. It represents the node in the binary tree to which the delta value will be added.
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of

@@ -105,6 +105,6 @@ * each greater node should be increased.

* specifies the property name of the nodes in the binary tree that you want to update. If not provided, it defaults to
* 'id'.
* 'key'.
* @returns a boolean value.
*/
allGreaterNodesAdd(node: N | BinaryTreeNodeId | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
allGreaterNodesAdd(node: N | BinaryTreeNodeKey | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
/**

@@ -134,8 +134,8 @@ * Balancing Adjustment:

* greater than, less than, or equal to the second ID.
* @param {BinaryTreeNodeId} a - a is a BinaryTreeNodeId, which represents the identifier of a binary tree node.
* @param {BinaryTreeNodeId} b - The parameter "b" in the above code refers to a BinaryTreeNodeId.
* @param {BinaryTreeNodeKey} a - a is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
* @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
* @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
* than), or CP.eq (equal).
*/
protected _compare(a: BinaryTreeNodeId, b: BinaryTreeNodeId): CP;
protected _compare(a: BinaryTreeNodeKey, b: BinaryTreeNodeKey): CP;
}
import { CP, LoopType } from '../../types';
import { BinaryTree, BinaryTreeNode } from './binary-tree';
export class BSTNode extends BinaryTreeNode {
constructor(id, val) {
super(id, val);
constructor(key, val) {
super(key, val);
}

@@ -24,11 +24,11 @@ }

/**
* The function creates a new binary search tree node with the given id and value.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
* The function creates a new binary search tree node with the given key and value.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
* identify each node in the binary tree.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
* that will be stored in the node.
* @returns a new instance of the BSTNode class with the specified id and value.
* @returns a new instance of the BSTNode class with the specified key and value.
*/
createNode(id, val) {
return new BSTNode(id, val);
createNode(key, val) {
return new BSTNode(key, val);
}

@@ -38,3 +38,3 @@ /**

* node with the same ID.
* @param {BinaryTreeNodeId | N | null} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId` or a `N`
* @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N`
* (which represents a binary tree node) or `null`.

@@ -45,13 +45,13 @@ * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node

*/
add(idOrNode, val) {
add(keyOrNode, val) {
// TODO support node as a param
let inserted = null;
let newNode = null;
if (idOrNode instanceof BSTNode) {
newNode = idOrNode;
if (keyOrNode instanceof BSTNode) {
newNode = keyOrNode;
}
else if (typeof idOrNode === 'number') {
newNode = this.createNode(idOrNode, val);
else if (typeof keyOrNode === 'number') {
newNode = this.createNode(keyOrNode, val);
}
else if (idOrNode === null) {
else if (keyOrNode === null) {
newNode = null;

@@ -69,3 +69,3 @@ }

if (cur !== null && newNode !== null) {
if (this._compare(cur.id, newNode.id) === CP.eq) {
if (this._compare(cur.key, newNode.key) === CP.eq) {
if (newNode) {

@@ -78,3 +78,3 @@ cur.val = newNode.val;

}
else if (this._compare(cur.id, newNode.id) === CP.gt) {
else if (this._compare(cur.key, newNode.key) === CP.gt) {
// Traverse left of the node

@@ -97,3 +97,3 @@ if (cur.left === undefined) {

}
else if (this._compare(cur.id, newNode.id) === CP.lt) {
else if (this._compare(cur.key, newNode.key) === CP.lt) {
// Traverse right of the node

@@ -127,4 +127,4 @@ if (cur.right === undefined) {

* manner.
* @param {[BinaryTreeNodeId | N , N['val']][]} idsOrNodes - The `idsOrNodes` parameter in the `addMany` function is an array of
* `BinaryTreeNodeId` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
* @param {[BinaryTreeNodeKey | N , N['val']][]} idsOrNodes - The `idsOrNodes` parameter in the `addMany` function is an array of
* `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
* to the binary search tree.

@@ -146,18 +146,18 @@ * @param {N['val'][]} data - The values of tree nodes

function isNodeOrNullTuple(arr) {
for (const [idOrNode] of arr)
if (idOrNode instanceof BSTNode)
for (const [keyOrNode] of arr)
if (keyOrNode instanceof BSTNode)
return true;
return false;
}
function isBinaryTreeIdOrNullTuple(arr) {
for (const [idOrNode] of arr)
if (typeof idOrNode === 'number')
function isBinaryTreeKeyOrNullTuple(arr) {
for (const [keyOrNode] of arr)
if (typeof keyOrNode === 'number')
return true;
return false;
}
let sortedIdsOrNodes = [], sortedData = [];
let sortedKeysOrNodes = [], sortedData = [];
if (isNodeOrNullTuple(combinedArr)) {
sorted = combinedArr.sort((a, b) => a[0].id - b[0].id);
sorted = combinedArr.sort((a, b) => a[0].key - b[0].key);
}
else if (isBinaryTreeIdOrNullTuple(combinedArr)) {
else if (isBinaryTreeKeyOrNullTuple(combinedArr)) {
sorted = combinedArr.sort((a, b) => a[0] - b[0]);

@@ -168,3 +168,3 @@ }

}
sortedIdsOrNodes = sorted.map(([idOrNode]) => idOrNode);
sortedKeysOrNodes = sorted.map(([keyOrNode]) => keyOrNode);
sortedData = sorted.map(([, val]) => val);

@@ -189,3 +189,3 @@ const recursive = (arr, data) => {

const m = l + Math.floor((r - l) / 2);
const newNode = this.add(sortedIdsOrNodes[m], sortedData === null || sortedData === void 0 ? void 0 : sortedData[m]);
const newNode = this.add(sortedKeysOrNodes[m], sortedData === null || sortedData === void 0 ? void 0 : sortedData[m]);
inserted.push(newNode);

@@ -199,3 +199,3 @@ stack.push([m + 1, r]);

if (this.loopType === LoopType.RECURSIVE) {
recursive(sortedIdsOrNodes, sortedData);
recursive(sortedKeysOrNodes, sortedData);
}

@@ -209,19 +209,19 @@ else {

* The function returns the first node in a binary tree that matches the given property name and value.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
* generic type `N`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'id'`.
* @returns The method is returning either a BinaryTreeNodeId or N (generic type) or null.
* specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
* @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
*/
get(nodeProperty, propertyName) {
var _a;
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
}
/**
* The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
* leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
* @returns The method `lastKey()` returns the id of the rightmost node in the binary tree if the comparison between
* the values at index 0 and 1 is less than, otherwise it returns the id of the leftmost node. If the comparison is
* equal, it returns the id of the rightmost node. If there are no nodes in the tree, it returns 0.
* The function returns the key of the rightmost node if the comparison between two values is less than, the key of the
* leftmost node if the comparison is greater than, and the key of the rightmost node otherwise.
* @returns The method `lastKey()` returns the key of the rightmost node in the binary tree if the comparison between
* the values at index 0 and 1 is less than, otherwise it returns the key of the leftmost node. If the comparison is
* equal, it returns the key of the rightmost node. If there are no nodes in the tree, it returns 0.
*/

@@ -231,14 +231,14 @@ lastKey() {

if (this._compare(0, 1) === CP.lt)
return (_b = (_a = this.getRightMost()) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : 0;
return (_b = (_a = this.getRightMost()) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : 0;
else if (this._compare(0, 1) === CP.gt)
return (_d = (_c = this.getLeftMost()) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : 0;
return (_d = (_c = this.getLeftMost()) === null || _c === void 0 ? void 0 : _c.key) !== null && _d !== void 0 ? _d : 0;
else
return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : 0;
return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.key) !== null && _f !== void 0 ? _f : 0;
}
/**
* The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or an
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or an
* `N` type. It represents the property of the binary tree node that you want to compare with.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use for comparison. If not provided, it defaults to `'id'`.
* specifies the property name to use for comparison. If not provided, it defaults to `'key'`.
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to

@@ -249,3 +249,3 @@ * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`

*/
getNodes(nodeProperty, propertyName = 'id', onlyOne) {
getNodes(nodeProperty, propertyName = 'key', onlyOne) {
if (!this.root)

@@ -260,6 +260,6 @@ return [];

return;
if (propertyName === 'id') {
if (this._compare(cur.id, nodeProperty) === CP.gt)
if (propertyName === 'key') {
if (this._compare(cur.key, nodeProperty) === CP.gt)
cur.left && _traverse(cur.left);
if (this._compare(cur.id, nodeProperty) === CP.lt)
if (this._compare(cur.key, nodeProperty) === CP.lt)
cur.right && _traverse(cur.right);

@@ -281,6 +281,6 @@ }

return result;
if (propertyName === 'id') {
if (this._compare(cur.id, nodeProperty) === CP.gt)
if (propertyName === 'key') {
if (this._compare(cur.key, nodeProperty) === CP.gt)
cur.left && queue.push(cur.left);
if (this._compare(cur.id, nodeProperty) === CP.lt)
if (this._compare(cur.key, nodeProperty) === CP.lt)
cur.right && queue.push(cur.right);

@@ -301,5 +301,5 @@ }

* less than a given node.
* @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} beginNode - The `beginNode` parameter can be one of the following:
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use for calculating the sum. If not provided, it defaults to `'id'`.
* specifies the property name to use for calculating the sum. If not provided, it defaults to `'key'`.
* @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the

@@ -309,5 +309,5 @@ * binary tree that have a lesser value than the specified `beginNode` based on the `propertyName`.

lesserSum(beginNode, propertyName) {
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
if (typeof beginNode === 'number')
beginNode = this.get(beginNode, 'id');
beginNode = this.get(beginNode, 'key');
if (!beginNode)

@@ -317,11 +317,11 @@ return 0;

return 0;
const id = beginNode.id;
const key = beginNode.key;
const getSumByPropertyName = (cur) => {
let needSum;
switch (propertyName) {
case 'id':
needSum = cur.id;
case 'key':
needSum = cur.key;
break;
default:
needSum = cur.id;
needSum = cur.key;
break;

@@ -334,3 +334,3 @@ }

const _traverse = (cur) => {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.eq) {

@@ -364,3 +364,3 @@ if (cur.right)

if (cur) {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.eq) {

@@ -395,4 +395,4 @@ if (cur.right)

* have a greater value than a given node.
* @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be either of type `N` (a generic type),
* `BinaryTreeNodeId`, or `null`. It represents the node in the binary tree to which the delta value will be added.
* @param {N | BinaryTreeNodeKey | null} node - The `node` parameter can be either of type `N` (a generic type),
* `BinaryTreeNodeKey`, or `null`. It represents the node in the binary tree to which the delta value will be added.
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of

@@ -402,12 +402,12 @@ * each greater node should be increased.

* specifies the property name of the nodes in the binary tree that you want to update. If not provided, it defaults to
* 'id'.
* 'key'.
* @returns a boolean value.
*/
allGreaterNodesAdd(node, delta, propertyName) {
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
if (typeof node === 'number')
node = this.get(node, 'id');
node = this.get(node, 'key');
if (!node)
return false;
const id = node.id;
const key = node.key;
if (!this.root)

@@ -417,7 +417,7 @@ return false;

switch (propertyName) {
case 'id':
cur.id += delta;
case 'key':
cur.key += delta;
break;
default:
cur.id += delta;
cur.key += delta;
break;

@@ -428,3 +428,3 @@ }

const _traverse = (cur) => {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.gt)

@@ -434,5 +434,5 @@ _sumByPropertyName(cur);

return;
if (cur.left && this._compare(cur.left.id, id) === CP.gt)
if (cur.left && this._compare(cur.left.key, key) === CP.gt)
_traverse(cur.left);
if (cur.right && this._compare(cur.right.id, id) === CP.gt)
if (cur.right && this._compare(cur.right.key, key) === CP.gt)
_traverse(cur.right);

@@ -448,8 +448,8 @@ };

if (cur) {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.gt)
_sumByPropertyName(cur);
if (cur.left && this._compare(cur.left.id, id) === CP.gt)
if (cur.left && this._compare(cur.left.key, key) === CP.gt)
queue.push(cur.left);
if (cur.right && this._compare(cur.right.id, id) === CP.gt)
if (cur.right && this._compare(cur.right.key, key) === CP.gt)
queue.push(cur.right);

@@ -486,3 +486,3 @@ }

const midNode = sorted[m];
this.add(midNode.id, midNode.val);
this.add(midNode.key, midNode.val);
buildBalanceBST(l, m - 1);

@@ -503,3 +503,3 @@ buildBalanceBST(m + 1, r);

const midNode = sorted[m];
this.add(midNode.id, midNode.val);
this.add(midNode.key, midNode.val);
stack.push([m + 1, r]);

@@ -566,4 +566,4 @@ stack.push([l, m - 1]);

* greater than, less than, or equal to the second ID.
* @param {BinaryTreeNodeId} a - a is a BinaryTreeNodeId, which represents the identifier of a binary tree node.
* @param {BinaryTreeNodeId} b - The parameter "b" in the above code refers to a BinaryTreeNodeId.
* @param {BinaryTreeNodeKey} a - a is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
* @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
* @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less

@@ -570,0 +570,0 @@ * than), or CP.eq (equal).

@@ -1,2 +0,2 @@

import { BinaryTreeNodeId, RBColor, RBTreeNodeNested, RBTreeOptions } from '../../types';
import { BinaryTreeNodeKey, RBColor, RBTreeNodeNested, RBTreeOptions } from '../../types';
import { IRBTree, IRBTreeNode } from '../../interfaces';

@@ -6,3 +6,3 @@ import { BST, BSTNode } from './bst';

private _color;
constructor(id: BinaryTreeNodeId, val?: V);
constructor(key: BinaryTreeNodeKey, val?: V);
get color(): RBColor;

@@ -13,3 +13,3 @@ set color(value: RBColor);

constructor(options?: RBTreeOptions);
createNode(id: BinaryTreeNodeId, val?: N['val']): N;
createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
}
import { RBColor } from '../../types';
import { BST, BSTNode } from './bst';
export class RBTreeNode extends BSTNode {
constructor(id, val) {
super(id, val);
constructor(key, val) {
super(key, val);
this._color = RBColor.RED;

@@ -19,5 +19,5 @@ }

}
createNode(id, val) {
return new RBTreeNode(id, val);
createNode(key, val) {
return new RBTreeNode(key, val);
}
}

@@ -8,3 +8,3 @@ /**

*/
import type { BinaryTreeNodeId, TreeMultisetNodeNested, TreeMultisetOptions } from '../../types';
import type { BinaryTreeNodeKey, TreeMultisetNodeNested, TreeMultisetOptions } from '../../types';
import { BinaryTreeDeletedResult, DFSOrderPattern } from '../../types';

@@ -15,4 +15,4 @@ import { ITreeMultiset, ITreeMultisetNode } from '../../interfaces';

/**
* The constructor function initializes a BinaryTreeNode object with an id, value, and count.
* @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
* The constructor function initializes a BinaryTreeNode object with an key, value, and count.
* @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
* of the binary tree node.

@@ -25,3 +25,3 @@ * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value of the binary

*/
constructor(id: BinaryTreeNodeId, val?: V, count?: number);
constructor(key: BinaryTreeNodeKey, val?: V, count?: number);
private _count;

@@ -45,4 +45,4 @@ get count(): number;

/**
* The function creates a new BSTNode with the given id, value, and count.
* @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
* The function creates a new BSTNode with the given key, value, and count.
* @param {BinaryTreeNodeKey} key - The key parameter is the unique identifier for the binary tree node. It is used to
* distinguish one node from another in the tree.

@@ -52,5 +52,5 @@ * @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.

* occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
* @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
* @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
*/
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
/**

@@ -67,3 +67,3 @@ * The function swaps the location of two nodes in a tree data structure.

* necessary.
* @param {BinaryTreeNodeId | N} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId` or a `N` (which
* @param {BinaryTreeNodeKey | N} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N` (which
* represents a `BinaryTreeNode`).

@@ -75,3 +75,3 @@ * @param [val] - The `val` parameter represents the value to be added to the binary tree node.

*/
add(idOrNode: BinaryTreeNodeId | N | null, val?: N['val'], count?: number): N | null | undefined;
add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val'], count?: number): N | null | undefined;
/**

@@ -90,10 +90,10 @@ * The function adds a new node to a binary tree if there is an available slot on the left or right side of the parent

* the inserted nodes.
* @param {(BinaryTreeNodeId | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeId or BinaryTreeNode
* @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
* objects, or null values.
* @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
* the nodes being added. It is used when adding nodes using the `idOrNode` and `data` arguments in the `this.add()`
* the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()`
* method. If provided, the `data` array should
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
*/
addMany(idsOrNodes: (BinaryTreeNodeId | null)[] | (N | null)[], data?: N['val'][]): (N | null | undefined)[];
addMany(idsOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][]): (N | null | undefined)[];
/**

@@ -108,3 +108,3 @@ * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then

* node that needs to be balanced.
* @param {N | BinaryTreeNodeId | null} nodeOrId - The `nodeOrId` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:
* @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines

@@ -115,3 +115,3 @@ * whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will

*/
remove(nodeOrId: N | BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
remove(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
/**

@@ -128,13 +128,13 @@ * The function `getSubTreeCount` calculates the number of nodes and the sum of their counts in a subtree, using either

* recursively or iteratively.
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeId` (a unique identifier for a node in the binary tree) or
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeKey` (a unique identifier for a node in the binary tree) or
* `null` if the subtree is empty.
* @returns the sum of the count values of all nodes in the subtree rooted at `subTreeRoot`.
*/
subTreeSumCount(subTreeRoot: N | BinaryTreeNodeId | null): number;
subTreeSumCount(subTreeRoot: N | BinaryTreeNodeKey | null): number;
/**
* The function `subTreeAddCount` recursively or iteratively traverses a binary tree and adds a given delta value to
* the `count` property of each node.
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeId` (a unique identifier for a node in the binary tree), a
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeKey` (a unique identifier for a node in the binary tree), a
* `BinaryTreeNode` object, or `null` if the subtree is empty.

@@ -145,7 +145,7 @@ * @param {number} delta - The delta parameter is a number that represents the amount by which the count of each node

*/
subTreeAddCount(subTreeRoot: N | BinaryTreeNodeId | null, delta: number): boolean;
subTreeAddCount(subTreeRoot: N | BinaryTreeNodeKey | null, delta: number): boolean;
/**
* The function `getNodesByCount` returns an array of nodes that have a specific count property, either recursively or
* using a queue.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
* `N`. It represents the property of the nodes that you want to search for.

@@ -157,3 +157,3 @@ * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to

*/
getNodesByCount(nodeProperty: BinaryTreeNodeId | N, onlyOne?: boolean): N[];
getNodesByCount(nodeProperty: BinaryTreeNodeKey | N, onlyOne?: boolean): N[];
/**

@@ -202,10 +202,10 @@ * The BFSCount function returns an array of counts from a breadth-first search of nodes.

* value than a given node.
* @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} beginNode - The `beginNode` parameter can be one of the following:
* @returns the sum of the counts of nodes in the binary tree that have a lesser value than the given beginNode.
*/
lesserSumCount(beginNode: N | BinaryTreeNodeId | null): number;
lesserSumCount(beginNode: N | BinaryTreeNodeKey | null): number;
/**
* The function `allGreaterNodesAddCount` updates the count property of all nodes in a binary tree that have an ID
* greater than a given ID by a specified delta value.
* @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} node - The `node` parameter can be one of the following:
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the `count` property

@@ -215,3 +215,3 @@ * of each node should be increased.

*/
allGreaterNodesAddCount(node: N | BinaryTreeNodeId | null, delta: number): boolean;
allGreaterNodesAddCount(node: N | BinaryTreeNodeKey | null, delta: number): boolean;
/**

@@ -218,0 +218,0 @@ * The clear() function clears the data and sets the count to 0.

@@ -5,4 +5,4 @@ import { CP, FamilyPosition, LoopType } from '../../types';

/**
* The constructor function initializes a BinaryTreeNode object with an id, value, and count.
* @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
* The constructor function initializes a BinaryTreeNode object with an key, value, and count.
* @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
* of the binary tree node.

@@ -15,4 +15,4 @@ * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value of the binary

*/
constructor(id, val, count = 1) {
super(id, val);
constructor(key, val, count = 1) {
super(key, val);
this._count = count;

@@ -45,4 +45,4 @@ }

/**
* The function creates a new BSTNode with the given id, value, and count.
* @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
* The function creates a new BSTNode with the given key, value, and count.
* @param {BinaryTreeNodeKey} key - The key parameter is the unique identifier for the binary tree node. It is used to
* distinguish one node from another in the tree.

@@ -52,6 +52,6 @@ * @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.

* occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
* @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
* @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
*/
createNode(id, val, count) {
return new TreeMultisetNode(id, val, count);
createNode(key, val, count) {
return new TreeMultisetNode(key, val, count);
}

@@ -66,11 +66,11 @@ /**

swapLocation(srcNode, destNode) {
const { id, val, count, height } = destNode;
const tempNode = this.createNode(id, val, count);
const { key, val, count, height } = destNode;
const tempNode = this.createNode(key, val, count);
if (tempNode) {
tempNode.height = height;
destNode.id = srcNode.id;
destNode.key = srcNode.key;
destNode.val = srcNode.val;
destNode.count = srcNode.count;
destNode.height = srcNode.height;
srcNode.id = tempNode.id;
srcNode.key = tempNode.key;
srcNode.val = tempNode.val;

@@ -85,3 +85,3 @@ srcNode.count = tempNode.count;

* necessary.
* @param {BinaryTreeNodeId | N} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId` or a `N` (which
* @param {BinaryTreeNodeKey | N} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N` (which
* represents a `BinaryTreeNode`).

@@ -93,13 +93,13 @@ * @param [val] - The `val` parameter represents the value to be added to the binary tree node.

*/
add(idOrNode, val, count) {
add(keyOrNode, val, count) {
count = count !== null && count !== void 0 ? count : 1;
let inserted = undefined, newNode;
if (idOrNode instanceof TreeMultisetNode) {
newNode = this.createNode(idOrNode.id, idOrNode.val, idOrNode.count);
if (keyOrNode instanceof TreeMultisetNode) {
newNode = this.createNode(keyOrNode.key, keyOrNode.val, keyOrNode.count);
}
else if (idOrNode === null) {
else if (keyOrNode === null) {
newNode = null;
}
else {
newNode = this.createNode(idOrNode, val, count);
newNode = this.createNode(keyOrNode, val, count);
}

@@ -118,3 +118,3 @@ if (!this.root) {

if (newNode) {
if (this._compare(cur.id, newNode.id) === CP.eq) {
if (this._compare(cur.key, newNode.key) === CP.eq) {
cur.val = newNode.val;

@@ -126,3 +126,3 @@ cur.count += newNode.count;

}
else if (this._compare(cur.id, newNode.id) === CP.gt) {
else if (this._compare(cur.key, newNode.key) === CP.gt) {
// Traverse left of the node

@@ -143,3 +143,3 @@ if (cur.left === undefined) {

}
else if (this._compare(cur.id, newNode.id) === CP.lt) {
else if (this._compare(cur.key, newNode.key) === CP.lt) {
// Traverse right of the node

@@ -212,6 +212,6 @@ if (cur.right === undefined) {

* the inserted nodes.
* @param {(BinaryTreeNodeId | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeId or BinaryTreeNode
* @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
* objects, or null values.
* @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
* the nodes being added. It is used when adding nodes using the `idOrNode` and `data` arguments in the `this.add()`
* the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()`
* method. If provided, the `data` array should

@@ -223,12 +223,12 @@ * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.

for (let i = 0; i < idsOrNodes.length; i++) {
const idOrNode = idsOrNodes[i];
if (idOrNode instanceof TreeMultisetNode) {
inserted.push(this.add(idOrNode.id, idOrNode.val, idOrNode.count));
const keyOrNode = idsOrNodes[i];
if (keyOrNode instanceof TreeMultisetNode) {
inserted.push(this.add(keyOrNode.key, keyOrNode.val, keyOrNode.count));
continue;
}
if (idOrNode === null) {
if (keyOrNode === null) {
inserted.push(this.add(NaN, null, 0));
continue;
}
inserted.push(this.add(idOrNode, data === null || data === void 0 ? void 0 : data[i], 1));
inserted.push(this.add(keyOrNode, data === null || data === void 0 ? void 0 : data[i], 1));
}

@@ -253,3 +253,3 @@ return inserted;

const midNode = sorted[m];
this.add(midNode.id, midNode.val, midNode.count);
this.add(midNode.key, midNode.val, midNode.count);
buildBalanceBST(l, m - 1);

@@ -270,3 +270,3 @@ buildBalanceBST(m + 1, r);

const midNode = sorted[m];
this.add(midNode.id, midNode.val, midNode.count);
this.add(midNode.key, midNode.val, midNode.count);
stack.push([m + 1, r]);

@@ -283,3 +283,3 @@ stack.push([l, m - 1]);

* node that needs to be balanced.
* @param {N | BinaryTreeNodeId | null} nodeOrId - The `nodeOrId` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:
* @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines

@@ -290,7 +290,7 @@ * whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will

*/
remove(nodeOrId, ignoreCount) {
remove(nodeOrKey, ignoreCount) {
const bstDeletedResult = [];
if (!this.root)
return bstDeletedResult;
const curr = this.get(nodeOrId);
const curr = this.get(nodeOrKey);
if (!curr)

@@ -383,4 +383,4 @@ return bstDeletedResult;

* recursively or iteratively.
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeId` (a unique identifier for a node in the binary tree) or
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeKey` (a unique identifier for a node in the binary tree) or
* `null` if the subtree is empty.

@@ -391,3 +391,3 @@ * @returns the sum of the count values of all nodes in the subtree rooted at `subTreeRoot`.

if (typeof subTreeRoot === 'number')
subTreeRoot = this.get(subTreeRoot, 'id');
subTreeRoot = this.get(subTreeRoot, 'key');
if (!subTreeRoot)

@@ -418,4 +418,4 @@ return 0;

* the `count` property of each node.
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeId` (a unique identifier for a node in the binary tree), a
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeKey` (a unique identifier for a node in the binary tree), a
* `BinaryTreeNode` object, or `null` if the subtree is empty.

@@ -428,3 +428,3 @@ * @param {number} delta - The delta parameter is a number that represents the amount by which the count of each node

if (typeof subTreeRoot === 'number')
subTreeRoot = this.get(subTreeRoot, 'id');
subTreeRoot = this.get(subTreeRoot, 'key');
if (!subTreeRoot)

@@ -458,3 +458,3 @@ return false;

* using a queue.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
* `N`. It represents the property of the nodes that you want to search for.

@@ -562,3 +562,3 @@ * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to

* value than a given node.
* @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} beginNode - The `beginNode` parameter can be one of the following:
* @returns the sum of the counts of nodes in the binary tree that have a lesser value than the given beginNode.

@@ -568,3 +568,3 @@ */

if (typeof beginNode === 'number')
beginNode = this.get(beginNode, 'id');
beginNode = this.get(beginNode, 'key');
if (!beginNode)

@@ -574,7 +574,7 @@ return 0;

return 0;
const id = beginNode.id;
const key = beginNode.key;
let sum = 0;
if (this.loopType === LoopType.RECURSIVE) {
const _traverse = (cur) => {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.eq) {

@@ -608,3 +608,3 @@ if (cur.right)

if (cur) {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.eq) {

@@ -639,3 +639,3 @@ if (cur.right)

* greater than a given ID by a specified delta value.
* @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} node - The `node` parameter can be one of the following:
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the `count` property

@@ -647,6 +647,6 @@ * of each node should be increased.

if (typeof node === 'number')
node = this.get(node, 'id');
node = this.get(node, 'key');
if (!node)
return false;
const id = node.id;
const key = node.key;
if (!this.root)

@@ -656,3 +656,3 @@ return false;

const _traverse = (cur) => {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.gt)

@@ -662,5 +662,5 @@ cur.count += delta;

return;
if (cur.left && this._compare(cur.left.id, id) === CP.gt)
if (cur.left && this._compare(cur.left.key, key) === CP.gt)
_traverse(cur.left);
if (cur.right && this._compare(cur.right.id, id) === CP.gt)
if (cur.right && this._compare(cur.right.key, key) === CP.gt)
_traverse(cur.right);

@@ -676,8 +676,8 @@ };

if (cur) {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.gt)
cur.count += delta;
if (cur.left && this._compare(cur.left.id, id) === CP.gt)
if (cur.left && this._compare(cur.left.key, key) === CP.gt)
queue.push(cur.left);
if (cur.right && this._compare(cur.right.id, id) === CP.gt)
if (cur.right && this._compare(cur.right.key, key) === CP.gt)
queue.push(cur.right);

@@ -684,0 +684,0 @@ }

@@ -1,7 +0,7 @@

import type { DijkstraResult, VertexId } from '../../types';
import type { DijkstraResult, VertexKey } from '../../types';
import { IAbstractGraph } from '../../interfaces';
export declare abstract class AbstractVertex<V = any> {
/**
* The function is a protected constructor that takes an id and an optional value as parameters.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* The function is a protected constructor that takes an key and an optional value as parameters.
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex object.

@@ -11,6 +11,6 @@ * @param {V} [val] - The parameter "val" is an optional parameter of type V. It is used to assign a value to the

*/
protected constructor(id: VertexId, val?: V);
private _id;
get id(): VertexId;
set id(v: VertexId);
protected constructor(key: VertexKey, val?: V);
private _key;
get key(): VertexKey;
set key(v: VertexKey);
private _val;

@@ -52,10 +52,10 @@ get val(): V | undefined;

private _vertices;
get vertices(): Map<VertexId, V>;
get vertices(): Map<VertexKey, V>;
/**
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param id
* @param key
* @param val
*/
abstract createVertex(id: VertexId, val?: V): V;
abstract createVertex(key: VertexKey, val?: V): V;
/**

@@ -69,73 +69,73 @@ * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.

*/
abstract createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
abstract createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E;
abstract removeEdge(edge: E): E | null;
abstract getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
abstract degreeOf(vertexOrId: V | VertexId): number;
abstract getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
abstract degreeOf(vertexOrKey: V | VertexKey): number;
abstract edgeSet(): E[];
abstract edgesOf(vertexOrId: V | VertexId): E[];
abstract getNeighbors(vertexOrId: V | VertexId): V[];
abstract edgesOf(vertexOrKey: V | VertexKey): E[];
abstract getNeighbors(vertexOrKey: V | VertexKey): V[];
abstract getEndsOfEdge(edge: E): [V, V] | null;
/**
* The function "getVertex" returns the vertex with the specified ID or null if it doesn't exist.
* @param {VertexId} vertexId - The `vertexId` parameter is the identifier of the vertex that you want to retrieve from
* @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
* the `_vertices` map.
* @returns The method `getVertex` returns the vertex with the specified `vertexId` if it exists in the `_vertices`
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
* map. If the vertex does not exist, it returns `null`.
*/
getVertex(vertexId: VertexId): V | null;
getVertex(vertexKey: VertexKey): V | null;
/**
* The function checks if a vertex exists in a graph.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns a boolean value.
*/
hasVertex(vertexOrId: V | VertexId): boolean;
hasVertex(vertexOrKey: V | VertexKey): boolean;
addVertex(vertex: V): boolean;
addVertex(id: VertexId, val?: V['val']): boolean;
addVertex(key: VertexKey, val?: V['val']): boolean;
/**
* The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns The method is returning a boolean value.
*/
removeVertex(vertexOrId: V | VertexId): boolean;
removeVertex(vertexOrKey: V | VertexKey): boolean;
/**
* The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
* @param {V[] | VertexId[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
* of vertex IDs (`VertexId[]`).
* @param {V[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
* of vertex IDs (`VertexKey[]`).
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
* were removed.
*/
removeAllVertices(vertices: V[] | VertexId[]): boolean;
removeAllVertices(vertices: V[] | VertexKey[]): boolean;
/**
* The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
* @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the unique
* @param {VertexKey | V} v1 - The parameter v1 can be either a VertexKey or a V. A VertexKey represents the unique
* identifier of a vertex in a graph, while V represents the type of the vertex object itself.
* @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
* `VertexId` or a `V` type, which represents the type of the vertex.
* @param {VertexKey | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
* `VertexKey` or a `V` type, which represents the type of the vertex.
* @returns A boolean value is being returned.
*/
hasEdge(v1: VertexId | V, v2: VertexId | V): boolean;
hasEdge(v1: VertexKey | V, v2: VertexKey | V): boolean;
addEdge(edge: E): boolean;
addEdge(src: V | VertexId, dest: V | VertexId, weight?: number, val?: E['val']): boolean;
addEdge(src: V | VertexKey, dest: V | VertexKey, weight?: number, val?: E['val']): boolean;
/**
* The function sets the weight of an edge between two vertices in a graph.
* @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
* @param {VertexKey | V} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `V` object. It represents
* the source vertex of the edge.
* @param {VertexId | V} destOrId - The `destOrId` parameter represents the destination vertex of the edge. It can be
* either a `VertexId` or a vertex object `V`.
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrId)
* and the destination vertex (destOrId).
* @param {VertexKey | V} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
* either a `VertexKey` or a vertex object `V`.
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
* and the destination vertex (destOrKey).
* @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
* the weight of the edge and return true. If the edge does not exist, the function will return false.
*/
setEdgeWeight(srcOrId: VertexId | V, destOrId: VertexId | V, weight: number): boolean;
setEdgeWeight(srcOrKey: VertexKey | V, destOrKey: VertexKey | V, weight: number): boolean;
/**
* The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
* It is the starting vertex for finding paths.
* @param {V | VertexId} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexKey} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
* @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`V[][]`).
*/
getAllPathsBetween(v1: V | VertexId, v2: V | VertexId): V[][];
getAllPathsBetween(v1: V | VertexKey, v2: V | VertexKey): V[][];
/**

@@ -150,4 +150,4 @@ * The function calculates the sum of weights along a given path.

* weights or using a breadth-first search algorithm.
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
* @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
* @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
* @param {V | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
* you want to find the minimum cost or weight from the source vertex `v1`.

@@ -162,9 +162,9 @@ * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.

*/
getMinCostBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): number | null;
getMinCostBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): number | null;
/**
* The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
* using a breadth-first search algorithm.
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
* object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexId} v2 - V | VertexId - The second vertex or vertex ID between which we want to find the minimum
* @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
* object (`V`) or a vertex ID (`VertexKey`).
* @param {V | VertexKey} v2 - V | VertexKey - The second vertex or vertex ID between which we want to find the minimum
* path.

@@ -177,3 +177,3 @@ * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the

*/
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
getMinPathBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): V[] | null;
/**

@@ -187,5 +187,5 @@ * Dijkstra algorithm time: O(VE) space: O(V + E)

* a graph without using a heap data structure.
* @param {V | VertexId} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
* @param {V | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
* vertex object or a vertex ID.
* @param {V | VertexId | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
* @param {V | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
* parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its

@@ -201,3 +201,3 @@ * identifier. If no destination is provided, the value is set to `null`.

*/
dijkstraWithoutHeap(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
dijkstraWithoutHeap(src: V | VertexKey, dest?: V | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
/**

@@ -216,5 +216,5 @@ * Dijkstra algorithm time: O(logVE) space: O(V + E)

* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
* @param {V | VertexId} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
* @param {V | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
* start. It can be either a vertex object or a vertex ID.
* @param {V | VertexId | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
* @param {V | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm

@@ -230,3 +230,3 @@ * will calculate the shortest paths to all other vertices from the source vertex.

*/
dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
dijkstra(src: V | VertexKey, dest?: V | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
/**

@@ -243,3 +243,3 @@ * BellmanFord time:O(VE) space:O(V)

* all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
* @param {V | VertexId} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
* @param {V | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
* start calculating the shortest paths. It can be either a vertex object or a vertex ID.

@@ -254,3 +254,3 @@ * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.

*/
bellmanFord(src: V | VertexId, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean): {
bellmanFord(src: V | VertexKey, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean): {
hasNegativeCycle: boolean | undefined;

@@ -341,5 +341,5 @@ distMap: Map<V, number>;

protected _addVertexOnly(newVertex: V): boolean;
protected _getVertex(vertexOrId: VertexId | V): V | null;
protected _getVertexId(vertexOrId: V | VertexId): VertexId;
protected _setVertices(value: Map<VertexId, V>): void;
protected _getVertex(vertexOrKey: VertexKey | V): V | null;
protected _getVertexKey(vertexOrKey: V | VertexKey): VertexKey;
protected _setVertices(value: Map<VertexKey, V>): void;
}

@@ -12,4 +12,4 @@ /**

/**
* The function is a protected constructor that takes an id and an optional value as parameters.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* The function is a protected constructor that takes an key and an optional value as parameters.
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex object.

@@ -19,11 +19,11 @@ * @param {V} [val] - The parameter "val" is an optional parameter of type V. It is used to assign a value to the

*/
constructor(id, val) {
this._id = id;
constructor(key, val) {
this._key = key;
this._val = val;
}
get id() {
return this._id;
get key() {
return this._key;
}
set id(v) {
this._id = v;
set key(v) {
this._key = v;
}

@@ -89,25 +89,25 @@ get val() {

* The function "getVertex" returns the vertex with the specified ID or null if it doesn't exist.
* @param {VertexId} vertexId - The `vertexId` parameter is the identifier of the vertex that you want to retrieve from
* @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
* the `_vertices` map.
* @returns The method `getVertex` returns the vertex with the specified `vertexId` if it exists in the `_vertices`
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
* map. If the vertex does not exist, it returns `null`.
*/
getVertex(vertexId) {
return this._vertices.get(vertexId) || null;
getVertex(vertexKey) {
return this._vertices.get(vertexKey) || null;
}
/**
* The function checks if a vertex exists in a graph.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns a boolean value.
*/
hasVertex(vertexOrId) {
return this._vertices.has(this._getVertexId(vertexOrId));
hasVertex(vertexOrKey) {
return this._vertices.has(this._getVertexKey(vertexOrKey));
}
addVertex(idOrVertex, val) {
if (idOrVertex instanceof AbstractVertex) {
return this._addVertexOnly(idOrVertex);
addVertex(keyOrVertex, val) {
if (keyOrVertex instanceof AbstractVertex) {
return this._addVertexOnly(keyOrVertex);
}
else {
const newVertex = this.createVertex(idOrVertex, val);
const newVertex = this.createVertex(keyOrVertex, val);
return this._addVertexOnly(newVertex);

@@ -118,14 +118,14 @@ }

* The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns The method is returning a boolean value.
*/
removeVertex(vertexOrId) {
const vertexId = this._getVertexId(vertexOrId);
return this._vertices.delete(vertexId);
removeVertex(vertexOrKey) {
const vertexKey = this._getVertexKey(vertexOrKey);
return this._vertices.delete(vertexKey);
}
/**
* The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
* @param {V[] | VertexId[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
* of vertex IDs (`VertexId[]`).
* @param {V[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
* of vertex IDs (`VertexKey[]`).
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices

@@ -143,6 +143,6 @@ * were removed.

* The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
* @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the unique
* @param {VertexKey | V} v1 - The parameter v1 can be either a VertexKey or a V. A VertexKey represents the unique
* identifier of a vertex in a graph, while V represents the type of the vertex object itself.
* @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
* `VertexId` or a `V` type, which represents the type of the vertex.
* @param {VertexKey | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
* `VertexKey` or a `V` type, which represents the type of the vertex.
* @returns A boolean value is being returned.

@@ -163,5 +163,5 @@ */

if (srcOrEdge instanceof AbstractVertex)
srcOrEdge = srcOrEdge.id;
srcOrEdge = srcOrEdge.key;
if (dest instanceof AbstractVertex)
dest = dest.id;
dest = dest.key;
const newEdge = this.createEdge(srcOrEdge, dest, weight, val);

@@ -171,3 +171,3 @@ return this._addEdgeOnly(newEdge);

else {
throw new Error('dest must be a Vertex or vertex id while srcOrEdge is an Edge');
throw new Error('dest must be a Vertex or vertex key while srcOrEdge is an Edge');
}

@@ -178,13 +178,13 @@ }

* The function sets the weight of an edge between two vertices in a graph.
* @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
* @param {VertexKey | V} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `V` object. It represents
* the source vertex of the edge.
* @param {VertexId | V} destOrId - The `destOrId` parameter represents the destination vertex of the edge. It can be
* either a `VertexId` or a vertex object `V`.
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrId)
* and the destination vertex (destOrId).
* @param {VertexKey | V} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
* either a `VertexKey` or a vertex object `V`.
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
* and the destination vertex (destOrKey).
* @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
* the weight of the edge and return true. If the edge does not exist, the function will return false.
*/
setEdgeWeight(srcOrId, destOrId, weight) {
const edge = this.getEdge(srcOrId, destOrId);
setEdgeWeight(srcOrKey, destOrKey, weight) {
const edge = this.getEdge(srcOrKey, destOrKey);
if (edge) {

@@ -200,5 +200,5 @@ edge.weight = weight;

* The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
* It is the starting vertex for finding paths.
* @param {V | VertexId} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexKey} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
* @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`V[][]`).

@@ -247,4 +247,4 @@ */

* weights or using a breadth-first search algorithm.
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
* @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
* @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
* @param {V | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
* you want to find the minimum cost or weight from the source vertex `v1`.

@@ -306,5 +306,5 @@ * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.

* using a breadth-first search algorithm.
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
* object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexId} v2 - V | VertexId - The second vertex or vertex ID between which we want to find the minimum
* @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
* object (`V`) or a vertex ID (`VertexKey`).
* @param {V | VertexKey} v2 - V | VertexKey - The second vertex or vertex ID between which we want to find the minimum
* path.

@@ -371,5 +371,5 @@ * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the

* a graph without using a heap data structure.
* @param {V | VertexId} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
* @param {V | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
* vertex object or a vertex ID.
* @param {V | VertexId | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
* @param {V | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
* parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its

@@ -406,5 +406,5 @@ * identifier. If no destination is provided, the value is set to `null`.

for (const vertex of vertices) {
const vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex)
distMap.set(vertexOrId, Infinity);
const vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex)
distMap.set(vertexOrKey, Infinity);
}

@@ -428,6 +428,6 @@ distMap.set(srcVertex, 0);

for (const vertex of vertices) {
const vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex) {
const path = [vertexOrId];
let parent = preMap.get(vertexOrId);
const vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex) {
const path = [vertexOrKey];
let parent = preMap.get(vertexOrKey);
while (parent) {

@@ -502,5 +502,5 @@ path.push(parent);

* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
* @param {V | VertexId} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
* @param {V | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
* start. It can be either a vertex object or a vertex ID.
* @param {V | VertexId | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
* @param {V | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm

@@ -537,10 +537,10 @@ * will calculate the shortest paths to all other vertices from the source vertex.

for (const vertex of vertices) {
const vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex)
distMap.set(vertexOrId, Infinity);
const vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex)
distMap.set(vertexOrKey, Infinity);
}
const heap = new PriorityQueue({
comparator: (a, b) => a.id - b.id
comparator: (a, b) => a.key - b.key
});
heap.add({ id: 0, val: srcVertex });
heap.add({ key: 0, val: srcVertex });
distMap.set(srcVertex, 0);

@@ -555,6 +555,6 @@ preMap.set(srcVertex, null);

for (const vertex of vertices) {
const vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex) {
const path = [vertexOrId];
let parent = preMap.get(vertexOrId);
const vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex) {
const path = [vertexOrKey];
let parent = preMap.get(vertexOrKey);
while (parent) {

@@ -573,3 +573,3 @@ path.push(parent);

const curHeapNode = heap.poll();
const dist = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.id;
const dist = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.key;
const cur = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.val;

@@ -596,3 +596,3 @@ if (dist !== undefined) {

if (dist + weight < distSrcToNeighbor) {
heap.add({ id: dist + weight, val: neighbor });
heap.add({ key: dist + weight, val: neighbor });
preMap.set(neighbor, cur);

@@ -635,3 +635,3 @@ distMap.set(neighbor, dist + weight);

* all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
* @param {V | VertexId} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
* @param {V | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
* start calculating the shortest paths. It can be either a vertex object or a vertex ID.

@@ -702,6 +702,6 @@ * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.

for (const vertex of vertices) {
const vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex) {
const path = [vertexOrId];
let parent = preMap.get(vertexOrId);
const vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex) {
const path = [vertexOrKey];
let parent = preMap.get(vertexOrKey);
while (parent !== undefined) {

@@ -924,13 +924,13 @@ path.push(parent);

return false;
// throw (new Error('Duplicated vertex id is not allowed'));
// throw (new Error('Duplicated vertex key is not allowed'));
}
this._vertices.set(newVertex.id, newVertex);
this._vertices.set(newVertex.key, newVertex);
return true;
}
_getVertex(vertexOrId) {
const vertexId = this._getVertexId(vertexOrId);
return this._vertices.get(vertexId) || null;
_getVertex(vertexOrKey) {
const vertexKey = this._getVertexKey(vertexOrKey);
return this._vertices.get(vertexKey) || null;
}
_getVertexId(vertexOrId) {
return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
_getVertexKey(vertexOrKey) {
return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
}

@@ -937,0 +937,0 @@ _setVertices(value) {

import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
import type { VertexId } from '../../types';
import type { VertexKey } from '../../types';
import { IDirectedGraph } from '../../interfaces';

@@ -7,3 +7,3 @@ export declare class DirectedVertex<V = any> extends AbstractVertex<V> {

* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex within a graph or data structure.

@@ -13,3 +13,3 @@ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the

*/
constructor(id: VertexId, val?: V);
constructor(key: VertexKey, val?: V);
}

@@ -20,6 +20,6 @@ export declare class DirectedEdge<V = any> extends AbstractEdge<V> {

* and value.
* @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* a graph.
* @param {VertexId} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
* `VertexId`, which is likely a unique identifier for a vertex in a graph.
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.

@@ -29,9 +29,9 @@ * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value associated with

*/
constructor(src: VertexId, dest: VertexId, weight?: number, val?: V);
constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: V);
private _src;
get src(): VertexId;
set src(v: VertexId);
get src(): VertexKey;
set src(v: VertexKey);
private _dest;
get dest(): VertexId;
set dest(v: VertexId);
get dest(): VertexKey;
set dest(v: VertexKey);
}

@@ -53,10 +53,10 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVertex, E extends DirectedEdge<any> = DirectedEdge> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {

* The function creates a new vertex with an optional value and returns it.
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is of type `VertexId`, which
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
* could be a number or a string depending on how you want to identify your vertices.
* @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
* it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
* assigned the same value as the 'id' parameter
* assigned the same value as the 'key' parameter
* @returns a new instance of a DirectedVertex object, casted as type V.
*/
createVertex(id: VertexId, val?: V['val']): V;
createVertex(key: VertexKey, val?: V['val']): V;
/**

@@ -68,4 +68,4 @@ * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.

* The function creates a directed edge between two vertices with an optional weight and value.
* @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no

@@ -77,19 +77,19 @@ * weight is provided, it defaults to 1.

*/
createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E;
/**
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
* @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a vertex object or a vertex ID.
* @param {V | null | VertexId} destOrId - The `destOrId` parameter in the `getEdge` function represents the
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexId`), or `null` if the
* @param {V | null | VertexKey} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
* @param {V | null | VertexKey} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexKey`), or `null` if the
* destination is not specified.
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
*/
getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
getEdge(srcOrKey: V | null | VertexKey, destOrKey: V | null | VertexKey): E | null;
/**
* The function removes an edge between two vertices in a graph and returns the removed edge.
* @param {V | VertexId} srcOrId - The source vertex or its ID.
* @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex or its ID.
* @param {V | VertexKey} srcOrKey - The source vertex or its ID.
* @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
* @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
*/
removeEdgeSrcToDest(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
removeEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
/**

@@ -104,47 +104,47 @@ * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.

* The function removes edges between two vertices and returns the removed edges.
* @param {VertexId | V} v1 - The parameter `v1` can be either a `VertexId` or a `V`. A `VertexId` represents the
* @param {VertexKey | V} v1 - The parameter `v1` can be either a `VertexKey` or a `V`. A `VertexKey` represents the
* unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
* @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V` object. It is used to specify
* @param {VertexKey | V} v2 - The parameter `v2` represents either a `VertexKey` or a `V` object. It is used to specify
* the second vertex in the edge that needs to be removed.
* @returns an array of removed edges (E[]).
*/
removeEdgesBetween(v1: VertexId | V, v2: VertexId | V): E[];
removeEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[];
/**
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
*/
incomingEdgesOf(vertexOrId: V | VertexId): E[];
incomingEdgesOf(vertexOrKey: V | VertexKey): E[];
/**
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
*/
outgoingEdgesOf(vertexOrId: V | VertexId): E[];
outgoingEdgesOf(vertexOrKey: V | VertexKey): E[];
/**
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
*/
degreeOf(vertexOrId: VertexId | V): number;
degreeOf(vertexOrKey: VertexKey | V): number;
/**
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The number of incoming edges of the specified vertex or vertex ID.
*/
inDegreeOf(vertexOrId: VertexId | V): number;
inDegreeOf(vertexOrKey: VertexKey | V): number;
/**
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The number of outgoing edges from the specified vertex or vertex ID.
*/
outDegreeOf(vertexOrId: VertexId | V): number;
outDegreeOf(vertexOrKey: VertexKey | V): number;
/**
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The function `edgesOf` returns an array of edges.
*/
edgesOf(vertexOrId: VertexId | V): E[];
edgesOf(vertexOrKey: VertexKey | V): E[];
/**

@@ -164,16 +164,16 @@ * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.

* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
* @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
* find the destinations. It can be either a `V` object, a `VertexId` value, or `null`.
* @param {V | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
* find the destinations. It can be either a `V` object, a `VertexKey` value, or `null`.
* @returns an array of vertices (V[]).
*/
getDestinations(vertex: V | VertexId | null): V[];
getDestinations(vertex: V | VertexKey | null): V[];
/**
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
* in the sorted order, or null if the graph contains a cycle.
* @param {'vertex' | 'id'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'id'. If 'vertex' is
* specified, the vertices themselves will be used for sorting. If 'id' is specified, the ids of
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
* specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
*/
topologicalSort(propertyName?: 'vertex' | 'id'): Array<V | VertexId> | null;
topologicalSort(propertyName?: 'vertex' | 'key'): Array<V | VertexKey> | null;
/**

@@ -186,7 +186,7 @@ * The `edgeSet` function returns an array of all the edges in the graph.

* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns an array of vertices (V[]).
*/
getNeighbors(vertexOrId: V | VertexId): V[];
getNeighbors(vertexOrKey: V | VertexKey): V[];
/**

@@ -193,0 +193,0 @@ * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,

@@ -13,3 +13,3 @@ /**

* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex within a graph or data structure.

@@ -19,4 +19,4 @@ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the

*/
constructor(id, val) {
super(id, val);
constructor(key, val) {
super(key, val);
}

@@ -28,6 +28,6 @@ }

* and value.
* @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* a graph.
* @param {VertexId} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
* `VertexId`, which is likely a unique identifier for a vertex in a graph.
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.

@@ -76,11 +76,11 @@ * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value associated with

* The function creates a new vertex with an optional value and returns it.
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is of type `VertexId`, which
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
* could be a number or a string depending on how you want to identify your vertices.
* @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
* it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
* assigned the same value as the 'id' parameter
* assigned the same value as the 'key' parameter
* @returns a new instance of a DirectedVertex object, casted as type V.
*/
createVertex(id, val) {
return new DirectedVertex(id, val !== null && val !== void 0 ? val : id);
createVertex(key, val) {
return new DirectedVertex(key, val !== null && val !== void 0 ? val : key);
}

@@ -93,4 +93,4 @@ /**

* The function creates a directed edge between two vertices with an optional weight and value.
* @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no

@@ -107,17 +107,17 @@ * weight is provided, it defaults to 1.

* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
* @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a vertex object or a vertex ID.
* @param {V | null | VertexId} destOrId - The `destOrId` parameter in the `getEdge` function represents the
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexId`), or `null` if the
* @param {V | null | VertexKey} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
* @param {V | null | VertexKey} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexKey`), or `null` if the
* destination is not specified.
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
*/
getEdge(srcOrId, destOrId) {
getEdge(srcOrKey, destOrKey) {
let edges = [];
if (srcOrId !== null && destOrId !== null) {
const src = this._getVertex(srcOrId);
const dest = this._getVertex(destOrId);
if (srcOrKey !== null && destOrKey !== null) {
const src = this._getVertex(srcOrKey);
const dest = this._getVertex(destOrKey);
if (src && dest) {
const srcOutEdges = this._outEdgeMap.get(src);
if (srcOutEdges) {
edges = srcOutEdges.filter(edge => edge.dest === dest.id);
edges = srcOutEdges.filter(edge => edge.dest === dest.key);
}

@@ -130,9 +130,9 @@ }

* The function removes an edge between two vertices in a graph and returns the removed edge.
* @param {V | VertexId} srcOrId - The source vertex or its ID.
* @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex or its ID.
* @param {V | VertexKey} srcOrKey - The source vertex or its ID.
* @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
* @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
*/
removeEdgeSrcToDest(srcOrId, destOrId) {
const src = this._getVertex(srcOrId);
const dest = this._getVertex(destOrId);
removeEdgeSrcToDest(srcOrKey, destOrKey) {
const src = this._getVertex(srcOrKey);
const dest = this._getVertex(destOrKey);
let removed = null;

@@ -144,7 +144,7 @@ if (!src || !dest) {

if (srcOutEdges) {
arrayRemove(srcOutEdges, (edge) => edge.dest === dest.id);
arrayRemove(srcOutEdges, (edge) => edge.dest === dest.key);
}
const destInEdges = this._inEdgeMap.get(dest);
if (destInEdges) {
removed = arrayRemove(destInEdges, (edge) => edge.src === src.id)[0] || null;
removed = arrayRemove(destInEdges, (edge) => edge.src === src.key)[0] || null;
}

@@ -166,7 +166,7 @@ return removed;

if (srcOutEdges && srcOutEdges.length > 0) {
arrayRemove(srcOutEdges, (edge) => edge.src === src.id);
arrayRemove(srcOutEdges, (edge) => edge.src === src.key);
}
const destInEdges = this._inEdgeMap.get(dest);
if (destInEdges && destInEdges.length > 0) {
removed = arrayRemove(destInEdges, (edge) => edge.dest === dest.id)[0];
removed = arrayRemove(destInEdges, (edge) => edge.dest === dest.key)[0];
}

@@ -178,5 +178,5 @@ }

* The function removes edges between two vertices and returns the removed edges.
* @param {VertexId | V} v1 - The parameter `v1` can be either a `VertexId` or a `V`. A `VertexId` represents the
* @param {VertexKey | V} v1 - The parameter `v1` can be either a `VertexKey` or a `V`. A `VertexKey` represents the
* unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
* @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V` object. It is used to specify
* @param {VertexKey | V} v2 - The parameter `v2` represents either a `VertexKey` or a `V` object. It is used to specify
* the second vertex in the edge that needs to be removed.

@@ -197,8 +197,8 @@ * @returns an array of removed edges (E[]).

* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
*/
incomingEdgesOf(vertexOrId) {
const target = this._getVertex(vertexOrId);
incomingEdgesOf(vertexOrKey) {
const target = this._getVertex(vertexOrKey);
if (target) {

@@ -211,8 +211,8 @@ return this.inEdgeMap.get(target) || [];

* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
*/
outgoingEdgesOf(vertexOrId) {
const target = this._getVertex(vertexOrId);
outgoingEdgesOf(vertexOrKey) {
const target = this._getVertex(vertexOrKey);
if (target) {

@@ -225,31 +225,31 @@ return this._outEdgeMap.get(target) || [];

* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
*/
degreeOf(vertexOrId) {
return this.outDegreeOf(vertexOrId) + this.inDegreeOf(vertexOrId);
degreeOf(vertexOrKey) {
return this.outDegreeOf(vertexOrKey) + this.inDegreeOf(vertexOrKey);
}
/**
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The number of incoming edges of the specified vertex or vertex ID.
*/
inDegreeOf(vertexOrId) {
return this.incomingEdgesOf(vertexOrId).length;
inDegreeOf(vertexOrKey) {
return this.incomingEdgesOf(vertexOrKey).length;
}
/**
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The number of outgoing edges from the specified vertex or vertex ID.
*/
outDegreeOf(vertexOrId) {
return this.outgoingEdgesOf(vertexOrId).length;
outDegreeOf(vertexOrKey) {
return this.outgoingEdgesOf(vertexOrKey).length;
}
/**
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The function `edgesOf` returns an array of edges.
*/
edgesOf(vertexOrId) {
return [...this.outgoingEdgesOf(vertexOrId), ...this.incomingEdgesOf(vertexOrId)];
edgesOf(vertexOrKey) {
return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
}

@@ -274,4 +274,4 @@ /**

* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
* @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
* find the destinations. It can be either a `V` object, a `VertexId` value, or `null`.
* @param {V | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
* find the destinations. It can be either a `V` object, a `VertexKey` value, or `null`.
* @returns an array of vertices (V[]).

@@ -296,9 +296,9 @@ */

* in the sorted order, or null if the graph contains a cycle.
* @param {'vertex' | 'id'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'id'. If 'vertex' is
* specified, the vertices themselves will be used for sorting. If 'id' is specified, the ids of
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
* specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
*/
topologicalSort(propertyName) {
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
// When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued

@@ -334,4 +334,4 @@ // When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued

return null;
if (propertyName === 'id')
sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.id : vertex));
if (propertyName === 'key')
sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.key : vertex));
return sorted.reverse();

@@ -352,9 +352,9 @@ }

* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns an array of vertices (V[]).
*/
getNeighbors(vertexOrId) {
getNeighbors(vertexOrKey) {
const neighbors = [];
const vertex = this._getVertex(vertexOrId);
const vertex = this._getVertex(vertexOrKey);
if (vertex) {

@@ -361,0 +361,0 @@ const outEdges = this.outgoingEdgesOf(vertex);

@@ -1,7 +0,7 @@

import { MapGraphCoordinate, VertexId } from '../../types';
import { MapGraphCoordinate, VertexKey } from '../../types';
import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
export declare class MapVertex<V = any> extends DirectedVertex<V> {
/**
* The constructor function initializes an object with an id, latitude, longitude, and an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex.
* The constructor function initializes an object with an key, latitude, longitude, and an optional value.
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
* @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate

@@ -16,3 +16,3 @@ * that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive

*/
constructor(id: VertexId, lat: number, long: number, val?: V);
constructor(key: VertexKey, lat: number, long: number, val?: V);
private _lat;

@@ -29,5 +29,5 @@ get lat(): number;

* value.
* @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* a graph.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.

@@ -37,3 +37,3 @@ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store additional

*/
constructor(src: VertexId, dest: VertexId, weight?: number, val?: V);
constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: V);
}

@@ -58,4 +58,4 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E extends MapEdge = MapEdge> extends DirectedGraph<V, E> {

/**
* The function creates a new vertex with the given id, value, latitude, and longitude.
* @param {VertexId} id - The id parameter is the unique identifier for the vertex. It is of type VertexId, which could
* The function creates a new vertex with the given key, value, latitude, and longitude.
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
* be a string or a number depending on how you define it in your code.

@@ -69,7 +69,7 @@ * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It

*/
createVertex(id: VertexId, val?: V['val'], lat?: number, long?: number): V;
createVertex(key: VertexKey, val?: V['val'], lat?: number, long?: number): V;
/**
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
* @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
* created.

@@ -83,3 +83,3 @@ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It

*/
createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E;
}
import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
export class MapVertex extends DirectedVertex {
/**
* The constructor function initializes an object with an id, latitude, longitude, and an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex.
* The constructor function initializes an object with an key, latitude, longitude, and an optional value.
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
* @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate

@@ -15,4 +15,4 @@ * that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive

*/
constructor(id, lat, long, val) {
super(id, val);
constructor(key, lat, long, val) {
super(key, val);
this._lat = lat;

@@ -38,5 +38,5 @@ this._long = long;

* value.
* @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* a graph.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.

@@ -79,4 +79,4 @@ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store additional

/**
* The function creates a new vertex with the given id, value, latitude, and longitude.
* @param {VertexId} id - The id parameter is the unique identifier for the vertex. It is of type VertexId, which could
* The function creates a new vertex with the given key, value, latitude, and longitude.
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
* be a string or a number depending on how you define it in your code.

@@ -90,9 +90,9 @@ * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It

*/
createVertex(id, val, lat = this.origin[0], long = this.origin[1]) {
return new MapVertex(id, lat, long, val);
createVertex(key, val, lat = this.origin[0], long = this.origin[1]) {
return new MapVertex(key, lat, long, val);
}
/**
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
* @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
* created.

@@ -99,0 +99,0 @@ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It

import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
import type { VertexId } from '../../types';
import type { VertexKey } from '../../types';
import { IUNDirectedGraph } from '../../interfaces';

@@ -7,3 +7,3 @@ export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {

* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex within a graph or network.

@@ -13,3 +13,3 @@ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the

*/
constructor(id: VertexId, val?: V);
constructor(key: VertexKey, val?: V);
}

@@ -20,4 +20,4 @@ export declare class UndirectedEdge<V = number> extends AbstractEdge<V> {

* value.
* @param {VertexId} v1 - The first vertex ID of the edge.
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
* @param {VertexKey} v1 - The first vertex ID of the edge.
* @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
* graph edge.

@@ -28,6 +28,6 @@ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.

*/
constructor(v1: VertexId, v2: VertexId, weight?: number, val?: V);
constructor(v1: VertexKey, v2: VertexKey, weight?: number, val?: V);
private _vertices;
get vertices(): [VertexId, VertexId];
set vertices(v: [VertexId, VertexId]);
get vertices(): [VertexKey, VertexKey];
set vertices(v: [VertexKey, VertexKey]);
}

@@ -43,14 +43,14 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IUNDirectedGraph<V, E> {

* The function creates a new vertex with an optional value and returns it.
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is used to distinguish one
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
* vertex from another in the graph.
* @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
* it will be used as the value of the vertex. If no value is provided, the `id` parameter will be used as the value of
* it will be used as the value of the vertex. If no value is provided, the `key` parameter will be used as the value of
* the vertex.
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
*/
createVertex(id: VertexId, val?: V['val']): V;
createVertex(key: VertexKey, val?: V['val']): V;
/**
* The function creates an undirected edge between two vertices with an optional weight and value.
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
* @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge.
* @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
* @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If

@@ -62,20 +62,20 @@ * no weight is provided, it defaults to 1.

*/
createEdge(v1: VertexId, v2: VertexId, weight?: number, val?: E['val']): E;
createEdge(v1: VertexKey, v2: VertexKey, weight?: number, val?: E['val']): E;
/**
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
* @param {V | null | VertexId} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexId` (a string or number representing the ID of a vertex).
* @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexId` (vertex ID).
* @param {V | null | VertexKey} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
* @param {V | null | VertexKey} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexKey` (vertex ID).
* @returns an edge (E) or null.
*/
getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
getEdge(v1: V | null | VertexKey, v2: V | null | VertexKey): E | null;
/**
* The function removes an edge between two vertices in a graph and returns the removed edge.
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexId} v2 - V | VertexId - This parameter can be either a vertex object (V) or a vertex ID
* (VertexId). It represents the second vertex of the edge that needs to be removed.
* @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
* @param {V | VertexKey} v2 - V | VertexKey - This parameter can be either a vertex object (V) or a vertex ID
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
* @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
*/
removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
removeEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null;
/**

@@ -90,14 +90,14 @@ * The removeEdge function removes an edge between two vertices in a graph.

* vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
* edges connected to that vertex.
*/
degreeOf(vertexOrId: VertexId | V): number;
degreeOf(vertexOrKey: VertexKey | V): number;
/**
* The function returns the edges of a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`. A `VertexId` is a
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`. A `VertexKey` is a
* unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
* @returns an array of edges.
*/
edgesOf(vertexOrId: VertexId | V): E[];
edgesOf(vertexOrKey: VertexKey | V): E[];
/**

@@ -110,7 +110,7 @@ * The function "edgeSet" returns an array of unique edges from a set of edges.

* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns an array of vertices (V[]).
*/
getNeighbors(vertexOrId: V | VertexId): V[];
getNeighbors(vertexOrKey: V | VertexKey): V[];
/**

@@ -117,0 +117,0 @@ * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise

@@ -13,3 +13,3 @@ /**

* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex within a graph or network.

@@ -19,4 +19,4 @@ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the

*/
constructor(id, val) {
super(id, val);
constructor(key, val) {
super(key, val);
}

@@ -28,4 +28,4 @@ }

* value.
* @param {VertexId} v1 - The first vertex ID of the edge.
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
* @param {VertexKey} v1 - The first vertex ID of the edge.
* @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
* graph edge.

@@ -60,16 +60,16 @@ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.

* The function creates a new vertex with an optional value and returns it.
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is used to distinguish one
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
* vertex from another in the graph.
* @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
* it will be used as the value of the vertex. If no value is provided, the `id` parameter will be used as the value of
* it will be used as the value of the vertex. If no value is provided, the `key` parameter will be used as the value of
* the vertex.
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
*/
createVertex(id, val) {
return new UndirectedVertex(id, val !== null && val !== void 0 ? val : id);
createVertex(key, val) {
return new UndirectedVertex(key, val !== null && val !== void 0 ? val : key);
}
/**
* The function creates an undirected edge between two vertices with an optional weight and value.
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
* @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge.
* @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
* @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If

@@ -86,6 +86,6 @@ * no weight is provided, it defaults to 1.

* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
* @param {V | null | VertexId} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexId` (a string or number representing the ID of a vertex).
* @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexId` (vertex ID).
* @param {V | null | VertexKey} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
* @param {V | null | VertexKey} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexKey` (vertex ID).
* @returns an edge (E) or null.

@@ -100,3 +100,3 @@ */

if (vertex1 && vertex2) {
edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e => e.vertices.includes(vertex2.id));
edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e => e.vertices.includes(vertex2.key));
}

@@ -108,5 +108,5 @@ }

* The function removes an edge between two vertices in a graph and returns the removed edge.
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexId} v2 - V | VertexId - This parameter can be either a vertex object (V) or a vertex ID
* (VertexId). It represents the second vertex of the edge that needs to be removed.
* @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
* @param {V | VertexKey} v2 - V | VertexKey - This parameter can be either a vertex object (V) or a vertex ID
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
* @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.

@@ -123,7 +123,7 @@ */

if (v1Edges) {
removed = arrayRemove(v1Edges, (e) => e.vertices.includes(vertex2.id))[0] || null;
removed = arrayRemove(v1Edges, (e) => e.vertices.includes(vertex2.key))[0] || null;
}
const v2Edges = this._edges.get(vertex2);
if (v2Edges) {
arrayRemove(v2Edges, (e) => e.vertices.includes(vertex1.id));
arrayRemove(v2Edges, (e) => e.vertices.includes(vertex1.key));
}

@@ -143,9 +143,9 @@ return removed;

* vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
* edges connected to that vertex.
*/
degreeOf(vertexOrId) {
degreeOf(vertexOrKey) {
var _a;
const vertex = this._getVertex(vertexOrId);
const vertex = this._getVertex(vertexOrKey);
if (vertex) {

@@ -160,8 +160,8 @@ return ((_a = this._edges.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;

* The function returns the edges of a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`. A `VertexId` is a
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`. A `VertexKey` is a
* unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
* @returns an array of edges.
*/
edgesOf(vertexOrId) {
const vertex = this._getVertex(vertexOrId);
edgesOf(vertexOrKey) {
const vertex = this._getVertex(vertexOrKey);
if (vertex) {

@@ -189,13 +189,13 @@ return this._edges.get(vertex) || [];

* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns an array of vertices (V[]).
*/
getNeighbors(vertexOrId) {
getNeighbors(vertexOrKey) {
const neighbors = [];
const vertex = this._getVertex(vertexOrId);
const vertex = this._getVertex(vertexOrKey);
if (vertex) {
const neighborEdges = this.edgesOf(vertex);
for (const edge of neighborEdges) {
const neighbor = this._getVertex(edge.vertices.filter(e => e !== vertex.id)[0]);
const neighbor = this._getVertex(edge.vertices.filter(e => e !== vertex.key)[0]);
if (neighbor) {

@@ -202,0 +202,0 @@ neighbors.push(neighbor);

export declare class TreeNode<V = any> {
constructor(id: string, value?: V, children?: TreeNode<V>[]);
private _id;
get id(): string;
set id(value: string);
constructor(key: string, value?: V, children?: TreeNode<V>[]);
private _key;
get key(): string;
set key(value: string);
private _value?;

@@ -7,0 +7,0 @@ get value(): V | undefined;

export class TreeNode {
constructor(id, value, children) {
this._id = id;
constructor(key, value, children) {
this._key = key;
this._value = value || undefined;
this._children = children || [];
}
get id() {
return this._id;
get key() {
return this._key;
}
set id(value) {
this._id = value;
set key(value) {
this._key = value;
}

@@ -13,0 +13,0 @@ get value() {

@@ -1,6 +0,6 @@

import { AbstractBinaryTreeNodeProperties, AbstractBinaryTreeNodeProperty, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, FamilyPosition, LoopType, NodeOrPropertyName } from '../types';
import { AbstractBinaryTreeNodeProperties, AbstractBinaryTreeNodeProperty, BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodePropertyName, DFSOrderPattern, FamilyPosition, LoopType, NodeOrPropertyName } from '../types';
import { AbstractBinaryTreeNode } from '../data-structures';
export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
get id(): BinaryTreeNodeId;
set id(v: BinaryTreeNodeId);
get key(): BinaryTreeNodeKey;
set key(v: BinaryTreeNodeKey);
get val(): T | undefined;

@@ -19,5 +19,5 @@ set val(v: T | undefined);

export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null;
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N | null;
get loopType(): LoopType;
get visitedId(): BinaryTreeNodeId[];
get visitedKey(): BinaryTreeNodeKey[];
get visitedVal(): Array<N['val']>;

@@ -30,6 +30,6 @@ get visitedNode(): N[];

isEmpty(): boolean;
add(id: BinaryTreeNodeId | N, val?: N['val']): N | null | undefined;
addMany(idsOrNodes: (BinaryTreeNodeId | N | null)[], data?: N['val'][]): (N | null | undefined)[];
fill(idsOrNodes: (BinaryTreeNodeId | N | null)[], data?: N[] | Array<N['val']>): boolean;
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
add(key: BinaryTreeNodeKey | N, val?: N['val']): N | null | undefined;
addMany(idsOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N['val'][]): (N | null | undefined)[];
fill(idsOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N[] | Array<N['val']>): boolean;
remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
getDepth(node: N): number;

@@ -39,5 +39,5 @@ getHeight(beginRoot?: N | null): number;

isPerfectlyBalanced(beginRoot?: N | null): boolean;
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
has(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): boolean;
get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
getPathToRoot(node: N): N[];

@@ -55,4 +55,4 @@ getLeftMost(): N | null;

subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
BFS(): BinaryTreeNodeId[];
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
BFS(): BinaryTreeNodeKey[];
BFS(nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
BFS(nodeOrPropertyName: 'val'): N['val'][];

@@ -62,4 +62,4 @@ BFS(nodeOrPropertyName: 'node'): N[];

BFS(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
DFS(): BinaryTreeNodeId[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
DFS(): BinaryTreeNodeKey[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];

@@ -69,4 +69,4 @@ DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];

DFS(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
DFSIterative(): BinaryTreeNodeId[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
DFSIterative(): BinaryTreeNodeKey[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];

@@ -76,4 +76,4 @@ DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];

DFSIterative(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
levelIterative(node: N | null): BinaryTreeNodeId[];
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
levelIterative(node: N | null): BinaryTreeNodeKey[];
levelIterative(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];

@@ -83,4 +83,4 @@ levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];

levelIterative(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
listLevels(node: N | null): BinaryTreeNodeId[][];
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
listLevels(node: N | null): BinaryTreeNodeKey[][];
listLevels(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[][];
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];

@@ -91,4 +91,4 @@ listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];

getPredecessor(node: N): N;
morris(): BinaryTreeNodeId[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
morris(): BinaryTreeNodeKey[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];

@@ -95,0 +95,0 @@ morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];

@@ -1,17 +0,17 @@

import { VertexId } from '../types';
import { VertexKey } from '../types';
export interface IAbstractGraph<V, E> {
hasVertex(vertexOrId: V | VertexId): boolean;
addVertex(id: VertexId, val?: V): boolean;
removeVertex(vertexOrId: V | VertexId): boolean;
removeAllVertices(vertices: V[] | VertexId[]): boolean;
degreeOf(vertexOrId: V | VertexId): number;
edgesOf(vertexOrId: V | VertexId): E[];
hasEdge(src: V | VertexId, dest: V | VertexId): boolean;
getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
hasVertex(vertexOrKey: V | VertexKey): boolean;
addVertex(key: VertexKey, val?: V): boolean;
removeVertex(vertexOrKey: V | VertexKey): boolean;
removeAllVertices(vertices: V[] | VertexKey[]): boolean;
degreeOf(vertexOrKey: V | VertexKey): number;
edgesOf(vertexOrKey: V | VertexKey): E[];
hasEdge(src: V | VertexKey, dest: V | VertexKey): boolean;
getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
edgeSet(): E[];
addEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E): boolean;
addEdge(src: V | VertexKey, dest: V | VertexKey, weight: number, val: E): boolean;
removeEdge(edge: E): E | null;
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
getNeighbors(vertexOrId: V | VertexId): V[];
setEdgeWeight(srcOrKey: V | VertexKey, destOrKey: V | VertexKey, weight: number): boolean;
getMinPathBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): V[] | null;
getNeighbors(vertexOrKey: V | VertexKey): V[];
}
import { AVLTreeNode } from '../data-structures';
import { IBST, IBSTNode } from './bst';
import { BinaryTreeDeletedResult, BinaryTreeNodeId } from '../types';
import { BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../types';
export type IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> = IBSTNode<T, NEIGHBOR>;
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
add(id: BinaryTreeNodeId, val?: N['val'] | null): N | null | undefined;
remove(id: BinaryTreeNodeId): BinaryTreeDeletedResult<N>[];
add(key: BinaryTreeNodeKey, val?: N['val'] | null): N | null | undefined;
remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
}
import { BSTNode } from '../data-structures';
import { IBinaryTree, IBinaryTreeNode } from './binary-tree';
import { BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName } from '../types';
import { BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodePropertyName } from '../types';
export type IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> = IBinaryTreeNode<T, NEIGHBOR>;
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
add(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N | null | undefined;
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
lastKey(): BinaryTreeNodeId;
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
add(key: BinaryTreeNodeKey, val?: N['val'] | null, count?: number): N | null | undefined;
get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
lastKey(): BinaryTreeNodeKey;
remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
lesserSum(key: BinaryTreeNodeKey, propertyName?: BinaryTreeNodePropertyName): number;
allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;

@@ -14,0 +14,0 @@ perfectlyBalance(): boolean;

@@ -1,2 +0,2 @@

import { VertexId } from '../types';
import { VertexKey } from '../types';
import { IAbstractGraph } from './abstract-graph';

@@ -6,8 +6,8 @@ export interface IDirectedGraph<V, E> extends IAbstractGraph<V, E> {

outgoingEdgesOf(vertex: V): E[];
inDegreeOf(vertexOrId: V | VertexId): number;
outDegreeOf(vertexOrId: V | VertexId): number;
inDegreeOf(vertexOrKey: V | VertexKey): number;
outDegreeOf(vertexOrKey: V | VertexKey): number;
getEdgeSrc(e: E): V | null;
getEdgeDest(e: E): V | null;
removeEdgeSrcToDest(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
removeEdgesBetween(v1: V | VertexId, v2: V | VertexId): E[];
removeEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
removeEdgesBetween(v1: V | VertexKey, v2: V | VertexKey): E[];
}
import { RBTreeNode } from '../data-structures';
import { IBST, IBSTNode } from './bst';
import { BinaryTreeNodeId } from '../types';
import { BinaryTreeNodeKey } from '../types';
export type IRBTreeNode<T, NEIGHBOR extends IRBTreeNode<T, NEIGHBOR>> = IBSTNode<T, NEIGHBOR>;
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
}

@@ -1,5 +0,5 @@

import { VertexId } from '../types';
import { VertexKey } from '../types';
import { IAbstractGraph } from './abstract-graph';
export interface IUNDirectedGraph<V, E> extends IAbstractGraph<V, E> {
removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
removeEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null;
}

@@ -21,6 +21,6 @@ import { AbstractBinaryTreeNode } from '../../data-structures';

}
export type BinaryTreeNodePropertyName = 'id' | 'val';
export type BinaryTreeNodePropertyName = 'key' | 'val';
export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
export type DFSOrderPattern = 'in' | 'pre' | 'post';
export type BinaryTreeNodeId = number;
export type BinaryTreeNodeKey = number;
export type BinaryTreeDeletedResult<N> = {

@@ -30,3 +30,3 @@ deleted: N | null | undefined;

};
export type AbstractBinaryTreeNodeProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeId;
export type AbstractBinaryTreeNodeProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeKey;
export type AbstractBinaryTreeNodeProperties<N extends AbstractBinaryTreeNode<N['val'], N>> = AbstractBinaryTreeNodeProperty<N>[];

@@ -33,0 +33,0 @@ export type AbstractBinaryTreeNodeNested<T> = AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;

@@ -1,3 +0,3 @@

export type VertexId = string | number;
export type EdgeId = string;
export type VertexKey = string | number;
export type EdgeKey = string;
export type DijkstraResult<V> = {

@@ -4,0 +4,0 @@ distMap: Map<V, number>;

import { BSTNode } from '../../data-structures/binary-tree';
import type { BinaryTreeOptions } from './binary-tree';
import { BinaryTreeNodeId } from './abstract-binary-tree';
export type BSTComparator = (a: BinaryTreeNodeId, b: BinaryTreeNodeId) => number;
import { BinaryTreeNodeKey } from './abstract-binary-tree';
export type BSTComparator = (a: BinaryTreeNodeKey, b: BinaryTreeNodeKey) => number;
export type BSTNodeNested<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;

@@ -6,0 +6,0 @@ export type BSTOptions = BinaryTreeOptions & {

import { TreeMultisetNode } from '../../data-structures/binary-tree';
import { AVLTreeOptions } from './avl-tree';
export type TreeMultisetNodeNested<T> = TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
export type TreeMultisetOptions = Omit<AVLTreeOptions, 'isMergeDuplicatedNodeById'> & {};
export type TreeMultisetOptions = Omit<AVLTreeOptions, 'isMergeDuplicatedNodeByKey'> & {};
export type KeyValueObject = {
[key: string]: any;
};
export type KeyValueObjectWithId = {
export type KeyValueObjectWithKey = {
[key: string]: any;
id: string | number | symbol;
key: string | number | symbol;
};
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
export type ObjectWithoutId = Omit<KeyValueObject, 'id'>;
export type ObjectWithNonNumberId = {
export type ObjectWithoutKey = Omit<KeyValueObject, 'key'>;
export type ObjectWithNonNumberKey = {
[key: string]: any;
id: string | boolean | symbol | null | object | undefined;
key: string | boolean | symbol | null | object | undefined;
};
export type ObjectWithNumberId = {
export type ObjectWithNumberKey = {
[key: string]: any;
id: number;
key: number;
};
export type RestrictValById = NonNumberNonObjectButDefined | ObjectWithoutId | ObjectWithNonNumberId | ObjectWithNumberId;
export type RestrictValByKey = NonNumberNonObjectButDefined | ObjectWithoutKey | ObjectWithNonNumberKey | ObjectWithNumberKey;
export type DummyAny = string | number | boolean | null | undefined | object | symbol | void | ((...args: []) => any) | never;
{
"name": "data-structure-typed",
"version": "1.34.7",
"version": "1.34.8",
"description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -9,3 +9,3 @@ /**

import {BST, BSTNode} from './bst';
import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId} from '../../types';
import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey} from '../../types';
import {IAVLTree, IAVLTreeNode} from '../../interfaces';

@@ -17,4 +17,4 @@

{
constructor(id: BinaryTreeNodeId, val?: V) {
super(id, val);
constructor(key: BinaryTreeNodeKey, val?: V) {
super(key, val);
}

@@ -35,11 +35,11 @@ }

/**
* The function creates a new AVL tree node with the given id and value.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
* The function creates a new AVL tree node with the given key and value.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
* identify each node in the tree.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
* that will be stored in the node.
* @returns a new AVLTreeNode object with the specified id and value.
* @returns a new AVLTreeNode object with the specified key and value.
*/
override createNode(id: BinaryTreeNodeId, val?: N['val']): N {
return new AVLTreeNode<N['val'], N>(id, val) as N;
override createNode(key: BinaryTreeNodeKey, val?: N['val']): N {
return new AVLTreeNode<N['val'], N>(key, val) as N;
}

@@ -49,3 +49,3 @@

* The function overrides the add method of a binary tree node and balances the tree after inserting a new node.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier of the binary tree node that we want to add.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It is of type

@@ -55,5 +55,5 @@ * `N['val']`, which means it should be of the same type as the `val` property of the nodes in the binary tree.

*/
override add(id: BinaryTreeNodeId, val?: N['val']): N | null | undefined {
override add(key: BinaryTreeNodeKey, val?: N['val']): N | null | undefined {
// TODO support node as a param
const inserted = super.add(id, val);
const inserted = super.add(key, val);
if (inserted) this._balancePath(inserted);

@@ -66,8 +66,8 @@ return inserted;

* deletion.
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
* @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be
* removed.
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
*/
override remove(id: BinaryTreeNodeId): BinaryTreeDeletedResult<N>[] {
const deletedResults = super.remove(id);
override remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[] {
const deletedResults = super.remove(key);
for (const {needBalanced} of deletedResults) {

@@ -74,0 +74,0 @@ if (needBalanced) {

@@ -9,3 +9,3 @@ /**

import type {BinaryTreeNodeId, BinaryTreeNodeNested, BinaryTreeOptions} from '../../types';
import type {BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions} from '../../types';
import {AbstractBinaryTree, AbstractBinaryTreeNode} from './abstract-binary-tree';

@@ -18,4 +18,4 @@ import {IBinaryTree, IBinaryTreeNode} from '../../interfaces';

{
constructor(id: BinaryTreeNodeId, val?: V) {
super(id, val);
constructor(key: BinaryTreeNodeKey, val?: V) {
super(key, val);
}

@@ -40,11 +40,11 @@ }

* The function creates a new binary tree node with an optional value.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
* `BinaryTreeNodeId`, which represents the unique identifier for each node in the binary tree.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is of type
* `BinaryTreeNodeKey`, which represents the unique identifier for each node in the binary tree.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
* stored in the node.
* @returns a new instance of a BinaryTreeNode with the specified id and value.
* @returns a new instance of a BinaryTreeNode with the specified key and value.
*/
createNode(id: BinaryTreeNodeId, val?: N['val']): N {
return new BinaryTreeNode<N['val'], N>(id, val) as N;
createNode(key: BinaryTreeNodeKey, val?: N['val']): N {
return new BinaryTreeNode<N['val'], N>(key, val) as N;
}
}

@@ -8,3 +8,9 @@ /**

*/
import type {BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTNodeNested, BSTOptions} from '../../types';
import type {
BinaryTreeNodeKey,
BinaryTreeNodePropertyName,
BSTComparator,
BSTNodeNested,
BSTOptions
} from '../../types';
import {CP, LoopType} from '../../types';

@@ -18,4 +24,4 @@ import {BinaryTree, BinaryTreeNode} from './binary-tree';

{
constructor(id: BinaryTreeNodeId, val?: V) {
super(id, val);
constructor(key: BinaryTreeNodeKey, val?: V) {
super(key, val);
}

@@ -40,11 +46,11 @@ }

/**
* The function creates a new binary search tree node with the given id and value.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
* The function creates a new binary search tree node with the given key and value.
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
* identify each node in the binary tree.
* @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
* that will be stored in the node.
* @returns a new instance of the BSTNode class with the specified id and value.
* @returns a new instance of the BSTNode class with the specified key and value.
*/
override createNode(id: BinaryTreeNodeId, val?: N['val']): N {
return new BSTNode<N['val'], N>(id, val) as N;
override createNode(key: BinaryTreeNodeKey, val?: N['val']): N {
return new BSTNode<N['val'], N>(key, val) as N;
}

@@ -55,3 +61,3 @@

* node with the same ID.
* @param {BinaryTreeNodeId | N | null} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId` or a `N`
* @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N`
* (which represents a binary tree node) or `null`.

@@ -62,11 +68,11 @@ * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node

*/
override add(idOrNode: BinaryTreeNodeId | N | null, val?: N['val']): N | null | undefined {
override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined {
// TODO support node as a param
let inserted: N | null = null;
let newNode: N | null = null;
if (idOrNode instanceof BSTNode) {
newNode = idOrNode;
} else if (typeof idOrNode === 'number') {
newNode = this.createNode(idOrNode, val);
} else if (idOrNode === null) {
if (keyOrNode instanceof BSTNode) {
newNode = keyOrNode;
} else if (typeof keyOrNode === 'number') {
newNode = this.createNode(keyOrNode, val);
} else if (keyOrNode === null) {
newNode = null;

@@ -83,3 +89,3 @@ }

if (cur !== null && newNode !== null) {
if (this._compare(cur.id, newNode.id) === CP.eq) {
if (this._compare(cur.key, newNode.key) === CP.eq) {
if (newNode) {

@@ -91,3 +97,3 @@ cur.val = newNode.val;

inserted = cur;
} else if (this._compare(cur.id, newNode.id) === CP.gt) {
} else if (this._compare(cur.key, newNode.key) === CP.gt) {
// Traverse left of the node

@@ -107,3 +113,3 @@ if (cur.left === undefined) {

}
} else if (this._compare(cur.id, newNode.id) === CP.lt) {
} else if (this._compare(cur.key, newNode.key) === CP.lt) {
// Traverse right of the node

@@ -135,4 +141,4 @@ if (cur.right === undefined) {

* manner.
* @param {[BinaryTreeNodeId | N , N['val']][]} idsOrNodes - The `idsOrNodes` parameter in the `addMany` function is an array of
* `BinaryTreeNodeId` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
* @param {[BinaryTreeNodeKey | N , N['val']][]} idsOrNodes - The `idsOrNodes` parameter in the `addMany` function is an array of
* `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
* to the binary search tree.

@@ -144,7 +150,7 @@ * @param {N['val'][]} data - The values of tree nodes

override addMany(
idsOrNodes: (BinaryTreeNodeId | null)[] | (N | null)[],
idsOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[],
data?: N['val'][],
isBalanceAdd = false
): (N | null | undefined)[] {
function hasNoNull(arr: (BinaryTreeNodeId | null)[] | (N | null)[]): arr is BinaryTreeNodeId[] | N[] {
function hasNoNull(arr: (BinaryTreeNodeKey | null)[] | (N | null)[]): arr is BinaryTreeNodeKey[] | N[] {
return arr.indexOf(null) === -1;

@@ -156,18 +162,20 @@ }

const inserted: (N | null | undefined)[] = [];
const combinedArr: [BinaryTreeNodeId | N, N['val']][] = idsOrNodes.map((value, index) => [value, data?.[index]]);
const combinedArr: [BinaryTreeNodeKey | N, N['val']][] = idsOrNodes.map((value, index) => [value, data?.[index]]);
let sorted = [];
function isNodeOrNullTuple(arr: [BinaryTreeNodeId | N, N['val']][]): arr is [N, N['val']][] {
for (const [idOrNode] of arr) if (idOrNode instanceof BSTNode) return true;
function isNodeOrNullTuple(arr: [BinaryTreeNodeKey | N, N['val']][]): arr is [N, N['val']][] {
for (const [keyOrNode] of arr) if (keyOrNode instanceof BSTNode) return true;
return false;
}
function isBinaryTreeIdOrNullTuple(arr: [BinaryTreeNodeId | N, N['val']][]): arr is [BinaryTreeNodeId, N['val']][] {
for (const [idOrNode] of arr) if (typeof idOrNode === 'number') return true;
function isBinaryTreeKeyOrNullTuple(
arr: [BinaryTreeNodeKey | N, N['val']][]
): arr is [BinaryTreeNodeKey, N['val']][] {
for (const [keyOrNode] of arr) if (typeof keyOrNode === 'number') return true;
return false;
}
let sortedIdsOrNodes: (number | N | null)[] = [],
let sortedKeysOrNodes: (number | N | null)[] = [],
sortedData: (N['val'] | undefined)[] | undefined = [];
if (isNodeOrNullTuple(combinedArr)) {
sorted = combinedArr.sort((a, b) => a[0].id - b[0].id);
} else if (isBinaryTreeIdOrNullTuple(combinedArr)) {
sorted = combinedArr.sort((a, b) => a[0].key - b[0].key);
} else if (isBinaryTreeKeyOrNullTuple(combinedArr)) {
sorted = combinedArr.sort((a, b) => a[0] - b[0]);

@@ -177,5 +185,5 @@ } else {

}
sortedIdsOrNodes = sorted.map(([idOrNode]) => idOrNode);
sortedKeysOrNodes = sorted.map(([keyOrNode]) => keyOrNode);
sortedData = sorted.map(([, val]) => val);
const recursive = (arr: (BinaryTreeNodeId | null | N)[], data?: N['val'][]) => {
const recursive = (arr: (BinaryTreeNodeKey | null | N)[], data?: N['val'][]) => {
if (arr.length === 0) return;

@@ -198,3 +206,3 @@

const m = l + Math.floor((r - l) / 2);
const newNode = this.add(sortedIdsOrNodes[m], sortedData?.[m]);
const newNode = this.add(sortedKeysOrNodes[m], sortedData?.[m]);
inserted.push(newNode);

@@ -208,3 +216,3 @@ stack.push([m + 1, r]);

if (this.loopType === LoopType.RECURSIVE) {
recursive(sortedIdsOrNodes, sortedData);
recursive(sortedKeysOrNodes, sortedData);
} else {

@@ -219,10 +227,10 @@ iterative();

* The function returns the first node in a binary tree that matches the given property name and value.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
* generic type `N`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'id'`.
* @returns The method is returning either a BinaryTreeNodeId or N (generic type) or null.
* specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
* @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
*/
override get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null {
propertyName = propertyName ?? 'id';
override get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null {
propertyName = propertyName ?? 'key';
return this.getNodes(nodeProperty, propertyName, true)[0] ?? null;

@@ -232,12 +240,12 @@ }

/**
* The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
* leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
* @returns The method `lastKey()` returns the id of the rightmost node in the binary tree if the comparison between
* the values at index 0 and 1 is less than, otherwise it returns the id of the leftmost node. If the comparison is
* equal, it returns the id of the rightmost node. If there are no nodes in the tree, it returns 0.
* The function returns the key of the rightmost node if the comparison between two values is less than, the key of the
* leftmost node if the comparison is greater than, and the key of the rightmost node otherwise.
* @returns The method `lastKey()` returns the key of the rightmost node in the binary tree if the comparison between
* the values at index 0 and 1 is less than, otherwise it returns the key of the leftmost node. If the comparison is
* equal, it returns the key of the rightmost node. If there are no nodes in the tree, it returns 0.
*/
lastKey(): BinaryTreeNodeId {
if (this._compare(0, 1) === CP.lt) return this.getRightMost()?.id ?? 0;
else if (this._compare(0, 1) === CP.gt) return this.getLeftMost()?.id ?? 0;
else return this.getRightMost()?.id ?? 0;
lastKey(): BinaryTreeNodeKey {
if (this._compare(0, 1) === CP.lt) return this.getRightMost()?.key ?? 0;
else if (this._compare(0, 1) === CP.gt) return this.getLeftMost()?.key ?? 0;
else return this.getRightMost()?.key ?? 0;
}

@@ -247,6 +255,6 @@

* The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or an
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or an
* `N` type. It represents the property of the binary tree node that you want to compare with.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use for comparison. If not provided, it defaults to `'id'`.
* specifies the property name to use for comparison. If not provided, it defaults to `'key'`.
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to

@@ -258,4 +266,4 @@ * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`

override getNodes(
nodeProperty: BinaryTreeNodeId | N,
propertyName: BinaryTreeNodePropertyName = 'id',
nodeProperty: BinaryTreeNodeKey | N,
propertyName: BinaryTreeNodePropertyName = 'key',
onlyOne?: boolean

@@ -271,5 +279,5 @@ ): N[] {

if (!cur.left && !cur.right) return;
if (propertyName === 'id') {
if (this._compare(cur.id, nodeProperty as number) === CP.gt) cur.left && _traverse(cur.left);
if (this._compare(cur.id, nodeProperty as number) === CP.lt) cur.right && _traverse(cur.right);
if (propertyName === 'key') {
if (this._compare(cur.key, nodeProperty as number) === CP.gt) cur.left && _traverse(cur.left);
if (this._compare(cur.key, nodeProperty as number) === CP.lt) cur.right && _traverse(cur.right);
} else {

@@ -288,5 +296,5 @@ cur.left && _traverse(cur.left);

if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne)) return result;
if (propertyName === 'id') {
if (this._compare(cur.id, nodeProperty as number) === CP.gt) cur.left && queue.push(cur.left);
if (this._compare(cur.id, nodeProperty as number) === CP.lt) cur.right && queue.push(cur.right);
if (propertyName === 'key') {
if (this._compare(cur.key, nodeProperty as number) === CP.gt) cur.left && queue.push(cur.left);
if (this._compare(cur.key, nodeProperty as number) === CP.lt) cur.right && queue.push(cur.right);
} else {

@@ -307,22 +315,22 @@ cur.left && queue.push(cur.left);

* less than a given node.
* @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} beginNode - The `beginNode` parameter can be one of the following:
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use for calculating the sum. If not provided, it defaults to `'id'`.
* specifies the property name to use for calculating the sum. If not provided, it defaults to `'key'`.
* @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
* binary tree that have a lesser value than the specified `beginNode` based on the `propertyName`.
*/
lesserSum(beginNode: N | BinaryTreeNodeId | null, propertyName?: BinaryTreeNodePropertyName): number {
propertyName = propertyName ?? 'id';
if (typeof beginNode === 'number') beginNode = this.get(beginNode, 'id');
lesserSum(beginNode: N | BinaryTreeNodeKey | null, propertyName?: BinaryTreeNodePropertyName): number {
propertyName = propertyName ?? 'key';
if (typeof beginNode === 'number') beginNode = this.get(beginNode, 'key');
if (!beginNode) return 0;
if (!this.root) return 0;
const id = beginNode.id;
const key = beginNode.key;
const getSumByPropertyName = (cur: N) => {
let needSum: number;
switch (propertyName) {
case 'id':
needSum = cur.id;
case 'key':
needSum = cur.key;
break;
default:
needSum = cur.id;
needSum = cur.key;
break;

@@ -337,3 +345,3 @@ }

const _traverse = (cur: N): void => {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.eq) {

@@ -359,3 +367,3 @@ if (cur.right) sum += this.subTreeSum(cur.right, propertyName);

if (cur) {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.eq) {

@@ -384,4 +392,4 @@ if (cur.right) sum += this.subTreeSum(cur.right, propertyName);

* have a greater value than a given node.
* @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be either of type `N` (a generic type),
* `BinaryTreeNodeId`, or `null`. It represents the node in the binary tree to which the delta value will be added.
* @param {N | BinaryTreeNodeKey | null} node - The `node` parameter can be either of type `N` (a generic type),
* `BinaryTreeNodeKey`, or `null`. It represents the node in the binary tree to which the delta value will be added.
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of

@@ -391,14 +399,14 @@ * each greater node should be increased.

* specifies the property name of the nodes in the binary tree that you want to update. If not provided, it defaults to
* 'id'.
* 'key'.
* @returns a boolean value.
*/
allGreaterNodesAdd(
node: N | BinaryTreeNodeId | null,
node: N | BinaryTreeNodeKey | null,
delta: number,
propertyName?: BinaryTreeNodePropertyName
): boolean {
propertyName = propertyName ?? 'id';
if (typeof node === 'number') node = this.get(node, 'id');
propertyName = propertyName ?? 'key';
if (typeof node === 'number') node = this.get(node, 'key');
if (!node) return false;
const id = node.id;
const key = node.key;
if (!this.root) return false;

@@ -408,7 +416,7 @@

switch (propertyName) {
case 'id':
cur.id += delta;
case 'key':
cur.key += delta;
break;
default:
cur.id += delta;
cur.key += delta;
break;

@@ -419,8 +427,8 @@ }

const _traverse = (cur: N) => {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.gt) _sumByPropertyName(cur);
if (!cur.left && !cur.right) return;
if (cur.left && this._compare(cur.left.id, id) === CP.gt) _traverse(cur.left);
if (cur.right && this._compare(cur.right.id, id) === CP.gt) _traverse(cur.right);
if (cur.left && this._compare(cur.left.key, key) === CP.gt) _traverse(cur.left);
if (cur.right && this._compare(cur.right.key, key) === CP.gt) _traverse(cur.right);
};

@@ -435,7 +443,7 @@

if (cur) {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.gt) _sumByPropertyName(cur);
if (cur.left && this._compare(cur.left.id, id) === CP.gt) queue.push(cur.left);
if (cur.right && this._compare(cur.right.id, id) === CP.gt) queue.push(cur.right);
if (cur.left && this._compare(cur.left.key, key) === CP.gt) queue.push(cur.left);
if (cur.right && this._compare(cur.right.key, key) === CP.gt) queue.push(cur.right);
}

@@ -473,3 +481,3 @@ }

const midNode = sorted[m];
this.add(midNode.id, midNode.val);
this.add(midNode.key, midNode.val);
buildBalanceBST(l, m - 1);

@@ -490,3 +498,3 @@ buildBalanceBST(m + 1, r);

const midNode = sorted[m];
this.add(midNode.id, midNode.val);
this.add(midNode.key, midNode.val);
stack.push([m + 1, r]);

@@ -554,8 +562,8 @@ stack.push([l, m - 1]);

* greater than, less than, or equal to the second ID.
* @param {BinaryTreeNodeId} a - a is a BinaryTreeNodeId, which represents the identifier of a binary tree node.
* @param {BinaryTreeNodeId} b - The parameter "b" in the above code refers to a BinaryTreeNodeId.
* @param {BinaryTreeNodeKey} a - a is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
* @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
* @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
* than), or CP.eq (equal).
*/
protected _compare(a: BinaryTreeNodeId, b: BinaryTreeNodeId): CP {
protected _compare(a: BinaryTreeNodeKey, b: BinaryTreeNodeKey): CP {
const compared = this._comparator(a, b);

@@ -562,0 +570,0 @@ if (compared > 0) return CP.gt;

@@ -1,2 +0,2 @@

import {BinaryTreeNodeId, RBColor, RBTreeNodeNested, RBTreeOptions} from '../../types';
import {BinaryTreeNodeKey, RBColor, RBTreeNodeNested, RBTreeOptions} from '../../types';
import {IRBTree, IRBTreeNode} from '../../interfaces';

@@ -11,4 +11,4 @@ import {BST, BSTNode} from './bst';

constructor(id: BinaryTreeNodeId, val?: V) {
super(id, val);
constructor(key: BinaryTreeNodeKey, val?: V) {
super(key, val);
this._color = RBColor.RED;

@@ -31,8 +31,8 @@ }

override createNode(id: BinaryTreeNodeId, val?: N['val']): N {
return new RBTreeNode(id, val) as N;
override createNode(key: BinaryTreeNodeKey, val?: N['val']): N {
return new RBTreeNode(key, val) as N;
}
// override add(idOrNode: BinaryTreeNodeId | N | null, val?: N['val']): N | null | undefined {
// const inserted = super.add(idOrNode, val);
// override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined {
// const inserted = super.add(keyOrNode, val);
// if (inserted) this._fixInsertViolation(inserted);

@@ -210,4 +210,4 @@ // return inserted;

//
// override remove(nodeOrId: BinaryTreeNodeId | N): BinaryTreeDeletedResult<N>[] {
// const node = this.get(nodeOrId);
// override remove(nodeOrKey: BinaryTreeNodeKey | N): BinaryTreeDeletedResult<N>[] {
// const node = this.get(nodeOrKey);
// const result: BinaryTreeDeletedResult<N>[] = [{deleted: undefined, needBalanced: null}];

@@ -214,0 +214,0 @@ // if (!node) return result; // Node does not exist

@@ -8,3 +8,3 @@ /**

*/
import type {BinaryTreeNodeId, TreeMultisetNodeNested, TreeMultisetOptions} from '../../types';
import type {BinaryTreeNodeKey, TreeMultisetNodeNested, TreeMultisetOptions} from '../../types';
import {BinaryTreeDeletedResult, CP, DFSOrderPattern, FamilyPosition, LoopType} from '../../types';

@@ -19,4 +19,4 @@ import {ITreeMultiset, ITreeMultisetNode} from '../../interfaces';

/**
* The constructor function initializes a BinaryTreeNode object with an id, value, and count.
* @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
* The constructor function initializes a BinaryTreeNode object with an key, value, and count.
* @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
* of the binary tree node.

@@ -29,4 +29,4 @@ * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value of the binary

*/
constructor(id: BinaryTreeNodeId, val?: V, count = 1) {
super(id, val);
constructor(key: BinaryTreeNodeKey, val?: V, count = 1) {
super(key, val);
this._count = count;

@@ -70,4 +70,4 @@ }

/**
* The function creates a new BSTNode with the given id, value, and count.
* @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
* The function creates a new BSTNode with the given key, value, and count.
* @param {BinaryTreeNodeKey} key - The key parameter is the unique identifier for the binary tree node. It is used to
* distinguish one node from another in the tree.

@@ -77,6 +77,6 @@ * @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.

* occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
* @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
* @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
*/
override createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N {
return new TreeMultisetNode(id, val, count) as N;
override createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N {
return new TreeMultisetNode(key, val, count) as N;
}

@@ -92,8 +92,8 @@

override swapLocation(srcNode: N, destNode: N): N {
const {id, val, count, height} = destNode;
const tempNode = this.createNode(id, val, count);
const {key, val, count, height} = destNode;
const tempNode = this.createNode(key, val, count);
if (tempNode) {
tempNode.height = height;
destNode.id = srcNode.id;
destNode.key = srcNode.key;
destNode.val = srcNode.val;

@@ -103,3 +103,3 @@ destNode.count = srcNode.count;

srcNode.id = tempNode.id;
srcNode.key = tempNode.key;
srcNode.val = tempNode.val;

@@ -116,3 +116,3 @@ srcNode.count = tempNode.count;

* necessary.
* @param {BinaryTreeNodeId | N} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId` or a `N` (which
* @param {BinaryTreeNodeKey | N} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N` (which
* represents a `BinaryTreeNode`).

@@ -124,12 +124,12 @@ * @param [val] - The `val` parameter represents the value to be added to the binary tree node.

*/
override add(idOrNode: BinaryTreeNodeId | N | null, val?: N['val'], count?: number): N | null | undefined {
override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val'], count?: number): N | null | undefined {
count = count ?? 1;
let inserted: N | null | undefined = undefined,
newNode: N | null;
if (idOrNode instanceof TreeMultisetNode) {
newNode = this.createNode(idOrNode.id, idOrNode.val, idOrNode.count);
} else if (idOrNode === null) {
if (keyOrNode instanceof TreeMultisetNode) {
newNode = this.createNode(keyOrNode.key, keyOrNode.val, keyOrNode.count);
} else if (keyOrNode === null) {
newNode = null;
} else {
newNode = this.createNode(idOrNode, val, count);
newNode = this.createNode(keyOrNode, val, count);
}

@@ -147,3 +147,3 @@ if (!this.root) {

if (newNode) {
if (this._compare(cur.id, newNode.id) === CP.eq) {
if (this._compare(cur.key, newNode.key) === CP.eq) {
cur.val = newNode.val;

@@ -154,3 +154,3 @@ cur.count += newNode.count;

inserted = cur;
} else if (this._compare(cur.id, newNode.id) === CP.gt) {
} else if (this._compare(cur.key, newNode.key) === CP.gt) {
// Traverse left of the node

@@ -169,3 +169,3 @@ if (cur.left === undefined) {

}
} else if (this._compare(cur.id, newNode.id) === CP.lt) {
} else if (this._compare(cur.key, newNode.key) === CP.lt) {
// Traverse right of the node

@@ -234,6 +234,6 @@ if (cur.right === undefined) {

* the inserted nodes.
* @param {(BinaryTreeNodeId | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeId or BinaryTreeNode
* @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
* objects, or null values.
* @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
* the nodes being added. It is used when adding nodes using the `idOrNode` and `data` arguments in the `this.add()`
* the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()`
* method. If provided, the `data` array should

@@ -243,3 +243,3 @@ * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.

override addMany(
idsOrNodes: (BinaryTreeNodeId | null)[] | (N | null)[],
idsOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[],
data?: N['val'][]

@@ -250,10 +250,10 @@ ): (N | null | undefined)[] {

for (let i = 0; i < idsOrNodes.length; i++) {
const idOrNode = idsOrNodes[i];
const keyOrNode = idsOrNodes[i];
if (idOrNode instanceof TreeMultisetNode) {
inserted.push(this.add(idOrNode.id, idOrNode.val, idOrNode.count));
if (keyOrNode instanceof TreeMultisetNode) {
inserted.push(this.add(keyOrNode.key, keyOrNode.val, keyOrNode.count));
continue;
}
if (idOrNode === null) {
if (keyOrNode === null) {
inserted.push(this.add(NaN, null, 0));

@@ -263,3 +263,3 @@ continue;

inserted.push(this.add(idOrNode, data?.[i], 1));
inserted.push(this.add(keyOrNode, data?.[i], 1));
}

@@ -286,3 +286,3 @@ return inserted;

const midNode = sorted[m];
this.add(midNode.id, midNode.val, midNode.count);
this.add(midNode.key, midNode.val, midNode.count);
buildBalanceBST(l, m - 1);

@@ -303,3 +303,3 @@ buildBalanceBST(m + 1, r);

const midNode = sorted[m];
this.add(midNode.id, midNode.val, midNode.count);
this.add(midNode.key, midNode.val, midNode.count);
stack.push([m + 1, r]);

@@ -317,3 +317,3 @@ stack.push([l, m - 1]);

* node that needs to be balanced.
* @param {N | BinaryTreeNodeId | null} nodeOrId - The `nodeOrId` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:
* @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines

@@ -324,7 +324,7 @@ * whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will

*/
override remove(nodeOrId: N | BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[] {
override remove(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[] {
const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];
if (!this.root) return bstDeletedResult;
const curr: N | null = this.get(nodeOrId);
const curr: N | null = this.get(nodeOrKey);
if (!curr) return bstDeletedResult;

@@ -420,9 +420,9 @@

* recursively or iteratively.
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeId` (a unique identifier for a node in the binary tree) or
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeKey` (a unique identifier for a node in the binary tree) or
* `null` if the subtree is empty.
* @returns the sum of the count values of all nodes in the subtree rooted at `subTreeRoot`.
*/
subTreeSumCount(subTreeRoot: N | BinaryTreeNodeId | null): number {
if (typeof subTreeRoot === 'number') subTreeRoot = this.get(subTreeRoot, 'id');
subTreeSumCount(subTreeRoot: N | BinaryTreeNodeKey | null): number {
if (typeof subTreeRoot === 'number') subTreeRoot = this.get(subTreeRoot, 'key');

@@ -458,4 +458,4 @@ if (!subTreeRoot) return 0;

* the `count` property of each node.
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeId` (a unique identifier for a node in the binary tree), a
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
* in a binary tree. It can be either a `BinaryTreeNodeKey` (a unique identifier for a node in the binary tree), a
* `BinaryTreeNode` object, or `null` if the subtree is empty.

@@ -466,4 +466,4 @@ * @param {number} delta - The delta parameter is a number that represents the amount by which the count of each node

*/
subTreeAddCount(subTreeRoot: N | BinaryTreeNodeId | null, delta: number): boolean {
if (typeof subTreeRoot === 'number') subTreeRoot = this.get(subTreeRoot, 'id');
subTreeAddCount(subTreeRoot: N | BinaryTreeNodeKey | null, delta: number): boolean {
if (typeof subTreeRoot === 'number') subTreeRoot = this.get(subTreeRoot, 'key');

@@ -502,3 +502,3 @@ if (!subTreeRoot) return false;

* using a queue.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
* `N`. It represents the property of the nodes that you want to search for.

@@ -510,3 +510,3 @@ * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to

*/
getNodesByCount(nodeProperty: BinaryTreeNodeId | N, onlyOne?: boolean): N[] {
getNodesByCount(nodeProperty: BinaryTreeNodeKey | N, onlyOne?: boolean): N[] {
if (!this.root) return [];

@@ -613,10 +613,10 @@ const result: N[] = [];

* value than a given node.
* @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} beginNode - The `beginNode` parameter can be one of the following:
* @returns the sum of the counts of nodes in the binary tree that have a lesser value than the given beginNode.
*/
lesserSumCount(beginNode: N | BinaryTreeNodeId | null): number {
if (typeof beginNode === 'number') beginNode = this.get(beginNode, 'id');
lesserSumCount(beginNode: N | BinaryTreeNodeKey | null): number {
if (typeof beginNode === 'number') beginNode = this.get(beginNode, 'key');
if (!beginNode) return 0;
if (!this.root) return 0;
const id = beginNode.id;
const key = beginNode.key;

@@ -627,3 +627,3 @@ let sum = 0;

const _traverse = (cur: N): void => {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.eq) {

@@ -649,3 +649,3 @@ if (cur.right) sum += this.subTreeSumCount(cur.right);

if (cur) {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.eq) {

@@ -674,3 +674,3 @@ if (cur.right) sum += this.subTreeSumCount(cur.right);

* greater than a given ID by a specified delta value.
* @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be one of the following:
* @param {N | BinaryTreeNodeKey | null} node - The `node` parameter can be one of the following:
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the `count` property

@@ -680,6 +680,6 @@ * of each node should be increased.

*/
allGreaterNodesAddCount(node: N | BinaryTreeNodeId | null, delta: number): boolean {
if (typeof node === 'number') node = this.get(node, 'id');
allGreaterNodesAddCount(node: N | BinaryTreeNodeKey | null, delta: number): boolean {
if (typeof node === 'number') node = this.get(node, 'key');
if (!node) return false;
const id = node.id;
const key = node.key;
if (!this.root) return false;

@@ -689,8 +689,8 @@

const _traverse = (cur: N) => {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.gt) cur.count += delta;
if (!cur.left && !cur.right) return;
if (cur.left && this._compare(cur.left.id, id) === CP.gt) _traverse(cur.left);
if (cur.right && this._compare(cur.right.id, id) === CP.gt) _traverse(cur.right);
if (cur.left && this._compare(cur.left.key, key) === CP.gt) _traverse(cur.left);
if (cur.right && this._compare(cur.right.key, key) === CP.gt) _traverse(cur.right);
};

@@ -705,7 +705,7 @@

if (cur) {
const compared = this._compare(cur.id, id);
const compared = this._compare(cur.key, key);
if (compared === CP.gt) cur.count += delta;
if (cur.left && this._compare(cur.left.id, id) === CP.gt) queue.push(cur.left);
if (cur.right && this._compare(cur.right.id, id) === CP.gt) queue.push(cur.right);
if (cur.left && this._compare(cur.left.key, key) === CP.gt) queue.push(cur.left);
if (cur.right && this._compare(cur.right.key, key) === CP.gt) queue.push(cur.right);
}

@@ -712,0 +712,0 @@ }

@@ -10,3 +10,3 @@ /**

import {PriorityQueue} from '../priority-queue';
import type {DijkstraResult, VertexId} from '../../types';
import type {DijkstraResult, VertexKey} from '../../types';
import {IAbstractGraph} from '../../interfaces';

@@ -16,4 +16,4 @@

/**
* The function is a protected constructor that takes an id and an optional value as parameters.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* The function is a protected constructor that takes an key and an optional value as parameters.
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex object.

@@ -23,15 +23,15 @@ * @param {V} [val] - The parameter "val" is an optional parameter of type V. It is used to assign a value to the

*/
protected constructor(id: VertexId, val?: V) {
this._id = id;
protected constructor(key: VertexKey, val?: V) {
this._key = key;
this._val = val;
}
private _id: VertexId;
private _key: VertexKey;
get id(): VertexId {
return this._id;
get key(): VertexKey {
return this._key;
}
set id(v: VertexId) {
this._id = v;
set key(v: VertexKey) {
this._key = v;
}

@@ -112,5 +112,5 @@

{
private _vertices: Map<VertexId, V> = new Map<VertexId, V>();
private _vertices: Map<VertexKey, V> = new Map<VertexKey, V>();
get vertices(): Map<VertexId, V> {
get vertices(): Map<VertexKey, V> {
return this._vertices;

@@ -122,6 +122,6 @@ }

* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param id
* @param key
* @param val
*/
abstract createVertex(id: VertexId, val?: V): V;
abstract createVertex(key: VertexKey, val?: V): V;

@@ -136,15 +136,15 @@ /**

*/
abstract createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
abstract createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E;
abstract removeEdge(edge: E): E | null;
abstract getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
abstract getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
abstract degreeOf(vertexOrId: V | VertexId): number;
abstract degreeOf(vertexOrKey: V | VertexKey): number;
abstract edgeSet(): E[];
abstract edgesOf(vertexOrId: V | VertexId): E[];
abstract edgesOf(vertexOrKey: V | VertexKey): E[];
abstract getNeighbors(vertexOrId: V | VertexId): V[];
abstract getNeighbors(vertexOrKey: V | VertexKey): V[];

@@ -155,9 +155,9 @@ abstract getEndsOfEdge(edge: E): [V, V] | null;

* The function "getVertex" returns the vertex with the specified ID or null if it doesn't exist.
* @param {VertexId} vertexId - The `vertexId` parameter is the identifier of the vertex that you want to retrieve from
* @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
* the `_vertices` map.
* @returns The method `getVertex` returns the vertex with the specified `vertexId` if it exists in the `_vertices`
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
* map. If the vertex does not exist, it returns `null`.
*/
getVertex(vertexId: VertexId): V | null {
return this._vertices.get(vertexId) || null;
getVertex(vertexKey: VertexKey): V | null {
return this._vertices.get(vertexKey) || null;
}

@@ -167,8 +167,8 @@

* The function checks if a vertex exists in a graph.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns a boolean value.
*/
hasVertex(vertexOrId: V | VertexId): boolean {
return this._vertices.has(this._getVertexId(vertexOrId));
hasVertex(vertexOrKey: V | VertexKey): boolean {
return this._vertices.has(this._getVertexKey(vertexOrKey));
}

@@ -178,9 +178,9 @@

addVertex(id: VertexId, val?: V['val']): boolean;
addVertex(key: VertexKey, val?: V['val']): boolean;
addVertex(idOrVertex: VertexId | V, val?: V['val']): boolean {
if (idOrVertex instanceof AbstractVertex) {
return this._addVertexOnly(idOrVertex);
addVertex(keyOrVertex: VertexKey | V, val?: V['val']): boolean {
if (keyOrVertex instanceof AbstractVertex) {
return this._addVertexOnly(keyOrVertex);
} else {
const newVertex = this.createVertex(idOrVertex, val);
const newVertex = this.createVertex(keyOrVertex, val);
return this._addVertexOnly(newVertex);

@@ -192,9 +192,9 @@ }

* The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns The method is returning a boolean value.
*/
removeVertex(vertexOrId: V | VertexId): boolean {
const vertexId = this._getVertexId(vertexOrId);
return this._vertices.delete(vertexId);
removeVertex(vertexOrKey: V | VertexKey): boolean {
const vertexKey = this._getVertexKey(vertexOrKey);
return this._vertices.delete(vertexKey);
}

@@ -204,8 +204,8 @@

* The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
* @param {V[] | VertexId[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
* of vertex IDs (`VertexId[]`).
* @param {V[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
* of vertex IDs (`VertexKey[]`).
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
* were removed.
*/
removeAllVertices(vertices: V[] | VertexId[]): boolean {
removeAllVertices(vertices: V[] | VertexKey[]): boolean {
const removed: boolean[] = [];

@@ -220,9 +220,9 @@ for (const v of vertices) {

* The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
* @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the unique
* @param {VertexKey | V} v1 - The parameter v1 can be either a VertexKey or a V. A VertexKey represents the unique
* identifier of a vertex in a graph, while V represents the type of the vertex object itself.
* @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
* `VertexId` or a `V` type, which represents the type of the vertex.
* @param {VertexKey | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
* `VertexKey` or a `V` type, which represents the type of the vertex.
* @returns A boolean value is being returned.
*/
hasEdge(v1: VertexId | V, v2: VertexId | V): boolean {
hasEdge(v1: VertexKey | V, v2: VertexKey | V): boolean {
const edge = this.getEdge(v1, v2);

@@ -234,5 +234,5 @@ return !!edge;

addEdge(src: V | VertexId, dest: V | VertexId, weight?: number, val?: E['val']): boolean;
addEdge(src: V | VertexKey, dest: V | VertexKey, weight?: number, val?: E['val']): boolean;
addEdge(srcOrEdge: V | VertexId | E, dest?: V | VertexId, weight?: number, val?: E['val']): boolean {
addEdge(srcOrEdge: V | VertexKey | E, dest?: V | VertexKey, weight?: number, val?: E['val']): boolean {
if (srcOrEdge instanceof AbstractEdge) {

@@ -243,8 +243,8 @@ return this._addEdgeOnly(srcOrEdge);

if (!(this.hasVertex(srcOrEdge) && this.hasVertex(dest))) return false;
if (srcOrEdge instanceof AbstractVertex) srcOrEdge = srcOrEdge.id;
if (dest instanceof AbstractVertex) dest = dest.id;
if (srcOrEdge instanceof AbstractVertex) srcOrEdge = srcOrEdge.key;
if (dest instanceof AbstractVertex) dest = dest.key;
const newEdge = this.createEdge(srcOrEdge, dest, weight, val);
return this._addEdgeOnly(newEdge);
} else {
throw new Error('dest must be a Vertex or vertex id while srcOrEdge is an Edge');
throw new Error('dest must be a Vertex or vertex key while srcOrEdge is an Edge');
}

@@ -256,13 +256,13 @@ }

* The function sets the weight of an edge between two vertices in a graph.
* @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
* @param {VertexKey | V} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `V` object. It represents
* the source vertex of the edge.
* @param {VertexId | V} destOrId - The `destOrId` parameter represents the destination vertex of the edge. It can be
* either a `VertexId` or a vertex object `V`.
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrId)
* and the destination vertex (destOrId).
* @param {VertexKey | V} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
* either a `VertexKey` or a vertex object `V`.
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
* and the destination vertex (destOrKey).
* @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
* the weight of the edge and return true. If the edge does not exist, the function will return false.
*/
setEdgeWeight(srcOrId: VertexId | V, destOrId: VertexId | V, weight: number): boolean {
const edge = this.getEdge(srcOrId, destOrId);
setEdgeWeight(srcOrKey: VertexKey | V, destOrKey: VertexKey | V, weight: number): boolean {
const edge = this.getEdge(srcOrKey, destOrKey);
if (edge) {

@@ -278,8 +278,8 @@ edge.weight = weight;

* The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
* It is the starting vertex for finding paths.
* @param {V | VertexId} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexKey} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
* @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`V[][]`).
*/
getAllPathsBetween(v1: V | VertexId, v2: V | VertexId): V[][] {
getAllPathsBetween(v1: V | VertexKey, v2: V | VertexKey): V[][] {
const paths: V[][] = [];

@@ -331,4 +331,4 @@ const vertex1 = this._getVertex(v1);

* weights or using a breadth-first search algorithm.
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
* @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
* @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
* @param {V | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
* you want to find the minimum cost or weight from the source vertex `v1`.

@@ -343,3 +343,3 @@ * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.

*/
getMinCostBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): number | null {
getMinCostBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): number | null {
if (isWeight === undefined) isWeight = false;

@@ -392,5 +392,5 @@

* using a breadth-first search algorithm.
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
* object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexId} v2 - V | VertexId - The second vertex or vertex ID between which we want to find the minimum
* @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
* object (`V`) or a vertex ID (`VertexKey`).
* @param {V | VertexKey} v2 - V | VertexKey - The second vertex or vertex ID between which we want to find the minimum
* path.

@@ -403,3 +403,3 @@ * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the

*/
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null {
getMinPathBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): V[] | null {
if (isWeight === undefined) isWeight = false;

@@ -463,5 +463,5 @@

* a graph without using a heap data structure.
* @param {V | VertexId} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
* @param {V | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
* vertex object or a vertex ID.
* @param {V | VertexId | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
* @param {V | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
* parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its

@@ -478,4 +478,4 @@ * identifier. If no destination is provided, the value is set to `null`.

dijkstraWithoutHeap(
src: V | VertexId,
dest?: V | VertexId | null,
src: V | VertexKey,
dest?: V | VertexKey | null,
getMinDist?: boolean,

@@ -506,4 +506,4 @@ genPaths?: boolean

for (const vertex of vertices) {
const vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex) distMap.set(vertexOrId, Infinity);
const vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity);
}

@@ -529,7 +529,7 @@ distMap.set(srcVertex, 0);

for (const vertex of vertices) {
const vertexOrId = vertex[1];
const vertexOrKey = vertex[1];
if (vertexOrId instanceof AbstractVertex) {
const path: V[] = [vertexOrId];
let parent = preMap.get(vertexOrId);
if (vertexOrKey instanceof AbstractVertex) {
const path: V[] = [vertexOrKey];
let parent = preMap.get(vertexOrKey);
while (parent) {

@@ -607,5 +607,5 @@ path.push(parent);

* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
* @param {V | VertexId} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
* @param {V | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
* start. It can be either a vertex object or a vertex ID.
* @param {V | VertexId | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
* @param {V | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm

@@ -621,3 +621,8 @@ * will calculate the shortest paths to all other vertices from the source vertex.

*/
dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V> {
dijkstra(
src: V | VertexKey,
dest?: V | VertexKey | null,
getMinDist?: boolean,
genPaths?: boolean
): DijkstraResult<V> {
if (getMinDist === undefined) getMinDist = false;

@@ -642,10 +647,10 @@ if (genPaths === undefined) genPaths = false;

for (const vertex of vertices) {
const vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex) distMap.set(vertexOrId, Infinity);
const vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity);
}
const heap = new PriorityQueue<{id: number; val: V}>({
comparator: (a, b) => a.id - b.id
const heap = new PriorityQueue<{key: number; val: V}>({
comparator: (a, b) => a.key - b.key
});
heap.add({id: 0, val: srcVertex});
heap.add({key: 0, val: srcVertex});

@@ -662,6 +667,6 @@ distMap.set(srcVertex, 0);

for (const vertex of vertices) {
const vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex) {
const path: V[] = [vertexOrId];
let parent = preMap.get(vertexOrId);
const vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex) {
const path: V[] = [vertexOrKey];
let parent = preMap.get(vertexOrKey);
while (parent) {

@@ -680,3 +685,3 @@ path.push(parent);

const curHeapNode = heap.poll();
const dist = curHeapNode?.id;
const dist = curHeapNode?.key;
const cur = curHeapNode?.val;

@@ -703,3 +708,3 @@ if (dist !== undefined) {

if (dist + weight < distSrcToNeighbor) {
heap.add({id: dist + weight, val: neighbor});
heap.add({key: dist + weight, val: neighbor});
preMap.set(neighbor, cur);

@@ -745,3 +750,3 @@ distMap.set(neighbor, dist + weight);

* all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
* @param {V | VertexId} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
* @param {V | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
* start calculating the shortest paths. It can be either a vertex object or a vertex ID.

@@ -756,3 +761,3 @@ * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.

*/
bellmanFord(src: V | VertexId, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean) {
bellmanFord(src: V | VertexKey, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean) {
if (getMin === undefined) getMin = false;

@@ -815,6 +820,6 @@ if (genPath === undefined) genPath = false;

for (const vertex of vertices) {
const vertexOrId = vertex[1];
if (vertexOrId instanceof AbstractVertex) {
const path: V[] = [vertexOrId];
let parent = preMap.get(vertexOrId);
const vertexOrKey = vertex[1];
if (vertexOrKey instanceof AbstractVertex) {
const path: V[] = [vertexOrKey];
let parent = preMap.get(vertexOrKey);
while (parent !== undefined) {

@@ -1055,20 +1060,20 @@ path.push(parent);

return false;
// throw (new Error('Duplicated vertex id is not allowed'));
// throw (new Error('Duplicated vertex key is not allowed'));
}
this._vertices.set(newVertex.id, newVertex);
this._vertices.set(newVertex.key, newVertex);
return true;
}
protected _getVertex(vertexOrId: VertexId | V): V | null {
const vertexId = this._getVertexId(vertexOrId);
return this._vertices.get(vertexId) || null;
protected _getVertex(vertexOrKey: VertexKey | V): V | null {
const vertexKey = this._getVertexKey(vertexOrKey);
return this._vertices.get(vertexKey) || null;
}
protected _getVertexId(vertexOrId: V | VertexId): VertexId {
return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
protected _getVertexKey(vertexOrKey: V | VertexKey): VertexKey {
return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
}
protected _setVertices(value: Map<VertexId, V>) {
protected _setVertices(value: Map<VertexKey, V>) {
this._vertices = value;
}
}

@@ -10,3 +10,3 @@ /**

import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
import type {TopologicalStatus, VertexId} from '../../types';
import type {TopologicalStatus, VertexKey} from '../../types';
import {IDirectedGraph} from '../../interfaces';

@@ -17,3 +17,3 @@

* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex within a graph or data structure.

@@ -23,4 +23,4 @@ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the

*/
constructor(id: VertexId, val?: V) {
super(id, val);
constructor(key: VertexKey, val?: V) {
super(key, val);
}

@@ -33,6 +33,6 @@ }

* and value.
* @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* a graph.
* @param {VertexId} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
* `VertexId`, which is likely a unique identifier for a vertex in a graph.
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.

@@ -42,3 +42,3 @@ * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value associated with

*/
constructor(src: VertexId, dest: VertexId, weight?: number, val?: V) {
constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: V) {
super(weight, val);

@@ -49,19 +49,19 @@ this._src = src;

private _src: VertexId;
private _src: VertexKey;
get src(): VertexId {
get src(): VertexKey {
return this._src;
}
set src(v: VertexId) {
set src(v: VertexKey) {
this._src = v;
}
private _dest: VertexId;
private _dest: VertexKey;
get dest(): VertexId {
get dest(): VertexKey {
return this._dest;
}
set dest(v: VertexId) {
set dest(v: VertexKey) {
this._dest = v;

@@ -101,11 +101,11 @@ }

* The function creates a new vertex with an optional value and returns it.
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is of type `VertexId`, which
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
* could be a number or a string depending on how you want to identify your vertices.
* @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
* it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
* assigned the same value as the 'id' parameter
* assigned the same value as the 'key' parameter
* @returns a new instance of a DirectedVertex object, casted as type V.
*/
createVertex(id: VertexId, val?: V['val']): V {
return new DirectedVertex(id, val ?? id) as V;
createVertex(key: VertexKey, val?: V['val']): V {
return new DirectedVertex(key, val ?? key) as V;
}

@@ -120,4 +120,4 @@

* The function creates a directed edge between two vertices with an optional weight and value.
* @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no

@@ -129,3 +129,3 @@ * weight is provided, it defaults to 1.

*/
createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E {
createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E {
return new DirectedEdge(src, dest, weight ?? 1, val) as E;

@@ -136,14 +136,14 @@ }

* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
* @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a vertex object or a vertex ID.
* @param {V | null | VertexId} destOrId - The `destOrId` parameter in the `getEdge` function represents the
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexId`), or `null` if the
* @param {V | null | VertexKey} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
* @param {V | null | VertexKey} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexKey`), or `null` if the
* destination is not specified.
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
*/
getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null {
getEdge(srcOrKey: V | null | VertexKey, destOrKey: V | null | VertexKey): E | null {
let edges: E[] = [];
if (srcOrId !== null && destOrId !== null) {
const src: V | null = this._getVertex(srcOrId);
const dest: V | null = this._getVertex(destOrId);
if (srcOrKey !== null && destOrKey !== null) {
const src: V | null = this._getVertex(srcOrKey);
const dest: V | null = this._getVertex(destOrKey);

@@ -153,3 +153,3 @@ if (src && dest) {

if (srcOutEdges) {
edges = srcOutEdges.filter(edge => edge.dest === dest.id);
edges = srcOutEdges.filter(edge => edge.dest === dest.key);
}

@@ -164,9 +164,9 @@ }

* The function removes an edge between two vertices in a graph and returns the removed edge.
* @param {V | VertexId} srcOrId - The source vertex or its ID.
* @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex or its ID.
* @param {V | VertexKey} srcOrKey - The source vertex or its ID.
* @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
* @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
*/
removeEdgeSrcToDest(srcOrId: V | VertexId, destOrId: V | VertexId): E | null {
const src: V | null = this._getVertex(srcOrId);
const dest: V | null = this._getVertex(destOrId);
removeEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null {
const src: V | null = this._getVertex(srcOrKey);
const dest: V | null = this._getVertex(destOrKey);
let removed: E | null = null;

@@ -179,3 +179,3 @@ if (!src || !dest) {

if (srcOutEdges) {
arrayRemove<E>(srcOutEdges, (edge: E) => edge.dest === dest.id);
arrayRemove<E>(srcOutEdges, (edge: E) => edge.dest === dest.key);
}

@@ -185,3 +185,3 @@

if (destInEdges) {
removed = arrayRemove<E>(destInEdges, (edge: E) => edge.src === src.id)[0] || null;
removed = arrayRemove<E>(destInEdges, (edge: E) => edge.src === src.key)[0] || null;
}

@@ -204,3 +204,3 @@ return removed;

if (srcOutEdges && srcOutEdges.length > 0) {
arrayRemove(srcOutEdges, (edge: E) => edge.src === src.id);
arrayRemove(srcOutEdges, (edge: E) => edge.src === src.key);
}

@@ -210,3 +210,3 @@

if (destInEdges && destInEdges.length > 0) {
removed = arrayRemove(destInEdges, (edge: E) => edge.dest === dest.id)[0];
removed = arrayRemove(destInEdges, (edge: E) => edge.dest === dest.key)[0];
}

@@ -220,9 +220,9 @@ }

* The function removes edges between two vertices and returns the removed edges.
* @param {VertexId | V} v1 - The parameter `v1` can be either a `VertexId` or a `V`. A `VertexId` represents the
* @param {VertexKey | V} v1 - The parameter `v1` can be either a `VertexKey` or a `V`. A `VertexKey` represents the
* unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
* @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V` object. It is used to specify
* @param {VertexKey | V} v2 - The parameter `v2` represents either a `VertexKey` or a `V` object. It is used to specify
* the second vertex in the edge that needs to be removed.
* @returns an array of removed edges (E[]).
*/
removeEdgesBetween(v1: VertexId | V, v2: VertexId | V): E[] {
removeEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[] {
const removed: E[] = [];

@@ -243,8 +243,8 @@

* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
*/
incomingEdgesOf(vertexOrId: V | VertexId): E[] {
const target = this._getVertex(vertexOrId);
incomingEdgesOf(vertexOrKey: V | VertexKey): E[] {
const target = this._getVertex(vertexOrKey);
if (target) {

@@ -258,8 +258,8 @@ return this.inEdgeMap.get(target) || [];

* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
*/
outgoingEdgesOf(vertexOrId: V | VertexId): E[] {
const target = this._getVertex(vertexOrId);
outgoingEdgesOf(vertexOrKey: V | VertexKey): E[] {
const target = this._getVertex(vertexOrKey);
if (target) {

@@ -273,7 +273,7 @@ return this._outEdgeMap.get(target) || [];

* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
*/
degreeOf(vertexOrId: VertexId | V): number {
return this.outDegreeOf(vertexOrId) + this.inDegreeOf(vertexOrId);
degreeOf(vertexOrKey: VertexKey | V): number {
return this.outDegreeOf(vertexOrKey) + this.inDegreeOf(vertexOrKey);
}

@@ -283,7 +283,7 @@

* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The number of incoming edges of the specified vertex or vertex ID.
*/
inDegreeOf(vertexOrId: VertexId | V): number {
return this.incomingEdgesOf(vertexOrId).length;
inDegreeOf(vertexOrKey: VertexKey | V): number {
return this.incomingEdgesOf(vertexOrKey).length;
}

@@ -293,7 +293,7 @@

* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The number of outgoing edges from the specified vertex or vertex ID.
*/
outDegreeOf(vertexOrId: VertexId | V): number {
return this.outgoingEdgesOf(vertexOrId).length;
outDegreeOf(vertexOrKey: VertexKey | V): number {
return this.outgoingEdgesOf(vertexOrKey).length;
}

@@ -303,7 +303,7 @@

* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The function `edgesOf` returns an array of edges.
*/
edgesOf(vertexOrId: VertexId | V): E[] {
return [...this.outgoingEdgesOf(vertexOrId), ...this.incomingEdgesOf(vertexOrId)];
edgesOf(vertexOrKey: VertexKey | V): E[] {
return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
}

@@ -331,7 +331,7 @@

* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
* @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
* find the destinations. It can be either a `V` object, a `VertexId` value, or `null`.
* @param {V | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
* find the destinations. It can be either a `V` object, a `VertexKey` value, or `null`.
* @returns an array of vertices (V[]).
*/
getDestinations(vertex: V | VertexId | null): V[] {
getDestinations(vertex: V | VertexKey | null): V[] {
if (vertex === null) {

@@ -354,12 +354,12 @@ return [];

* in the sorted order, or null if the graph contains a cycle.
* @param {'vertex' | 'id'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'id'. If 'vertex' is
* specified, the vertices themselves will be used for sorting. If 'id' is specified, the ids of
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
* specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
*/
topologicalSort(propertyName?: 'vertex' | 'id'): Array<V | VertexId> | null {
propertyName = propertyName ?? 'id';
topologicalSort(propertyName?: 'vertex' | 'key'): Array<V | VertexKey> | null {
propertyName = propertyName ?? 'key';
// When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
// When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
const statusMap: Map<V | VertexId, TopologicalStatus> = new Map<V | VertexId, TopologicalStatus>();
const statusMap: Map<V | VertexKey, TopologicalStatus> = new Map<V | VertexKey, TopologicalStatus>();
for (const entry of this.vertices) {

@@ -369,5 +369,5 @@ statusMap.set(entry[1], 0);

let sorted: (V | VertexId)[] = [];
let sorted: (V | VertexKey)[] = [];
let hasCycle = false;
const dfs = (cur: V | VertexId) => {
const dfs = (cur: V | VertexKey) => {
statusMap.set(cur, 1);

@@ -395,3 +395,3 @@ const children = this.getDestinations(cur);

if (propertyName === 'id') sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.id : vertex));
if (propertyName === 'key') sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.key : vertex));
return sorted.reverse();

@@ -414,9 +414,9 @@ }

* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns an array of vertices (V[]).
*/
getNeighbors(vertexOrId: V | VertexId): V[] {
getNeighbors(vertexOrKey: V | VertexKey): V[] {
const neighbors: V[] = [];
const vertex = this._getVertex(vertexOrId);
const vertex = this._getVertex(vertexOrKey);
if (vertex) {

@@ -423,0 +423,0 @@ const outEdges = this.outgoingEdgesOf(vertex);

@@ -1,2 +0,2 @@

import {MapGraphCoordinate, VertexId} from '../../types';
import {MapGraphCoordinate, VertexKey} from '../../types';
import {DirectedEdge, DirectedGraph, DirectedVertex} from './directed-graph';

@@ -6,4 +6,4 @@

/**
* The constructor function initializes an object with an id, latitude, longitude, and an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex.
* The constructor function initializes an object with an key, latitude, longitude, and an optional value.
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
* @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate

@@ -18,4 +18,4 @@ * that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive

*/
constructor(id: VertexId, lat: number, long: number, val?: V) {
super(id, val);
constructor(key: VertexKey, lat: number, long: number, val?: V) {
super(key, val);
this._lat = lat;

@@ -50,5 +50,5 @@ this._long = long;

* value.
* @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* a graph.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.

@@ -58,3 +58,3 @@ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store additional

*/
constructor(src: VertexId, dest: VertexId, weight?: number, val?: V) {
constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: V) {
super(src, dest, weight, val);

@@ -104,4 +104,4 @@ }

/**
* The function creates a new vertex with the given id, value, latitude, and longitude.
* @param {VertexId} id - The id parameter is the unique identifier for the vertex. It is of type VertexId, which could
* The function creates a new vertex with the given key, value, latitude, and longitude.
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
* be a string or a number depending on how you define it in your code.

@@ -115,4 +115,9 @@ * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It

*/
override createVertex(id: VertexId, val?: V['val'], lat: number = this.origin[0], long: number = this.origin[1]): V {
return new MapVertex(id, lat, long, val) as V;
override createVertex(
key: VertexKey,
val?: V['val'],
lat: number = this.origin[0],
long: number = this.origin[1]
): V {
return new MapVertex(key, lat, long, val) as V;
}

@@ -122,4 +127,4 @@

* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
* @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
* created.

@@ -133,5 +138,5 @@ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It

*/
override createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E {
override createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E {
return new MapEdge(src, dest, weight, val) as E;
}
}

@@ -10,3 +10,3 @@ /**

import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
import type {VertexId} from '../../types';
import type {VertexKey} from '../../types';
import {IUNDirectedGraph} from '../../interfaces';

@@ -17,3 +17,3 @@

* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex within a graph or network.

@@ -23,4 +23,4 @@ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the

*/
constructor(id: VertexId, val?: V) {
super(id, val);
constructor(key: VertexKey, val?: V) {
super(key, val);
}

@@ -33,4 +33,4 @@ }

* value.
* @param {VertexId} v1 - The first vertex ID of the edge.
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
* @param {VertexKey} v1 - The first vertex ID of the edge.
* @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
* graph edge.

@@ -41,3 +41,3 @@ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.

*/
constructor(v1: VertexId, v2: VertexId, weight?: number, val?: V) {
constructor(v1: VertexKey, v2: VertexKey, weight?: number, val?: V) {
super(weight, val);

@@ -47,3 +47,3 @@ this._vertices = [v1, v2];

private _vertices: [VertexId, VertexId];
private _vertices: [VertexKey, VertexKey];

@@ -54,3 +54,3 @@ get vertices() {

set vertices(v: [VertexId, VertexId]) {
set vertices(v: [VertexKey, VertexKey]) {
this._vertices = v;

@@ -83,11 +83,11 @@ }

* The function creates a new vertex with an optional value and returns it.
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is used to distinguish one
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
* vertex from another in the graph.
* @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
* it will be used as the value of the vertex. If no value is provided, the `id` parameter will be used as the value of
* it will be used as the value of the vertex. If no value is provided, the `key` parameter will be used as the value of
* the vertex.
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
*/
override createVertex(id: VertexId, val?: V['val']): V {
return new UndirectedVertex(id, val ?? id) as V;
override createVertex(key: VertexKey, val?: V['val']): V {
return new UndirectedVertex(key, val ?? key) as V;
}

@@ -97,4 +97,4 @@

* The function creates an undirected edge between two vertices with an optional weight and value.
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
* @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge.
* @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
* @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If

@@ -106,3 +106,3 @@ * no weight is provided, it defaults to 1.

*/
override createEdge(v1: VertexId, v2: VertexId, weight?: number, val?: E['val']): E {
override createEdge(v1: VertexKey, v2: VertexKey, weight?: number, val?: E['val']): E {
return new UndirectedEdge(v1, v2, weight ?? 1, val) as E;

@@ -113,9 +113,9 @@ }

* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
* @param {V | null | VertexId} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexId` (a string or number representing the ID of a vertex).
* @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexId` (vertex ID).
* @param {V | null | VertexKey} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
* @param {V | null | VertexKey} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexKey` (vertex ID).
* @returns an edge (E) or null.
*/
getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null {
getEdge(v1: V | null | VertexKey, v2: V | null | VertexKey): E | null {
let edges: E[] | undefined = [];

@@ -128,3 +128,3 @@

if (vertex1 && vertex2) {
edges = this._edges.get(vertex1)?.filter(e => e.vertices.includes(vertex2.id));
edges = this._edges.get(vertex1)?.filter(e => e.vertices.includes(vertex2.key));
}

@@ -138,8 +138,8 @@ }

* The function removes an edge between two vertices in a graph and returns the removed edge.
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexId} v2 - V | VertexId - This parameter can be either a vertex object (V) or a vertex ID
* (VertexId). It represents the second vertex of the edge that needs to be removed.
* @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
* @param {V | VertexKey} v2 - V | VertexKey - This parameter can be either a vertex object (V) or a vertex ID
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
* @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
*/
removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null {
removeEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null {
const vertex1: V | null = this._getVertex(v1);

@@ -155,7 +155,7 @@ const vertex2: V | null = this._getVertex(v2);

if (v1Edges) {
removed = arrayRemove<E>(v1Edges, (e: E) => e.vertices.includes(vertex2.id))[0] || null;
removed = arrayRemove<E>(v1Edges, (e: E) => e.vertices.includes(vertex2.key))[0] || null;
}
const v2Edges = this._edges.get(vertex2);
if (v2Edges) {
arrayRemove<E>(v2Edges, (e: E) => e.vertices.includes(vertex1.id));
arrayRemove<E>(v2Edges, (e: E) => e.vertices.includes(vertex1.key));
}

@@ -177,8 +177,8 @@ return removed;

* vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
* edges connected to that vertex.
*/
degreeOf(vertexOrId: VertexId | V): number {
const vertex = this._getVertex(vertexOrId);
degreeOf(vertexOrKey: VertexKey | V): number {
const vertex = this._getVertex(vertexOrKey);
if (vertex) {

@@ -193,8 +193,8 @@ return this._edges.get(vertex)?.length || 0;

* The function returns the edges of a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`. A `VertexId` is a
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`. A `VertexKey` is a
* unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
* @returns an array of edges.
*/
edgesOf(vertexOrId: VertexId | V): E[] {
const vertex = this._getVertex(vertexOrId);
edgesOf(vertexOrKey: VertexKey | V): E[] {
const vertex = this._getVertex(vertexOrKey);
if (vertex) {

@@ -223,13 +223,13 @@ return this._edges.get(vertex) || [];

* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
* (`VertexKey`).
* @returns an array of vertices (V[]).
*/
getNeighbors(vertexOrId: V | VertexId): V[] {
getNeighbors(vertexOrKey: V | VertexKey): V[] {
const neighbors: V[] = [];
const vertex = this._getVertex(vertexOrId);
const vertex = this._getVertex(vertexOrKey);
if (vertex) {
const neighborEdges = this.edgesOf(vertex);
for (const edge of neighborEdges) {
const neighbor = this._getVertex(edge.vertices.filter(e => e !== vertex.id)[0]);
const neighbor = this._getVertex(edge.vertices.filter(e => e !== vertex.key)[0]);
if (neighbor) {

@@ -236,0 +236,0 @@ neighbors.push(neighbor);

export class TreeNode<V = any> {
constructor(id: string, value?: V, children?: TreeNode<V>[]) {
this._id = id;
constructor(key: string, value?: V, children?: TreeNode<V>[]) {
this._key = key;
this._value = value || undefined;

@@ -8,10 +8,10 @@ this._children = children || [];

private _id: string;
private _key: string;
get id(): string {
return this._id;
get key(): string {
return this._key;
}
set id(value: string) {
this._id = value;
set key(value: string) {
this._key = value;
}

@@ -18,0 +18,0 @@

@@ -5,3 +5,3 @@ import {

BinaryTreeDeletedResult,
BinaryTreeNodeId,
BinaryTreeNodeKey,
BinaryTreeNodePropertyName,

@@ -16,5 +16,5 @@ DFSOrderPattern,

export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
get id(): BinaryTreeNodeId;
get key(): BinaryTreeNodeKey;
set id(v: BinaryTreeNodeId);
set key(v: BinaryTreeNodeKey);

@@ -45,7 +45,7 @@ get val(): T | undefined;

export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null;
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N | null;
get loopType(): LoopType;
get visitedId(): BinaryTreeNodeId[];
get visitedKey(): BinaryTreeNodeKey[];

@@ -66,9 +66,9 @@ get visitedVal(): Array<N['val']>;

add(id: BinaryTreeNodeId | N, val?: N['val']): N | null | undefined;
add(key: BinaryTreeNodeKey | N, val?: N['val']): N | null | undefined;
addMany(idsOrNodes: (BinaryTreeNodeId | N | null)[], data?: N['val'][]): (N | null | undefined)[];
addMany(idsOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N['val'][]): (N | null | undefined)[];
fill(idsOrNodes: (BinaryTreeNodeId | N | null)[], data?: N[] | Array<N['val']>): boolean;
fill(idsOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N[] | Array<N['val']>): boolean;
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];

@@ -83,7 +83,7 @@ getDepth(node: N): number;

getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
has(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): boolean;
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;

@@ -116,5 +116,5 @@ getPathToRoot(node: N): N[];

BFS(): BinaryTreeNodeId[];
BFS(): BinaryTreeNodeKey[];
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
BFS(nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];

@@ -129,5 +129,5 @@ BFS(nodeOrPropertyName: 'val'): N['val'][];

DFS(): BinaryTreeNodeId[];
DFS(): BinaryTreeNodeKey[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];

@@ -142,5 +142,5 @@ DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];

DFSIterative(): BinaryTreeNodeId[];
DFSIterative(): BinaryTreeNodeKey[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];

@@ -158,5 +158,5 @@ DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];

levelIterative(node: N | null): BinaryTreeNodeId[];
levelIterative(node: N | null): BinaryTreeNodeKey[];
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
levelIterative(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];

@@ -171,5 +171,5 @@ levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];

listLevels(node: N | null): BinaryTreeNodeId[][];
listLevels(node: N | null): BinaryTreeNodeKey[][];
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
listLevels(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[][];

@@ -186,5 +186,5 @@ listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];

morris(): BinaryTreeNodeId[];
morris(): BinaryTreeNodeKey[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];

@@ -191,0 +191,0 @@ morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];

@@ -1,31 +0,31 @@

import {VertexId} from '../types';
import {VertexKey} from '../types';
export interface IAbstractGraph<V, E> {
hasVertex(vertexOrId: V | VertexId): boolean;
hasVertex(vertexOrKey: V | VertexKey): boolean;
addVertex(id: VertexId, val?: V): boolean;
addVertex(key: VertexKey, val?: V): boolean;
removeVertex(vertexOrId: V | VertexId): boolean;
removeVertex(vertexOrKey: V | VertexKey): boolean;
removeAllVertices(vertices: V[] | VertexId[]): boolean;
removeAllVertices(vertices: V[] | VertexKey[]): boolean;
degreeOf(vertexOrId: V | VertexId): number;
degreeOf(vertexOrKey: V | VertexKey): number;
edgesOf(vertexOrId: V | VertexId): E[];
edgesOf(vertexOrKey: V | VertexKey): E[];
hasEdge(src: V | VertexId, dest: V | VertexId): boolean;
hasEdge(src: V | VertexKey, dest: V | VertexKey): boolean;
getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
edgeSet(): E[];
addEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E): boolean;
addEdge(src: V | VertexKey, dest: V | VertexKey, weight: number, val: E): boolean;
removeEdge(edge: E): E | null;
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
setEdgeWeight(srcOrKey: V | VertexKey, destOrKey: V | VertexKey, weight: number): boolean;
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
getMinPathBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): V[] | null;
getNeighbors(vertexOrId: V | VertexId): V[];
getNeighbors(vertexOrKey: V | VertexKey): V[];
}
import {AVLTreeNode} from '../data-structures';
import {IBST, IBSTNode} from './bst';
import {BinaryTreeDeletedResult, BinaryTreeNodeId} from '../types';
import {BinaryTreeDeletedResult, BinaryTreeNodeKey} from '../types';

@@ -8,5 +8,5 @@ export type IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> = IBSTNode<T, NEIGHBOR>;

export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
add(id: BinaryTreeNodeId, val?: N['val'] | null): N | null | undefined;
add(key: BinaryTreeNodeKey, val?: N['val'] | null): N | null | undefined;
remove(id: BinaryTreeNodeId): BinaryTreeDeletedResult<N>[];
remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];

@@ -13,0 +13,0 @@ // _balanceFactor(node: N): number

import {BSTNode} from '../data-structures';
import {IBinaryTree, IBinaryTreeNode} from './binary-tree';
import {BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName} from '../types';
import {BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodePropertyName} from '../types';

@@ -8,17 +8,17 @@ export type IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> = IBinaryTreeNode<T, NEIGHBOR>;

export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
add(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N | null | undefined;
add(key: BinaryTreeNodeKey, val?: N['val'] | null, count?: number): N | null | undefined;
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
lastKey(): BinaryTreeNodeId;
lastKey(): BinaryTreeNodeKey;
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
// --- start additional functions
lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
lesserSum(key: BinaryTreeNodeKey, propertyName?: BinaryTreeNodePropertyName): number;

@@ -25,0 +25,0 @@ allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;

@@ -1,2 +0,2 @@

import {VertexId} from '../types';
import {VertexKey} from '../types';
import {IAbstractGraph} from './abstract-graph';

@@ -9,5 +9,5 @@

inDegreeOf(vertexOrId: V | VertexId): number;
inDegreeOf(vertexOrKey: V | VertexKey): number;
outDegreeOf(vertexOrId: V | VertexId): number;
outDegreeOf(vertexOrKey: V | VertexKey): number;

@@ -18,5 +18,5 @@ getEdgeSrc(e: E): V | null;

removeEdgeSrcToDest(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
removeEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
removeEdgesBetween(v1: V | VertexId, v2: V | VertexId): E[];
removeEdgesBetween(v1: V | VertexKey, v2: V | VertexKey): E[];
}
import {RBTreeNode} from '../data-structures';
import {IBST, IBSTNode} from './bst';
import {BinaryTreeNodeId} from '../types';
import {BinaryTreeNodeKey} from '../types';

@@ -8,3 +8,3 @@ export type IRBTreeNode<T, NEIGHBOR extends IRBTreeNode<T, NEIGHBOR>> = IBSTNode<T, NEIGHBOR>;

export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
}

@@ -1,6 +0,6 @@

import {VertexId} from '../types';
import {VertexKey} from '../types';
import {IAbstractGraph} from './abstract-graph';
export interface IUNDirectedGraph<V, E> extends IAbstractGraph<V, E> {
removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
removeEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null;
}

@@ -26,3 +26,3 @@ import {AbstractBinaryTreeNode} from '../../data-structures';

export type BinaryTreeNodePropertyName = 'id' | 'val';
export type BinaryTreeNodePropertyName = 'key' | 'val';

@@ -33,3 +33,3 @@ export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;

export type BinaryTreeNodeId = number;
export type BinaryTreeNodeKey = number;

@@ -42,3 +42,3 @@ export type BinaryTreeDeletedResult<N> = { deleted: N | null | undefined; needBalanced: N | null };

| number
| BinaryTreeNodeId;
| BinaryTreeNodeKey;

@@ -45,0 +45,0 @@

@@ -1,3 +0,3 @@

export type VertexId = string | number;
export type EdgeId = string;
export type VertexKey = string | number;
export type EdgeKey = string;
export type DijkstraResult<V> = {

@@ -4,0 +4,0 @@ distMap: Map<V, number>;

import {BSTNode} from '../../data-structures/binary-tree';
import type {BinaryTreeOptions} from './binary-tree';
import {BinaryTreeNodeId} from './abstract-binary-tree';
import {BinaryTreeNodeKey} from './abstract-binary-tree';
export type BSTComparator = (a: BinaryTreeNodeId, b: BinaryTreeNodeId) => number;
export type BSTComparator = (a: BinaryTreeNodeKey, b: BinaryTreeNodeKey) => number;

@@ -7,0 +7,0 @@ // prettier-ignore

@@ -6,2 +6,2 @@ import {TreeMultisetNode} from '../../data-structures/binary-tree';

export type TreeMultisetOptions = Omit<AVLTreeOptions, 'isMergeDuplicatedNodeById'> & {}
export type TreeMultisetOptions = Omit<AVLTreeOptions, 'isMergeDuplicatedNodeByKey'> & {}
export type KeyValueObject = {[key: string]: any};
export type KeyValueObjectWithId = {[key: string]: any; id: string | number | symbol};
export type KeyValueObjectWithKey = {[key: string]: any; key: string | number | symbol};
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
export type ObjectWithoutId = Omit<KeyValueObject, 'id'>;
export type ObjectWithoutKey = Omit<KeyValueObject, 'key'>;
export type ObjectWithNonNumberId = {
export type ObjectWithNonNumberKey = {
[key: string]: any;
id: string | boolean | symbol | null | object | undefined;
key: string | boolean | symbol | null | object | undefined;
};
export type ObjectWithNumberId = {
export type ObjectWithNumberKey = {
[key: string]: any;
id: number;
key: number;
};
export type RestrictValById =
export type RestrictValByKey =
| NonNumberNonObjectButDefined
| ObjectWithoutId
| ObjectWithNonNumberId
| ObjectWithNumberId;
| ObjectWithoutKey
| ObjectWithNonNumberKey
| ObjectWithNumberKey;

@@ -25,0 +25,0 @@ export type DummyAny =

@@ -15,11 +15,11 @@ import {AVLTree} from '../../../../src';

const getNodeById = tree.get(10, 'id');
expect(getNodeById?.id).toBe(10);
const getNodeById = tree.get(10, 'key');
expect(getNodeById?.key).toBe(10);
const getMinNodeByRoot = tree.getLeftMost();
expect(getMinNodeByRoot?.id).toBe(1);
expect(getMinNodeByRoot?.key).toBe(1);
const node15 = tree.get(15);
const getMinNodeBySpecificNode = node15 && tree.getLeftMost(node15);
expect(getMinNodeBySpecificNode?.id).toBe(12);
expect(getMinNodeBySpecificNode?.key).toBe(12);

@@ -36,4 +36,4 @@ const subTreeSum = node15 && tree.subTreeSum(node15);

const dfs = tree.DFS('in', 'node');
expect(dfs[0].id).toBe(1);
expect(dfs[dfs.length - 1].id).toBe(16);
expect(dfs[0].key).toBe(1);
expect(dfs[dfs.length - 1].key).toBe(16);

@@ -43,22 +43,22 @@ tree.perfectlyBalance();

expect(tree.isPerfectlyBalanced()).toBe(true);
expect(bfs[0].id).toBe(8);
expect(bfs[bfs.length - 1].id).toBe(16);
expect(bfs[0].key).toBe(8);
expect(bfs[bfs.length - 1].key).toBe(16);
expect(tree.remove(11)[0].deleted?.id).toBe(11);
expect(tree.remove(11)[0].deleted?.key).toBe(11);
expect(tree.isAVLBalanced()).toBe(true);
expect(node15 && tree.getHeight(node15)).toBe(2);
expect(tree.remove(1)[0].deleted?.id).toBe(1);
expect(tree.remove(1)[0].deleted?.key).toBe(1);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(4);
expect(tree.remove(4)[0].deleted?.id).toBe(4);
expect(tree.remove(4)[0].deleted?.key).toBe(4);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(4);
expect(tree.remove(10)[0].deleted?.id).toBe(10);
expect(tree.remove(10)[0].deleted?.key).toBe(10);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(3);
expect(tree.remove(15)[0].deleted?.id).toBe(15);
expect(tree.remove(15)[0].deleted?.key).toBe(15);
expect(tree.isAVLBalanced()).toBe(true);

@@ -68,19 +68,19 @@

expect(tree.remove(5)[0].deleted?.id).toBe(5);
expect(tree.remove(5)[0].deleted?.key).toBe(5);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(3);
expect(tree.remove(13)[0].deleted?.id).toBe(13);
expect(tree.remove(13)[0].deleted?.key).toBe(13);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(3);
expect(tree.remove(3)[0].deleted?.id).toBe(3);
expect(tree.remove(3)[0].deleted?.key).toBe(3);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(3);
expect(tree.remove(8)[0].deleted?.id).toBe(8);
expect(tree.remove(8)[0].deleted?.key).toBe(8);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(3);
expect(tree.remove(6)[0].deleted?.id).toBe(6);
expect(tree.remove(6)[0].deleted?.key).toBe(6);
expect(tree.remove(6).length).toBe(0);

@@ -90,10 +90,10 @@ expect(tree.isAVLBalanced()).toBe(true);

expect(tree.remove(7)[0].deleted?.id).toBe(7);
expect(tree.remove(7)[0].deleted?.key).toBe(7);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(2);
expect(tree.remove(9)[0].deleted?.id).toBe(9);
expect(tree.remove(9)[0].deleted?.key).toBe(9);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(2);
expect(tree.remove(14)[0].deleted?.id).toBe(14);
expect(tree.remove(14)[0].deleted?.key).toBe(14);
expect(tree.isAVLBalanced()).toBe(true);

@@ -109,6 +109,6 @@ expect(tree.getHeight()).toBe(1);

const lastBFSNodes = tree.BFS('node');
expect(lastBFSNodes[0].id).toBe(12);
expect(lastBFSNodes[1].id).toBe(2);
expect(lastBFSNodes[2].id).toBe(16);
expect(lastBFSNodes[0].key).toBe(12);
expect(lastBFSNodes[1].key).toBe(2);
expect(lastBFSNodes[2].key).toBe(16);
});
});

@@ -11,6 +11,6 @@ import {BinaryTree, BinaryTreeNode} from '../../../../src';

const node = new BinaryTreeNode<number>(1);
expect(node.id).toBe(1);
expect(node.key).toBe(1);
node.id = 2;
expect(node.id).toBe(2);
node.key = 2;
expect(node.key).toBe(2);
});

@@ -17,0 +17,0 @@

@@ -13,3 +13,3 @@ import {BST, BSTNode} from '../../../../src';

if (bst.root) expect(bst.root.id).toBe(11);
if (bst.root) expect(bst.root.key).toBe(11);

@@ -25,13 +25,13 @@ expect(bst.size).toBe(16);

const nodeId10 = bst.get(10);
expect(nodeId10?.id).toBe(10);
expect(nodeId10?.key).toBe(10);
const nodeVal9 = bst.get(9, 'val');
expect(nodeVal9?.id).toBe(9);
expect(nodeVal9?.key).toBe(9);
const leftMost = bst.getLeftMost();
expect(leftMost?.id).toBe(1);
expect(leftMost?.key).toBe(1);
const node15 = bst.get(15);
const minNodeBySpecificNode = node15 && bst.getLeftMost(node15);
expect(minNodeBySpecificNode?.id).toBe(12);
expect(minNodeBySpecificNode?.key).toBe(12);

@@ -50,4 +50,4 @@ const subTreeSum = node15 && bst.subTreeSum(15);

const dfsInorderNodes = bst.DFS('in', 'node');
expect(dfsInorderNodes[0].id).toBe(1);
expect(dfsInorderNodes[dfsInorderNodes.length - 1].id).toBe(16);
expect(dfsInorderNodes[0].key).toBe(1);
expect(dfsInorderNodes[dfsInorderNodes.length - 1].key).toBe(16);

@@ -58,4 +58,4 @@ bst.perfectlyBalance();

const bfsNodesAfterBalanced = bst.BFS('node');
expect(bfsNodesAfterBalanced[0].id).toBe(8);
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].id).toBe(16);
expect(bfsNodesAfterBalanced[0].key).toBe(8);
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);

@@ -67,3 +67,3 @@ const removed11 = bst.remove(11);

if (removed11[0].deleted) expect(removed11[0].deleted.id).toBe(11);
if (removed11[0].deleted) expect(removed11[0].deleted.key).toBe(11);

@@ -78,3 +78,3 @@ expect(bst.isAVLBalanced()).toBe(true);

expect(removed1[0].deleted).toBeDefined();
if (removed1[0].deleted) expect(removed1[0].deleted.id).toBe(1);
if (removed1[0].deleted) expect(removed1[0].deleted.key).toBe(1);

@@ -89,3 +89,3 @@ expect(bst.isAVLBalanced()).toBe(true);

expect(removed4[0].deleted).toBeDefined();
if (removed4[0].deleted) expect(removed4[0].deleted.id).toBe(4);
if (removed4[0].deleted) expect(removed4[0].deleted.key).toBe(4);
expect(bst.isAVLBalanced()).toBe(true);

@@ -98,3 +98,3 @@ expect(bst.getHeight()).toBe(4);

expect(removed10[0].deleted).toBeDefined();
if (removed10[0].deleted) expect(removed10[0].deleted.id).toBe(10);
if (removed10[0].deleted) expect(removed10[0].deleted.key).toBe(10);
expect(bst.isAVLBalanced()).toBe(false);

@@ -107,3 +107,3 @@ expect(bst.getHeight()).toBe(4);

expect(removed15[0].deleted).toBeDefined();
if (removed15[0].deleted) expect(removed15[0].deleted.id).toBe(15);
if (removed15[0].deleted) expect(removed15[0].deleted.key).toBe(15);

@@ -117,3 +117,3 @@ expect(bst.isAVLBalanced()).toBe(true);

expect(removed5[0].deleted).toBeDefined();
if (removed5[0].deleted) expect(removed5[0].deleted.id).toBe(5);
if (removed5[0].deleted) expect(removed5[0].deleted.key).toBe(5);

@@ -127,3 +127,3 @@ expect(bst.isAVLBalanced()).toBe(true);

expect(removed13[0].deleted).toBeDefined();
if (removed13[0].deleted) expect(removed13[0].deleted.id).toBe(13);
if (removed13[0].deleted) expect(removed13[0].deleted.key).toBe(13);
expect(bst.isAVLBalanced()).toBe(true);

@@ -136,3 +136,3 @@ expect(bst.getHeight()).toBe(3);

expect(removed3[0].deleted).toBeDefined();
if (removed3[0].deleted) expect(removed3[0].deleted.id).toBe(3);
if (removed3[0].deleted) expect(removed3[0].deleted.key).toBe(3);
expect(bst.isAVLBalanced()).toBe(false);

@@ -145,3 +145,3 @@ expect(bst.getHeight()).toBe(3);

expect(removed8[0].deleted).toBeDefined();
if (removed8[0].deleted) expect(removed8[0].deleted.id).toBe(8);
if (removed8[0].deleted) expect(removed8[0].deleted.key).toBe(8);
expect(bst.isAVLBalanced()).toBe(true);

@@ -154,3 +154,3 @@ expect(bst.getHeight()).toBe(3);

expect(removed6[0].deleted).toBeDefined();
if (removed6[0].deleted) expect(removed6[0].deleted.id).toBe(6);
if (removed6[0].deleted) expect(removed6[0].deleted.key).toBe(6);
expect(bst.remove(6).length).toBe(0);

@@ -164,3 +164,3 @@ expect(bst.isAVLBalanced()).toBe(false);

expect(removed7[0].deleted).toBeDefined();
if (removed7[0].deleted) expect(removed7[0].deleted.id).toBe(7);
if (removed7[0].deleted) expect(removed7[0].deleted.key).toBe(7);
expect(bst.isAVLBalanced()).toBe(false);

@@ -173,3 +173,3 @@ expect(bst.getHeight()).toBe(3);

expect(removed9[0].deleted).toBeDefined();
if (removed9[0].deleted) expect(removed9[0].deleted.id).toBe(9);
if (removed9[0].deleted) expect(removed9[0].deleted.key).toBe(9);
expect(bst.isAVLBalanced()).toBe(false);

@@ -182,3 +182,3 @@ expect(bst.getHeight()).toBe(3);

expect(removed14[0].deleted).toBeDefined();
if (removed14[0].deleted) expect(removed14[0].deleted.id).toBe(14);
if (removed14[0].deleted) expect(removed14[0].deleted.key).toBe(14);
expect(bst.isAVLBalanced()).toBe(false);

@@ -195,31 +195,31 @@ expect(bst.getHeight()).toBe(2);

const bfsNodes = bst.BFS('node');
expect(bfsNodes[0].id).toBe(2);
expect(bfsNodes[1].id).toBe(12);
expect(bfsNodes[2].id).toBe(16);
expect(bfsNodes[0].key).toBe(2);
expect(bfsNodes[1].key).toBe(12);
expect(bfsNodes[2].key).toBe(16);
});
it('should perform various operations on a Binary Search Tree with object values', () => {
const objBST = new BST<BSTNode<{id: number; keyA: number}>>();
const objBST = new BST<BSTNode<{key: number; keyA: number}>>();
expect(objBST).toBeInstanceOf(BST);
objBST.add(11, {id: 11, keyA: 11});
objBST.add(3, {id: 3, keyA: 3});
objBST.add(11, {key: 11, keyA: 11});
objBST.add(3, {key: 3, keyA: 3});
const values = [
{id: 15, keyA: 15},
{id: 1, keyA: 1},
{id: 8, keyA: 8},
{id: 13, keyA: 13},
{id: 16, keyA: 16},
{id: 2, keyA: 2},
{id: 6, keyA: 6},
{id: 9, keyA: 9},
{id: 12, keyA: 12},
{id: 14, keyA: 14},
{id: 4, keyA: 4},
{id: 7, keyA: 7},
{id: 10, keyA: 10},
{id: 5, keyA: 5}
{key: 15, keyA: 15},
{key: 1, keyA: 1},
{key: 8, keyA: 8},
{key: 13, keyA: 13},
{key: 16, keyA: 16},
{key: 2, keyA: 2},
{key: 6, keyA: 6},
{key: 9, keyA: 9},
{key: 12, keyA: 12},
{key: 14, keyA: 14},
{key: 4, keyA: 4},
{key: 7, keyA: 7},
{key: 10, keyA: 10},
{key: 5, keyA: 5}
];
objBST.addMany(
values.map(item => item.id),
values.map(item => item.key),
values

@@ -230,3 +230,3 @@ );

if (objBST.root) expect(objBST.root.id).toBe(11);
if (objBST.root) expect(objBST.root.key).toBe(11);

@@ -239,15 +239,15 @@ expect(objBST.has(6)).toBe(true);

const nodeId10 = objBST.get(10, 'id');
expect(nodeId10?.id).toBe(10);
const nodeId10 = objBST.get(10, 'key');
expect(nodeId10?.key).toBe(10);
const nodeVal9 = objBST.get(9, 'id');
expect(nodeVal9?.id).toBe(9);
const nodeVal9 = objBST.get(9, 'key');
expect(nodeVal9?.key).toBe(9);
const leftMost = objBST.getLeftMost();
expect(leftMost?.id).toBe(1);
expect(leftMost?.key).toBe(1);
const node15 = objBST.get(15);
expect(node15?.val).toEqual({id: 15, keyA: 15});
expect(node15?.val).toEqual({key: 15, keyA: 15});
const minNodeBySpecificNode = node15 && objBST.getLeftMost(node15);
expect(minNodeBySpecificNode?.id).toBe(12);
expect(minNodeBySpecificNode?.key).toBe(12);

@@ -266,4 +266,4 @@ const subTreeSum = node15 && objBST.subTreeSum(node15);

const dfsInorderNodes = objBST.DFS('in', 'node');
expect(dfsInorderNodes[0].id).toBe(1);
expect(dfsInorderNodes[dfsInorderNodes.length - 1].id).toBe(16);
expect(dfsInorderNodes[0].key).toBe(1);
expect(dfsInorderNodes[dfsInorderNodes.length - 1].key).toBe(16);

@@ -274,4 +274,4 @@ objBST.perfectlyBalance();

const bfsNodesAfterBalanced = objBST.BFS('node');
expect(bfsNodesAfterBalanced[0].id).toBe(8);
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].id).toBe(16);
expect(bfsNodesAfterBalanced[0].key).toBe(8);
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);

@@ -283,3 +283,3 @@ const removed11 = objBST.remove(11);

if (removed11[0].deleted) expect(removed11[0].deleted.id).toBe(11);
if (removed11[0].deleted) expect(removed11[0].deleted.key).toBe(11);

@@ -294,3 +294,3 @@ expect(objBST.isAVLBalanced()).toBe(true);

expect(removed1[0].deleted).toBeDefined();
if (removed1[0].deleted) expect(removed1[0].deleted.id).toBe(1);
if (removed1[0].deleted) expect(removed1[0].deleted.key).toBe(1);

@@ -305,3 +305,3 @@ expect(objBST.isAVLBalanced()).toBe(true);

expect(removed4[0].deleted).toBeDefined();
if (removed4[0].deleted) expect(removed4[0].deleted.id).toBe(4);
if (removed4[0].deleted) expect(removed4[0].deleted.key).toBe(4);
expect(objBST.isAVLBalanced()).toBe(true);

@@ -314,3 +314,3 @@ expect(objBST.getHeight()).toBe(4);

expect(removed10[0].deleted).toBeDefined();
if (removed10[0].deleted) expect(removed10[0].deleted.id).toBe(10);
if (removed10[0].deleted) expect(removed10[0].deleted.key).toBe(10);
expect(objBST.isAVLBalanced()).toBe(false);

@@ -323,3 +323,3 @@ expect(objBST.getHeight()).toBe(4);

expect(removed15[0].deleted).toBeDefined();
if (removed15[0].deleted) expect(removed15[0].deleted.id).toBe(15);
if (removed15[0].deleted) expect(removed15[0].deleted.key).toBe(15);

@@ -333,3 +333,3 @@ expect(objBST.isAVLBalanced()).toBe(true);

expect(removed5[0].deleted).toBeDefined();
if (removed5[0].deleted) expect(removed5[0].deleted.id).toBe(5);
if (removed5[0].deleted) expect(removed5[0].deleted.key).toBe(5);

@@ -343,3 +343,3 @@ expect(objBST.isAVLBalanced()).toBe(true);

expect(removed13[0].deleted).toBeDefined();
if (removed13[0].deleted) expect(removed13[0].deleted.id).toBe(13);
if (removed13[0].deleted) expect(removed13[0].deleted.key).toBe(13);
expect(objBST.isAVLBalanced()).toBe(true);

@@ -352,3 +352,3 @@ expect(objBST.getHeight()).toBe(3);

expect(removed3[0].deleted).toBeDefined();
if (removed3[0].deleted) expect(removed3[0].deleted.id).toBe(3);
if (removed3[0].deleted) expect(removed3[0].deleted.key).toBe(3);
expect(objBST.isAVLBalanced()).toBe(false);

@@ -361,3 +361,3 @@ expect(objBST.getHeight()).toBe(3);

expect(removed8[0].deleted).toBeDefined();
if (removed8[0].deleted) expect(removed8[0].deleted.id).toBe(8);
if (removed8[0].deleted) expect(removed8[0].deleted.key).toBe(8);
expect(objBST.isAVLBalanced()).toBe(true);

@@ -370,3 +370,3 @@ expect(objBST.getHeight()).toBe(3);

expect(removed6[0].deleted).toBeDefined();
if (removed6[0].deleted) expect(removed6[0].deleted.id).toBe(6);
if (removed6[0].deleted) expect(removed6[0].deleted.key).toBe(6);
expect(objBST.remove(6).length).toBe(0);

@@ -380,3 +380,3 @@ expect(objBST.isAVLBalanced()).toBe(false);

expect(removed7[0].deleted).toBeDefined();
if (removed7[0].deleted) expect(removed7[0].deleted.id).toBe(7);
if (removed7[0].deleted) expect(removed7[0].deleted.key).toBe(7);
expect(objBST.isAVLBalanced()).toBe(false);

@@ -389,3 +389,3 @@ expect(objBST.getHeight()).toBe(3);

expect(removed9[0].deleted).toBeDefined();
if (removed9[0].deleted) expect(removed9[0].deleted.id).toBe(9);
if (removed9[0].deleted) expect(removed9[0].deleted.key).toBe(9);
expect(objBST.isAVLBalanced()).toBe(false);

@@ -398,3 +398,3 @@ expect(objBST.getHeight()).toBe(3);

expect(removed14[0].deleted).toBeDefined();
if (removed14[0].deleted) expect(removed14[0].deleted.id).toBe(14);
if (removed14[0].deleted) expect(removed14[0].deleted.key).toBe(14);
expect(objBST.isAVLBalanced()).toBe(false);

@@ -411,6 +411,6 @@ expect(objBST.getHeight()).toBe(2);

const bfsNodes = objBST.BFS('node');
expect(bfsNodes[0].id).toBe(2);
expect(bfsNodes[1].id).toBe(12);
expect(bfsNodes[2].id).toBe(16);
expect(bfsNodes[0].key).toBe(2);
expect(bfsNodes[1].key).toBe(12);
expect(bfsNodes[2].key).toBe(16);
});
});

@@ -20,4 +20,4 @@ import {AVLTree, BST, BSTNode} from '../../../../src';

const leftMost = bst.getLeftMost();
leftMost?.id === 1; // true
expect(leftMost?.id).toBe(1);
leftMost?.key === 1; // true
expect(leftMost?.key).toBe(1);
bst.remove(6);

@@ -32,5 +32,5 @@ bst.get(6); // null

const objBST = new BST<BSTNode<{id: number; keyA: number}>>();
objBST.add(11, {id: 11, keyA: 11});
objBST.add(3, {id: 3, keyA: 3});
const objBST = new BST<BSTNode<{key: number; keyA: number}>>();
objBST.add(11, {key: 11, keyA: 11});
objBST.add(3, {key: 3, keyA: 3});

@@ -40,16 +40,16 @@ objBST.addMany(

[
{id: 15, keyA: 15},
{id: 1, keyA: 1},
{id: 8, keyA: 8},
{id: 13, keyA: 13},
{id: 16, keyA: 16},
{id: 2, keyA: 2},
{id: 6, keyA: 6},
{id: 9, keyA: 9},
{id: 12, keyA: 12},
{id: 14, keyA: 14},
{id: 4, keyA: 4},
{id: 7, keyA: 7},
{id: 10, keyA: 10},
{id: 5, keyA: 5}
{key: 15, keyA: 15},
{key: 1, keyA: 1},
{key: 8, keyA: 8},
{key: 13, keyA: 13},
{key: 16, keyA: 16},
{key: 2, keyA: 2},
{key: 6, keyA: 6},
{key: 9, keyA: 9},
{key: 12, keyA: 12},
{key: 14, keyA: 14},
{key: 4, keyA: 4},
{key: 7, keyA: 7},
{key: 10, keyA: 10},
{key: 5, keyA: 5}
]

@@ -56,0 +56,0 @@ );

@@ -14,7 +14,7 @@ import {TreeMultiset, TreeMultisetNode} from '../../../../src';

if (treeMultiset.root) expect(treeMultiset.root.id == 11);
if (treeMultiset.root) expect(treeMultiset.root.key == 11);
expect(treeMultiset.size).toBe(16);
expect(treeMultiset.count).toBe(18);
expect(treeMultiset.BFS('id'));
expect(treeMultiset.BFS('key'));

@@ -26,6 +26,6 @@ expect(treeMultiset.has(6));

const nodeId10 = treeMultiset.get(10);
expect(nodeId10?.id).toBe(10);
expect(nodeId10?.key).toBe(10);
const nodeVal9 = treeMultiset.get(9, 'val');
expect(nodeVal9?.id).toBe(9);
expect(nodeVal9?.key).toBe(9);

@@ -38,7 +38,7 @@ const nodesByCount1 = treeMultiset.getNodesByCount(1);

const leftMost = treeMultiset.getLeftMost();
expect(leftMost?.id).toBe(1);
expect(leftMost?.key).toBe(1);
const node15 = treeMultiset.get(15);
const minNodeBySpecificNode = node15 && treeMultiset.getLeftMost(node15);
expect(minNodeBySpecificNode?.id).toBe(12);
expect(minNodeBySpecificNode?.key).toBe(12);

@@ -63,4 +63,4 @@ const subTreeSum = node15 && treeMultiset.subTreeSum(15);

const dfsInorderNodes = treeMultiset.DFS('in', 'node');
expect(dfsInorderNodes[0].id).toBe(1);
expect(dfsInorderNodes[dfsInorderNodes.length - 1].id).toBe(16);
expect(dfsInorderNodes[0].key).toBe(1);
expect(dfsInorderNodes[dfsInorderNodes.length - 1].key).toBe(16);
expect(treeMultiset.isPerfectlyBalanced()).toBe(false);

@@ -74,4 +74,4 @@

const bfsNodesAfterBalanced = treeMultiset.BFS('node');
expect(bfsNodesAfterBalanced[0].id).toBe(8);
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].id).toBe(16);
expect(bfsNodesAfterBalanced[0].key).toBe(8);
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);

@@ -83,3 +83,3 @@ const removed11 = treeMultiset.remove(11, true);

if (removed11[0].deleted) expect(removed11[0].deleted.id).toBe(11);
if (removed11[0].deleted) expect(removed11[0].deleted.key).toBe(11);

@@ -94,3 +94,3 @@ expect(treeMultiset.isAVLBalanced()).toBe(true);

expect(removed1[0].deleted);
if (removed1[0].deleted) expect(removed1[0].deleted.id).toBe(1);
if (removed1[0].deleted) expect(removed1[0].deleted.key).toBe(1);

@@ -105,3 +105,3 @@ expect(treeMultiset.isAVLBalanced()).toBe(true);

expect(removed4[0].deleted);
if (removed4[0].deleted) expect(removed4[0].deleted.id).toBe(4);
if (removed4[0].deleted) expect(removed4[0].deleted.key).toBe(4);

@@ -115,3 +115,3 @@ expect(treeMultiset.isAVLBalanced()).toBe(true);

expect(removed10[0].deleted);
if (removed10[0].deleted) expect(removed10[0].deleted.id).toBe(10);
if (removed10[0].deleted) expect(removed10[0].deleted.key).toBe(10);
expect(treeMultiset.isAVLBalanced()).toBe(true);

@@ -125,3 +125,3 @@

expect(removed15[0].deleted);
if (removed15[0].deleted) expect(removed15[0].deleted.id).toBe(15);
if (removed15[0].deleted) expect(removed15[0].deleted.key).toBe(15);

@@ -135,3 +135,3 @@ expect(treeMultiset.isAVLBalanced()).toBe(true);

expect(removed5[0].deleted);
if (removed5[0].deleted) expect(removed5[0].deleted.id).toBe(5);
if (removed5[0].deleted) expect(removed5[0].deleted.key).toBe(5);

@@ -145,3 +145,3 @@ expect(treeMultiset.isAVLBalanced()).toBe(true);

expect(removed13[0].deleted);
if (removed13[0].deleted) expect(removed13[0].deleted.id).toBe(13);
if (removed13[0].deleted) expect(removed13[0].deleted.key).toBe(13);
expect(treeMultiset.isAVLBalanced()).toBe(true);

@@ -154,3 +154,3 @@ expect(treeMultiset.getHeight()).toBe(3);

expect(removed3[0].deleted);
if (removed3[0].deleted) expect(removed3[0].deleted.id).toBe(3);
if (removed3[0].deleted) expect(removed3[0].deleted.key).toBe(3);
expect(treeMultiset.isAVLBalanced()).toBe(true);

@@ -163,3 +163,3 @@ expect(treeMultiset.getHeight()).toBe(3);

expect(removed8[0].deleted);
if (removed8[0].deleted) expect(removed8[0].deleted.id).toBe(8);
if (removed8[0].deleted) expect(removed8[0].deleted.key).toBe(8);
expect(treeMultiset.isAVLBalanced()).toBe(true);

@@ -172,3 +172,3 @@ expect(treeMultiset.getHeight()).toBe(3);

expect(removed6[0].deleted);
if (removed6[0].deleted) expect(removed6[0].deleted.id).toBe(6);
if (removed6[0].deleted) expect(removed6[0].deleted.key).toBe(6);
expect(treeMultiset.remove(6, true).length).toBe(0);

@@ -183,3 +183,3 @@ expect(treeMultiset.isAVLBalanced()).toBe(true);

expect(removed7[0].deleted);
if (removed7[0].deleted) expect(removed7[0].deleted.id).toBe(7);
if (removed7[0].deleted) expect(removed7[0].deleted.key).toBe(7);
expect(treeMultiset.isAVLBalanced()).toBe(true);

@@ -192,3 +192,3 @@ expect(treeMultiset.getHeight()).toBe(2);

expect(removed9[0].deleted);
if (removed9[0].deleted) expect(removed9[0].deleted.id).toBe(9);
if (removed9[0].deleted) expect(removed9[0].deleted.key).toBe(9);
expect(treeMultiset.isAVLBalanced()).toBe(true);

@@ -201,3 +201,3 @@ expect(treeMultiset.getHeight()).toBe(2);

expect(removed14[0].deleted);
if (removed14[0].deleted) expect(removed14[0].deleted.id).toBe(14);
if (removed14[0].deleted) expect(removed14[0].deleted.key).toBe(14);
expect(treeMultiset.isAVLBalanced()).toBe(true);

@@ -216,5 +216,5 @@ expect(treeMultiset.getHeight()).toBe(1);

expect(bfsNodes[0].id).toBe(12);
expect(bfsNodes[1].id).toBe(2);
expect(bfsNodes[2].id).toBe(16);
expect(bfsNodes[0].key).toBe(12);
expect(bfsNodes[1].key).toBe(2);
expect(bfsNodes[2].key).toBe(16);

@@ -225,25 +225,25 @@ expect(treeMultiset.count).toBe(9);

it('should perform various operations on a Binary Search Tree with object values', () => {
const objTreeMultiset = new TreeMultiset<TreeMultisetNode<{id: number; keyA: number}>>();
const objTreeMultiset = new TreeMultiset<TreeMultisetNode<{key: number; keyA: number}>>();
expect(objTreeMultiset).toBeInstanceOf(TreeMultiset);
objTreeMultiset.add(11, {id: 11, keyA: 11});
objTreeMultiset.add(3, {id: 3, keyA: 3});
objTreeMultiset.add(11, {key: 11, keyA: 11});
objTreeMultiset.add(3, {key: 3, keyA: 3});
const values = [
{id: 15, keyA: 15},
{id: 1, keyA: 1},
{id: 8, keyA: 8},
{id: 13, keyA: 13},
{id: 16, keyA: 16},
{id: 2, keyA: 2},
{id: 6, keyA: 6},
{id: 9, keyA: 9},
{id: 12, keyA: 12},
{id: 14, keyA: 14},
{id: 4, keyA: 4},
{id: 7, keyA: 7},
{id: 10, keyA: 10},
{id: 5, keyA: 5}
{key: 15, keyA: 15},
{key: 1, keyA: 1},
{key: 8, keyA: 8},
{key: 13, keyA: 13},
{key: 16, keyA: 16},
{key: 2, keyA: 2},
{key: 6, keyA: 6},
{key: 9, keyA: 9},
{key: 12, keyA: 12},
{key: 14, keyA: 14},
{key: 4, keyA: 4},
{key: 7, keyA: 7},
{key: 10, keyA: 10},
{key: 5, keyA: 5}
];
objTreeMultiset.addMany(
values.map(item => item.id),
values.map(item => item.key),
values

@@ -254,3 +254,3 @@ );

if (objTreeMultiset.root) expect(objTreeMultiset.root.id).toBe(11);
if (objTreeMultiset.root) expect(objTreeMultiset.root.key).toBe(11);

@@ -265,7 +265,7 @@ expect(objTreeMultiset.count).toBe(16);

//
// const nodeId10 = objTreeMultiset.get(10, 'id');
// expect(nodeId10?.id).toBe(10);
// const nodeId10 = objTreeMultiset.get(10, 'key');
// expect(nodeId10?.key).toBe(10);
//
// const nodeVal9 = objTreeMultiset.get(9, 'id');
// expect(nodeVal9?.id).toBe(9);
// const nodeVal9 = objTreeMultiset.get(9, 'key');
// expect(nodeVal9?.key).toBe(9);
//

@@ -276,8 +276,8 @@ // const nodesByCount1 = objTreeMultiset.getNodesByCount(1);

// const leftMost = objTreeMultiset.getLeftMost();
// expect(leftMost?.id).toBe(1);
// expect(leftMost?.key).toBe(1);
//
// const node15 = objTreeMultiset.get(15);
// expect(node15?.val).toEqual({id: 15, keyA: 15});
// expect(node15?.val).toEqual({key: 15, keyA: 15});
// const minNodeBySpecificNode = node15 && objTreeMultiset.getLeftMost(node15);
// expect(minNodeBySpecificNode?.id).toBe(12);
// expect(minNodeBySpecificNode?.key).toBe(12);
//

@@ -304,4 +304,4 @@ // const subTreeSum = node15 && objTreeMultiset.subTreeSum(node15);

// const dfsInorderNodes = objTreeMultiset.DFS('in', 'node');
// expect(dfsInorderNodes[0].id).toBe(1);
// expect(dfsInorderNodes[dfsInorderNodes.length - 1].id).toBe(16);
// expect(dfsInorderNodes[0].key).toBe(1);
// expect(dfsInorderNodes[dfsInorderNodes.length - 1].key).toBe(16);
//

@@ -312,4 +312,4 @@ // objTreeMultiset.perfectlyBalance();

// const bfsNodesAfterBalanced = objTreeMultiset.BFS('node');
// expect(bfsNodesAfterBalanced[0].id).toBe(8);
// expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].id).toBe(16);
// expect(bfsNodesAfterBalanced[0].key).toBe(8);
// expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);
//

@@ -321,3 +321,3 @@ // const removed11 = objTreeMultiset.remove(11, true);

//
// if (removed11[0].deleted) expect(removed11[0].deleted.id).toBe(11);
// if (removed11[0].deleted) expect(removed11[0].deleted.key).toBe(11);
//

@@ -332,3 +332,3 @@ // expect(objTreeMultiset.isAVLBalanced()).toBe(true);

// expect(removed1[0].deleted).toBeDefined();
// if (removed1[0].deleted) expect(removed1[0].deleted.id).toBe(1);
// if (removed1[0].deleted) expect(removed1[0].deleted.key).toBe(1);
//

@@ -343,3 +343,3 @@ // expect(objTreeMultiset.isAVLBalanced()).toBe(true);

// expect(removed4[0].deleted).toBeDefined();
// if (removed4[0].deleted) expect(removed4[0].deleted.id).toBe(4);
// if (removed4[0].deleted) expect(removed4[0].deleted.key).toBe(4);
// expect(objTreeMultiset.isAVLBalanced()).toBe(true);

@@ -352,3 +352,3 @@ // expect(objTreeMultiset.getHeight()).toBe(4);

// expect(removed10[0].deleted).toBeDefined();
// if (removed10[0].deleted) expect(removed10[0].deleted.id).toBe(10);
// if (removed10[0].deleted) expect(removed10[0].deleted.key).toBe(10);
// expect(objTreeMultiset.isAVLBalanced()).toBe(false);

@@ -361,3 +361,3 @@ // expect(objTreeMultiset.getHeight()).toBe(4);

// expect(removed15[0].deleted).toBeDefined();
// if (removed15[0].deleted) expect(removed15[0].deleted.id).toBe(15);
// if (removed15[0].deleted) expect(removed15[0].deleted.key).toBe(15);
//

@@ -371,3 +371,3 @@ // expect(objTreeMultiset.isAVLBalanced()).toBe(true);

// expect(removed5[0].deleted).toBeDefined();
// if (removed5[0].deleted) expect(removed5[0].deleted.id).toBe(5);
// if (removed5[0].deleted) expect(removed5[0].deleted.key).toBe(5);
//

@@ -381,3 +381,3 @@ // expect(objTreeMultiset.isAVLBalanced()).toBe(true);

// expect(removed13[0].deleted).toBeDefined();
// if (removed13[0].deleted) expect(removed13[0].deleted.id).toBe(13);
// if (removed13[0].deleted) expect(removed13[0].deleted.key).toBe(13);
// expect(objTreeMultiset.isAVLBalanced()).toBe(true);

@@ -390,3 +390,3 @@ // expect(objTreeMultiset.getHeight()).toBe(3);

// expect(removed3[0].deleted).toBeDefined();
// if (removed3[0].deleted) expect(removed3[0].deleted.id).toBe(3);
// if (removed3[0].deleted) expect(removed3[0].deleted.key).toBe(3);
// expect(objTreeMultiset.isAVLBalanced()).toBe(false);

@@ -399,3 +399,3 @@ // expect(objTreeMultiset.getHeight()).toBe(3);

// expect(removed8[0].deleted).toBeDefined();
// if (removed8[0].deleted) expect(removed8[0].deleted.id).toBe(8);
// if (removed8[0].deleted) expect(removed8[0].deleted.key).toBe(8);
// expect(objTreeMultiset.isAVLBalanced()).toBe(true);

@@ -408,3 +408,3 @@ // expect(objTreeMultiset.getHeight()).toBe(3);

// expect(removed6[0].deleted).toBeDefined();
// if (removed6[0].deleted) expect(removed6[0].deleted.id).toBe(6);
// if (removed6[0].deleted) expect(removed6[0].deleted.key).toBe(6);
// expect(objTreeMultiset.remove(6, true).length).toBe(0);

@@ -418,3 +418,3 @@ // expect(objTreeMultiset.isAVLBalanced()).toBe(false);

// expect(removed7[0].deleted).toBeDefined();
// if (removed7[0].deleted) expect(removed7[0].deleted.id).toBe(7);
// if (removed7[0].deleted) expect(removed7[0].deleted.key).toBe(7);
// expect(objTreeMultiset.isAVLBalanced()).toBe(false);

@@ -427,3 +427,3 @@ // expect(objTreeMultiset.getHeight()).toBe(3);

// expect(removed9[0].deleted).toBeDefined();
// if (removed9[0].deleted) expect(removed9[0].deleted.id).toBe(9);
// if (removed9[0].deleted) expect(removed9[0].deleted.key).toBe(9);
// expect(objTreeMultiset.isAVLBalanced()).toBe(false);

@@ -436,3 +436,3 @@ // expect(objTreeMultiset.getHeight()).toBe(3);

// expect(removed14[0].deleted).toBeDefined();
// if (removed14[0].deleted) expect(removed14[0].deleted.id).toBe(14);
// if (removed14[0].deleted) expect(removed14[0].deleted.key).toBe(14);
// expect(objTreeMultiset.isAVLBalanced()).toBe(false);

@@ -450,5 +450,5 @@ // expect(objTreeMultiset.getHeight()).toBe(2);

// const bfsNodes = objTreeMultiset.BFS('node');
// expect(bfsNodes[0].id).toBe(2);
// expect(bfsNodes[1].id).toBe(12);
// expect(bfsNodes[2].id).toBe(16);
// expect(bfsNodes[0].key).toBe(2);
// expect(bfsNodes[1].key).toBe(12);
// expect(bfsNodes[2].key).toBe(16);
//

@@ -455,0 +455,0 @@ // expect(objTreeMultiset.count).toBe(5);

@@ -66,4 +66,4 @@ import {DirectedEdge, DirectedGraph, DirectedVertex, VertexId} from '../../../../src';

class MyVertex<V extends string> extends DirectedVertex<V> {
constructor(id: VertexId, val?: V) {
super(id, val);
constructor(key: VertexId, val?: V) {
super(key, val);
this._data = val;

@@ -101,4 +101,4 @@ }

class MyDirectedGraph<V extends MyVertex<string>, E extends MyEdge<string>> extends DirectedGraph<V, E> {
createVertex(id: VertexId, val: V['val']): V {
return new MyVertex(id, val) as V;
createVertex(key: VertexId, val: V['val']): V {
return new MyVertex(key, val) as V;
}

@@ -188,3 +188,3 @@

sorted[3] instanceof MyVertex && expect(sorted[3].data).toBe('data6');
sorted[8] instanceof MyVertex && expect(sorted[8].id).toBe(1);
sorted[8] instanceof MyVertex && expect(sorted[8].key).toBe(1);
}

@@ -272,5 +272,5 @@ });

expect(minPath1to7[0]).toBeInstanceOf(MyVertex);
expect(minPath1to7[0].id).toBe(1);
expect(minPath1to7[1].id).toBe(9);
expect(minPath1to7[2].id).toBe(7);
expect(minPath1to7[0].key).toBe(1);
expect(minPath1to7[1].key).toBe(9);
expect(minPath1to7[2].key).toBe(7);
}

@@ -277,0 +277,0 @@

@@ -33,5 +33,5 @@ import {MapGraph, MapVertex} from '../../../../src';

const minPathBetween = mapGraph.getMinPathBetween('Surin', 'Saanen Goat Farm');
expect(minPathBetween?.map(v => v.id)).toEqual(expected1);
expect(minPathBetween?.map(v => v.key)).toEqual(expected1);
const surinToSaanenGoatFarmDij = mapGraph.dijkstra('Surin', 'Saanen Goat Farm', true, true);
expect(surinToSaanenGoatFarmDij?.minPath.map(v => v.id)).toEqual(expected1);
expect(surinToSaanenGoatFarmDij?.minPath.map(v => v.key)).toEqual(expected1);
expect(surinToSaanenGoatFarmDij?.minDist).toBe(41.1);

@@ -41,7 +41,7 @@ mapGraph.addEdge('Surin', 'Batu Feringgi Beach', 1.5);

const minPathBetweenViaBFB = mapGraph.getMinPathBetween('Surin', 'Saanen Goat Farm', true);
expect(minPathBetweenViaBFB?.map(v => v.id)).toEqual(expected2);
expect(minPathBetweenViaBFB?.map(v => v.key)).toEqual(expected2);
const surinToSaanenGoatFarmViaDij = mapGraph.dijkstra('Surin', 'Saanen Goat Farm', true, true);
expect(surinToSaanenGoatFarmViaDij?.minPath.map(v => v.id)).toEqual(expected2);
expect(surinToSaanenGoatFarmViaDij?.minPath.map(v => v.key)).toEqual(expected2);
expect(surinToSaanenGoatFarmViaDij?.minDist).toBe(25.2);
});
});

@@ -46,5 +46,5 @@ import {DirectedGraph, UndirectedGraph} from '../../../../src';

const dijkstraResult = graph.dijkstra('A');
Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id); // ['A', 'B', 'D']
expect(Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id)).toEqual(['A', 'B', 'D']);
Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key); // ['A', 'B', 'D']
expect(Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key)).toEqual(['A', 'B', 'D']);
});
});

@@ -57,4 +57,4 @@ import {UndirectedEdge, UndirectedGraph, UndirectedVertex} from '../../../../src';

const dijkstraResult = graph.dijkstra('A');
expect(Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id)).toEqual(['A', 'B', 'D']);
expect(Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key)).toEqual(['A', 'B', 'D']);
});
});

@@ -70,2 +70,1 @@ import {PriorityQueue} from '../../../../src';

});
import {TreeNode} from '../../../../src';
describe('TreeNode', () => {
it('should create a TreeNode with the given id and value', () => {
it('should create a TreeNode with the given key and value', () => {
const node = new TreeNode<string>('1', 'Node 1');
expect(node.id).toBe('1');
expect(node.key).toBe('1');
expect(node.value).toBe('Node 1');

@@ -8,0 +8,0 @@ expect(node.children).toEqual([]);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc