priority-queue-typed 1.46.4 → 1.46.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/binary-tree/binary-tree.d.ts +2 -1
- package/dist/data-structures/binary-tree/binary-tree.js +29 -46
- package/dist/data-structures/binary-tree/rb-tree.js +10 -5
- package/dist/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/data-structures/hash/hash-map.js +1 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/utils/utils.d.ts +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +33 -46
- package/src/data-structures/binary-tree/rb-tree.ts +9 -4
- package/src/data-structures/hash/hash-map.ts +4 -5
- package/src/index.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +1 -1
- package/src/types/index.ts +1 -1
- package/src/utils/utils.ts +1 -1
- /package/dist/types/{helpers.d.ts → common.d.ts} +0 -0
- /package/dist/types/{helpers.js → common.js} +0 -0
- /package/src/types/{helpers.ts → common.ts} +0 -0
|
@@ -441,11 +441,12 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
441
441
|
[Symbol.iterator](node?: N | null | undefined): Generator<BTNKey, void, undefined>;
|
|
442
442
|
/**
|
|
443
443
|
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
444
|
-
* @param {N | null | undefined}
|
|
444
|
+
* @param {N | null | undefined} beginRoot - The `root` parameter is of type `BTNKey | N | null |
|
|
445
445
|
* undefined`. It represents the root node of a binary tree. The root node can have one of the
|
|
446
446
|
* following types:
|
|
447
447
|
*/
|
|
448
448
|
print(beginRoot?: BTNKey | N | null | undefined): void;
|
|
449
|
+
protected _displayAux(node: N | null | undefined): [string[], number, number, number];
|
|
449
450
|
protected _defaultOneParamCallback: (node: N) => number;
|
|
450
451
|
/**
|
|
451
452
|
* Swap the data of two nodes in the binary tree.
|
|
@@ -1447,7 +1447,7 @@ class BinaryTree {
|
|
|
1447
1447
|
}
|
|
1448
1448
|
/**
|
|
1449
1449
|
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
1450
|
-
* @param {N | null | undefined}
|
|
1450
|
+
* @param {N | null | undefined} beginRoot - The `root` parameter is of type `BTNKey | N | null |
|
|
1451
1451
|
* undefined`. It represents the root node of a binary tree. The root node can have one of the
|
|
1452
1452
|
* following types:
|
|
1453
1453
|
*/
|
|
@@ -1456,57 +1456,40 @@ class BinaryTree {
|
|
|
1456
1456
|
if (!beginRoot)
|
|
1457
1457
|
return;
|
|
1458
1458
|
const display = (root) => {
|
|
1459
|
-
const [lines, , ,] = _displayAux(root);
|
|
1459
|
+
const [lines, , ,] = this._displayAux(root);
|
|
1460
1460
|
for (const line of lines) {
|
|
1461
1461
|
console.log(line);
|
|
1462
1462
|
}
|
|
1463
1463
|
};
|
|
1464
|
-
const _displayAux = (node) => {
|
|
1465
|
-
if (!this.isRealNode(node)) {
|
|
1466
|
-
return [[], 0, 0, 0];
|
|
1467
|
-
}
|
|
1468
|
-
if (this.isRealNode(node) && !this.isRealNode(node.right) && !this.isRealNode(node.left)) {
|
|
1469
|
-
const line = `${node.key}`;
|
|
1470
|
-
const width = line.length;
|
|
1471
|
-
const height = 1;
|
|
1472
|
-
const middle = Math.floor(width / 2);
|
|
1473
|
-
return [[line], width, height, middle];
|
|
1474
|
-
}
|
|
1475
|
-
if (this.isRealNode(node) && !this.isRealNode(node.right)) {
|
|
1476
|
-
const [lines, n, p, x] = _displayAux(node.left);
|
|
1477
|
-
const s = `${node.key}`;
|
|
1478
|
-
const u = s.length;
|
|
1479
|
-
const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s;
|
|
1480
|
-
const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u);
|
|
1481
|
-
const shifted_lines = lines.map(line => line + ' '.repeat(u));
|
|
1482
|
-
return [[first_line, second_line, ...shifted_lines], n + u, p + 2, n + Math.floor(u / 2)];
|
|
1483
|
-
}
|
|
1484
|
-
if (this.isRealNode(node) && !this.isRealNode(node.left)) {
|
|
1485
|
-
const [lines, n, p, u] = _displayAux(node.right);
|
|
1486
|
-
const s = `${node.key}`;
|
|
1487
|
-
const x = s.length;
|
|
1488
|
-
const first_line = s + '_'.repeat(x) + ' '.repeat(n - x);
|
|
1489
|
-
const second_line = ' '.repeat(u + x) + '\\' + ' '.repeat(n - x - 1);
|
|
1490
|
-
const shifted_lines = lines.map(line => ' '.repeat(u) + line);
|
|
1491
|
-
return [[first_line, second_line, ...shifted_lines], n + x, p + 2, Math.floor(u / 2)];
|
|
1492
|
-
}
|
|
1493
|
-
const [left, n, p, x] = _displayAux(node.left);
|
|
1494
|
-
const [right, m, q, y] = _displayAux(node.right);
|
|
1495
|
-
const s = `${node.key}`;
|
|
1496
|
-
const u = s.length;
|
|
1497
|
-
const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s + '_'.repeat(y) + ' '.repeat(m - y);
|
|
1498
|
-
const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u + y) + '\\' + ' '.repeat(m - y - 1);
|
|
1499
|
-
if (p < q) {
|
|
1500
|
-
left.push(...new Array(q - p).fill(' '.repeat(n)));
|
|
1501
|
-
}
|
|
1502
|
-
else if (q < p) {
|
|
1503
|
-
right.push(...new Array(p - q).fill(' '.repeat(m)));
|
|
1504
|
-
}
|
|
1505
|
-
const zipped_lines = left.map((a, i) => a + ' '.repeat(u) + right[i]);
|
|
1506
|
-
return [[first_line, second_line, ...zipped_lines], n + m + u, Math.max(p, q) + 2, n + Math.floor(u / 2)];
|
|
1507
|
-
};
|
|
1508
1464
|
display(beginRoot);
|
|
1509
1465
|
}
|
|
1466
|
+
_displayAux(node) {
|
|
1467
|
+
if (!node) {
|
|
1468
|
+
return [['─'], 1, 0, 0];
|
|
1469
|
+
}
|
|
1470
|
+
const line = node.key.toString();
|
|
1471
|
+
const width = line.length;
|
|
1472
|
+
if (!node.left && !node.right) {
|
|
1473
|
+
return [[line], width, 1, Math.floor(width / 2)];
|
|
1474
|
+
}
|
|
1475
|
+
const [leftLines, leftWidth, leftHeight, leftMiddle] = node.left ? this._displayAux(node.left) : [[''], 0, 0, 0];
|
|
1476
|
+
const [rightLines, rightWidth, rightHeight, rightMiddle] = node.right ? this._displayAux(node.right) : [[''], 0, 0, 0];
|
|
1477
|
+
const firstLine = ' '.repeat(Math.max(0, leftMiddle + 1))
|
|
1478
|
+
+ '_'.repeat(Math.max(0, leftWidth - leftMiddle - 1))
|
|
1479
|
+
+ line
|
|
1480
|
+
+ '_'.repeat(Math.max(0, rightMiddle))
|
|
1481
|
+
+ ' '.repeat(Math.max(0, rightWidth - rightMiddle));
|
|
1482
|
+
const secondLine = (leftHeight > 0 ? ' '.repeat(leftMiddle) + '/' + ' '.repeat(leftWidth - leftMiddle - 1) : ' '.repeat(leftWidth))
|
|
1483
|
+
+ ' '.repeat(width)
|
|
1484
|
+
+ (rightHeight > 0 ? ' '.repeat(rightMiddle) + '\\' + ' '.repeat(rightWidth - rightMiddle - 1) : ' '.repeat(rightWidth));
|
|
1485
|
+
const mergedLines = [firstLine, secondLine];
|
|
1486
|
+
for (let i = 0; i < Math.max(leftHeight, rightHeight); i++) {
|
|
1487
|
+
const leftLine = i < leftHeight ? leftLines[i] : ' '.repeat(leftWidth);
|
|
1488
|
+
const rightLine = i < rightHeight ? rightLines[i] : ' '.repeat(rightWidth);
|
|
1489
|
+
mergedLines.push(leftLine + ' '.repeat(width) + rightLine);
|
|
1490
|
+
}
|
|
1491
|
+
return [mergedLines, leftWidth + width + rightWidth, Math.max(leftHeight, rightHeight) + 2, leftWidth + Math.floor(width / 2)];
|
|
1492
|
+
}
|
|
1510
1493
|
/**
|
|
1511
1494
|
* Swap the data of two nodes in the binary tree.
|
|
1512
1495
|
* @param {N} srcNode - The source node to swap.
|
|
@@ -81,11 +81,16 @@ class RedBlackTree extends bst_1.BST {
|
|
|
81
81
|
let x = this.root;
|
|
82
82
|
while (x !== this.NIL) {
|
|
83
83
|
y = x;
|
|
84
|
-
if (x
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
if (x) {
|
|
85
|
+
if (node.key < x.key) {
|
|
86
|
+
x = x.left;
|
|
87
|
+
}
|
|
88
|
+
else if (node.key > x.key) {
|
|
89
|
+
x = x === null || x === void 0 ? void 0 : x.right;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
node.parent = y;
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
import { HashMapLinkedNode, HashMapOptions } from '../../types';
|
|
9
9
|
export declare class HashMap<K = any, V = any> {
|
|
10
10
|
protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
|
|
11
|
-
protected _objMap: WeakMap<
|
|
11
|
+
protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
|
|
12
12
|
protected _head: HashMapLinkedNode<K, V | undefined>;
|
|
13
13
|
protected _tail: HashMapLinkedNode<K, V | undefined>;
|
|
14
14
|
protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
|
|
15
15
|
protected _hashFn: (key: K) => string;
|
|
16
|
-
protected _objHashFn: (key: K) =>
|
|
16
|
+
protected _objHashFn: (key: K) => object;
|
|
17
17
|
/**
|
|
18
18
|
* The constructor initializes a HashMapLinkedNode with an optional iterable of key-value pairs.
|
|
19
19
|
* @param options - The `options` parameter is an object that contains the `elements` property. The
|
|
@@ -99,8 +99,7 @@ class HashMap {
|
|
|
99
99
|
set(key, value) {
|
|
100
100
|
let node;
|
|
101
101
|
if ((0, utils_1.isWeakKey)(key)) {
|
|
102
|
-
|
|
103
|
-
const hash = key;
|
|
102
|
+
const hash = this._objHashFn(key);
|
|
104
103
|
node = this._objMap.get(hash);
|
|
105
104
|
if (node) {
|
|
106
105
|
// If the node already exists, update its value
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -24,4 +24,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
24
24
|
// export { PriorityQueue, MaxPriorityQueue, MinPriorityQueue } from 'data-structure-typed';
|
|
25
25
|
__exportStar(require("./data-structures/priority-queue"), exports);
|
|
26
26
|
__exportStar(require("./types/data-structures/priority-queue"), exports);
|
|
27
|
-
__exportStar(require("./types/
|
|
27
|
+
__exportStar(require("./types/common"), exports);
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./data-structures"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./common"), exports);
|
|
19
19
|
__exportStar(require("./utils"), exports);
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -20,5 +20,5 @@ export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Paramet
|
|
|
20
20
|
export declare const getMSB: (value: number) => number;
|
|
21
21
|
export declare const rangeCheck: (index: number, min: number, max: number, message?: string) => void;
|
|
22
22
|
export declare const throwRangeError: (message?: string) => void;
|
|
23
|
-
export declare const isWeakKey: (input: unknown) => input is
|
|
23
|
+
export declare const isWeakKey: (input: unknown) => input is object;
|
|
24
24
|
export declare const calcMinUnitsRequired: (totalQuantity: number, unitSize: number) => number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "priority-queue-typed",
|
|
3
|
-
"version": "1.46.
|
|
3
|
+
"version": "1.46.6",
|
|
4
4
|
"description": "Priority Queue, Min Priority Queue, Max Priority Queue. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -120,6 +120,6 @@
|
|
|
120
120
|
"typedoc": "^0.25.1"
|
|
121
121
|
},
|
|
122
122
|
"dependencies": {
|
|
123
|
-
"data-structure-typed": "^1.46.
|
|
123
|
+
"data-structure-typed": "^1.46.6"
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -1727,7 +1727,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
|
|
|
1727
1727
|
|
|
1728
1728
|
/**
|
|
1729
1729
|
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
1730
|
-
* @param {N | null | undefined}
|
|
1730
|
+
* @param {N | null | undefined} beginRoot - The `root` parameter is of type `BTNKey | N | null |
|
|
1731
1731
|
* undefined`. It represents the root node of a binary tree. The root node can have one of the
|
|
1732
1732
|
* following types:
|
|
1733
1733
|
*/
|
|
@@ -1736,61 +1736,48 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
|
|
|
1736
1736
|
if (!beginRoot) return;
|
|
1737
1737
|
|
|
1738
1738
|
const display = (root: N | null | undefined): void => {
|
|
1739
|
-
const [lines, , ,] = _displayAux(root);
|
|
1739
|
+
const [lines, , ,] = this._displayAux(root);
|
|
1740
1740
|
for (const line of lines) {
|
|
1741
1741
|
console.log(line);
|
|
1742
1742
|
}
|
|
1743
1743
|
};
|
|
1744
1744
|
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
return [[], 0, 0, 0];
|
|
1748
|
-
}
|
|
1745
|
+
display(beginRoot);
|
|
1746
|
+
}
|
|
1749
1747
|
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
const middle = Math.floor(width / 2);
|
|
1755
|
-
return [[line], width, height, middle];
|
|
1756
|
-
}
|
|
1748
|
+
protected _displayAux(node: N | null | undefined): [string[], number, number, number] {
|
|
1749
|
+
if (!node) {
|
|
1750
|
+
return [['─'], 1, 0, 0];
|
|
1751
|
+
}
|
|
1757
1752
|
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
const s = `${node.key}`;
|
|
1761
|
-
const u = s.length;
|
|
1762
|
-
const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s;
|
|
1763
|
-
const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u);
|
|
1764
|
-
const shifted_lines = lines.map(line => line + ' '.repeat(u));
|
|
1765
|
-
return [[first_line, second_line, ...shifted_lines], n + u, p + 2, n + Math.floor(u / 2)];
|
|
1766
|
-
}
|
|
1753
|
+
const line = node.key.toString();
|
|
1754
|
+
const width = line.length;
|
|
1767
1755
|
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
const x = s.length;
|
|
1772
|
-
const first_line = s + '_'.repeat(x) + ' '.repeat(n - x);
|
|
1773
|
-
const second_line = ' '.repeat(u + x) + '\\' + ' '.repeat(n - x - 1);
|
|
1774
|
-
const shifted_lines = lines.map(line => ' '.repeat(u) + line);
|
|
1775
|
-
return [[first_line, second_line, ...shifted_lines], n + x, p + 2, Math.floor(u / 2)];
|
|
1776
|
-
}
|
|
1756
|
+
if (!node.left && !node.right) {
|
|
1757
|
+
return [[line], width, 1, Math.floor(width / 2)];
|
|
1758
|
+
}
|
|
1777
1759
|
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
const s = `${node.key}`;
|
|
1781
|
-
const u = s.length;
|
|
1782
|
-
const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s + '_'.repeat(y) + ' '.repeat(m - y);
|
|
1783
|
-
const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u + y) + '\\' + ' '.repeat(m - y - 1);
|
|
1784
|
-
if (p < q) {
|
|
1785
|
-
left.push(...new Array(q - p).fill(' '.repeat(n)));
|
|
1786
|
-
} else if (q < p) {
|
|
1787
|
-
right.push(...new Array(p - q).fill(' '.repeat(m)));
|
|
1788
|
-
}
|
|
1789
|
-
const zipped_lines = left.map((a, i) => a + ' '.repeat(u) + right[i]);
|
|
1790
|
-
return [[first_line, second_line, ...zipped_lines], n + m + u, Math.max(p, q) + 2, n + Math.floor(u / 2)];
|
|
1791
|
-
};
|
|
1760
|
+
const [leftLines, leftWidth, leftHeight, leftMiddle] = node.left ? this._displayAux(node.left) : [[''], 0, 0, 0];
|
|
1761
|
+
const [rightLines, rightWidth, rightHeight, rightMiddle] = node.right ? this._displayAux(node.right) : [[''], 0, 0, 0];
|
|
1792
1762
|
|
|
1793
|
-
|
|
1763
|
+
const firstLine = ' '.repeat(Math.max(0, leftMiddle + 1))
|
|
1764
|
+
+ '_'.repeat(Math.max(0, leftWidth - leftMiddle - 1))
|
|
1765
|
+
+ line
|
|
1766
|
+
+ '_'.repeat(Math.max(0, rightMiddle))
|
|
1767
|
+
+ ' '.repeat(Math.max(0, rightWidth - rightMiddle));
|
|
1768
|
+
|
|
1769
|
+
const secondLine = (leftHeight > 0 ? ' '.repeat(leftMiddle) + '/' + ' '.repeat(leftWidth - leftMiddle - 1) : ' '.repeat(leftWidth))
|
|
1770
|
+
+ ' '.repeat(width)
|
|
1771
|
+
+ (rightHeight > 0 ? ' '.repeat(rightMiddle) + '\\' + ' '.repeat(rightWidth - rightMiddle - 1) : ' '.repeat(rightWidth));
|
|
1772
|
+
|
|
1773
|
+
const mergedLines = [firstLine, secondLine];
|
|
1774
|
+
for (let i = 0; i < Math.max(leftHeight, rightHeight); i++) {
|
|
1775
|
+
const leftLine = i < leftHeight ? leftLines[i] : ' '.repeat(leftWidth);
|
|
1776
|
+
const rightLine = i < rightHeight ? rightLines[i] : ' '.repeat(rightWidth);
|
|
1777
|
+
mergedLines.push(leftLine + ' '.repeat(width) + rightLine);
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
return [mergedLines, leftWidth + width + rightWidth, Math.max(leftHeight, rightHeight) + 2, leftWidth + Math.floor(width / 2)];
|
|
1794
1781
|
}
|
|
1795
1782
|
|
|
1796
1783
|
protected _defaultOneParamCallback = (node: N) => node.key;
|
|
@@ -103,11 +103,16 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
|
|
|
103
103
|
|
|
104
104
|
while (x !== this.NIL) {
|
|
105
105
|
y = x;
|
|
106
|
-
if (x
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
if (x) {
|
|
107
|
+
if (node.key < x.key) {
|
|
108
|
+
x = x.left;
|
|
109
|
+
} else if (node.key > x.key) {
|
|
110
|
+
x = x?.right;
|
|
111
|
+
} else {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
110
114
|
}
|
|
115
|
+
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
node.parent = y;
|
|
@@ -12,12 +12,12 @@ import { HashMapLinkedNode, HashMapOptions } from '../../types';
|
|
|
12
12
|
export class HashMap<K = any, V = any> {
|
|
13
13
|
|
|
14
14
|
protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>> = {};
|
|
15
|
-
protected _objMap = new WeakMap<
|
|
15
|
+
protected _objMap = new WeakMap<object, HashMapLinkedNode<K, V | undefined>>();
|
|
16
16
|
protected _head: HashMapLinkedNode<K, V | undefined>;
|
|
17
17
|
protected _tail: HashMapLinkedNode<K, V | undefined>;
|
|
18
18
|
protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
|
|
19
19
|
protected _hashFn: (key: K) => string;
|
|
20
|
-
protected _objHashFn: (key: K) =>
|
|
20
|
+
protected _objHashFn: (key: K) => object;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* The constructor initializes a HashMapLinkedNode with an optional iterable of key-value pairs.
|
|
@@ -27,7 +27,7 @@ export class HashMap<K = any, V = any> {
|
|
|
27
27
|
constructor(options: HashMapOptions<K, V> = {
|
|
28
28
|
elements: [],
|
|
29
29
|
hashFn: (key: K) => String(key),
|
|
30
|
-
objHashFn: (key: K) => (<
|
|
30
|
+
objHashFn: (key: K) => (<object>key)
|
|
31
31
|
}) {
|
|
32
32
|
this._sentinel = <HashMapLinkedNode<K, V>>{};
|
|
33
33
|
this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
|
|
@@ -114,8 +114,7 @@ export class HashMap<K = any, V = any> {
|
|
|
114
114
|
let node;
|
|
115
115
|
|
|
116
116
|
if (isWeakKey(key)) {
|
|
117
|
-
|
|
118
|
-
const hash = key;
|
|
117
|
+
const hash = this._objHashFn(key);
|
|
119
118
|
node = this._objMap.get(hash);
|
|
120
119
|
|
|
121
120
|
if (node) {
|
package/src/index.ts
CHANGED
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
// export { PriorityQueue, MaxPriorityQueue, MinPriorityQueue } from 'data-structure-typed';
|
|
9
9
|
export * from './data-structures/priority-queue';
|
|
10
10
|
export * from './types/data-structures/priority-queue';
|
|
11
|
-
export * from './types/
|
|
11
|
+
export * from './types/common';
|
package/src/types/index.ts
CHANGED
package/src/utils/utils.ts
CHANGED
|
@@ -93,7 +93,7 @@ export const throwRangeError = (message = 'The value is off-limits.'): void => {
|
|
|
93
93
|
throw new RangeError(message);
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
export const isWeakKey = (input: unknown): input is
|
|
96
|
+
export const isWeakKey = (input: unknown): input is object => {
|
|
97
97
|
const inputType = typeof input;
|
|
98
98
|
return (inputType === 'object' && input !== null) || inputType === 'function';
|
|
99
99
|
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|