data-structure-typed 1.39.2 → 1.39.4

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.
Files changed (98) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +11 -11
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.js +8 -6
  4. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +50 -117
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js +43 -51
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/bst.d.ts +23 -23
  10. package/dist/cjs/data-structures/binary-tree/bst.js +18 -18
  11. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +15 -15
  15. package/dist/cjs/data-structures/binary-tree/tree-multiset.js +9 -9
  16. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  17. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  18. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  19. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  20. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  21. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  22. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  23. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  24. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  25. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  26. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  27. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  28. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  29. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  30. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  31. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  32. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  33. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  34. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  35. package/dist/cjs/interfaces/binary-tree.d.ts +4 -4
  36. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  37. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +2 -2
  38. package/dist/cjs/types/helpers.d.ts +1 -1
  39. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +11 -11
  40. package/dist/mjs/data-structures/binary-tree/avl-tree.js +8 -6
  41. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +50 -117
  42. package/dist/mjs/data-structures/binary-tree/binary-tree.js +43 -51
  43. package/dist/mjs/data-structures/binary-tree/bst.d.ts +23 -23
  44. package/dist/mjs/data-structures/binary-tree/bst.js +18 -18
  45. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
  46. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +15 -15
  47. package/dist/mjs/data-structures/binary-tree/tree-multiset.js +9 -9
  48. package/dist/mjs/interfaces/binary-tree.d.ts +4 -4
  49. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  50. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +2 -2
  51. package/dist/mjs/types/helpers.d.ts +1 -1
  52. package/dist/umd/data-structure-typed.min.js +1 -1
  53. package/dist/umd/data-structure-typed.min.js.map +1 -1
  54. package/package.json +5 -5
  55. package/src/data-structures/binary-tree/avl-tree.ts +16 -14
  56. package/src/data-structures/binary-tree/binary-indexed-tree.ts +1 -1
  57. package/src/data-structures/binary-tree/binary-tree.ts +145 -84
  58. package/src/data-structures/binary-tree/bst.ts +37 -38
  59. package/src/data-structures/binary-tree/rb-tree.ts +7 -6
  60. package/src/data-structures/binary-tree/tree-multiset.ts +18 -17
  61. package/src/data-structures/graph/abstract-graph.ts +11 -10
  62. package/src/data-structures/graph/directed-graph.ts +2 -1
  63. package/src/data-structures/graph/undirected-graph.ts +5 -4
  64. package/src/data-structures/hash/hash-map.ts +1 -1
  65. package/src/data-structures/hash/tree-map.ts +1 -2
  66. package/src/data-structures/hash/tree-set.ts +1 -2
  67. package/src/data-structures/heap/heap.ts +2 -2
  68. package/src/data-structures/heap/max-heap.ts +1 -1
  69. package/src/data-structures/heap/min-heap.ts +1 -1
  70. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  71. package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
  72. package/src/data-structures/matrix/matrix.ts +1 -1
  73. package/src/data-structures/matrix/vector2d.ts +1 -2
  74. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  75. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  76. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  77. package/src/data-structures/queue/deque.ts +4 -5
  78. package/src/data-structures/queue/queue.ts +1 -1
  79. package/src/interfaces/binary-tree.ts +4 -4
  80. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  81. package/src/types/data-structures/binary-tree/bst.ts +2 -2
  82. package/src/types/data-structures/matrix/navigator.ts +1 -1
  83. package/src/types/helpers.ts +1 -1
  84. package/src/types/utils/utils.ts +1 -1
  85. package/src/types/utils/validate-type.ts +2 -2
  86. package/test/integration/bst.test.ts +1 -1
  87. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +1 -1
  88. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +14 -9
  89. package/test/unit/data-structures/binary-tree/bst.test.ts +6 -6
  90. package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
  91. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +2 -2
  92. package/test/unit/data-structures/hash/coordinate-map.test.ts +2 -2
  93. package/test/unit/data-structures/hash/coordinate-set.test.ts +2 -2
  94. package/test/unit/data-structures/heap/heap.test.ts +2 -2
  95. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +2 -6
  96. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +4 -7
  97. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +2 -2
  98. package/test/utils/big-o.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.39.2",
3
+ "version": "1.39.4",
4
4
  "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
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/mjs/index.js",
@@ -61,17 +61,17 @@
61
61
  "@typescript-eslint/eslint-plugin": "^6.7.4",
62
62
  "@typescript-eslint/parser": "^6.7.4",
63
63
  "auto-changelog": "^2.4.0",
64
- "avl-tree-typed": "^1.39.1",
64
+ "avl-tree-typed": "^1.39.3",
65
65
  "benchmark": "^2.1.4",
66
- "binary-tree-typed": "^1.39.1",
67
- "bst-typed": "^1.39.1",
66
+ "binary-tree-typed": "^1.39.3",
67
+ "bst-typed": "^1.39.3",
68
68
  "dependency-cruiser": "^14.1.0",
69
69
  "eslint": "^8.50.0",
70
70
  "eslint-config-prettier": "^9.0.0",
71
71
  "eslint-import-resolver-alias": "^1.1.2",
72
72
  "eslint-import-resolver-typescript": "^3.6.1",
73
73
  "eslint-plugin-import": "^2.28.1",
74
- "heap-typed": "^1.39.1",
74
+ "heap-typed": "^1.39.3",
75
75
  "istanbul-badges-readme": "^1.8.5",
76
76
  "jest": "^29.7.0",
77
77
  "prettier": "^3.0.3",
@@ -6,14 +6,14 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import {BST, BSTNode} from './bst';
9
- import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey} from '../../types';
10
- import {OneParamCallback} from '../../types';
9
+ import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BTNKey} from '../../types';
10
+ import {BTNCallback} from '../../types';
11
11
  import {IBinaryTree} from '../../interfaces';
12
12
 
13
13
  export class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
14
14
  height: number;
15
15
 
16
- constructor(key: BinaryTreeNodeKey, val?: V) {
16
+ constructor(key: BTNKey, val?: V) {
17
17
  super(key, val);
18
18
  this.height = 0;
19
19
  }
@@ -21,7 +21,8 @@ export class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNeste
21
21
 
22
22
  export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>>
23
23
  extends BST<V, N>
24
- implements IBinaryTree<V, N> {
24
+ implements IBinaryTree<V, N>
25
+ {
25
26
  /**
26
27
  * This is a constructor function for an AVL tree data structure in TypeScript.
27
28
  * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
@@ -34,27 +35,27 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
34
35
 
35
36
  /**
36
37
  * The function creates a new AVL tree node with the specified key and value.
37
- * @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
38
+ * @param {BTNKey} key - The key parameter is the key value that will be associated with
38
39
  * the new node. It is used to determine the position of the node in the binary search tree.
39
40
  * @param [val] - The parameter `val` is an optional value that can be assigned to the node. It is of
40
41
  * type `V`, which means it can be any value that is assignable to the `val` property of the
41
42
  * node type `N`.
42
43
  * @returns a new AVLTreeNode object with the specified key and value.
43
44
  */
44
- override createNode(key: BinaryTreeNodeKey, val?: V): N {
45
+ override createNode(key: BTNKey, val?: V): N {
45
46
  return new AVLTreeNode<V, N>(key, val) as N;
46
47
  }
47
48
 
48
49
  /**
49
50
  * The function overrides the add method of a binary tree node and balances the tree after inserting
50
51
  * a new node.
51
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
52
- * `BinaryTreeNodeKey` or a `N` (which represents a node in the binary tree) or `null`.
52
+ * @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
53
+ * `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
53
54
  * @param [val] - The `val` parameter is the value that you want to assign to the new node that you
54
55
  * are adding to the binary search tree.
55
56
  * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
56
57
  */
57
- override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: V): N | null | undefined {
58
+ override add(keyOrNode: BTNKey | N | null, val?: V): N | null | undefined {
58
59
  // TODO support node as a param
59
60
  const inserted = super.add(keyOrNode, val);
60
61
  if (inserted) this._balancePath(inserted);
@@ -65,18 +66,19 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
65
66
  * The function overrides the delete method of a binary tree and balances the tree after deleting a
66
67
  * node if necessary.
67
68
  * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
68
- * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
69
+ * `BTNKey` or a generic type `N`. It represents the property of the node that we are
69
70
  * searching for. It can be a specific key value or any other property of the node.
70
71
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
71
72
  * value. This value is compared with the `identifier` parameter to determine if the node should be
72
73
  * included in the result. The `callback` parameter has a default value of
73
- * `this._defaultCallbackByKey`
74
+ * `((node: N) => node.key)`
74
75
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
75
76
  */
76
- override delete<C extends OneParamCallback<N>>(
77
+ override delete<C extends BTNCallback<N>>(
77
78
  identifier: ReturnType<C>,
78
- callback: C = this._defaultCallbackByKey as C
79
+ callback: C = ((node: N) => node.key) as C
79
80
  ): BinaryTreeDeletedResult<N>[] {
81
+ if ((identifier as any) instanceof AVLTreeNode) callback = (node => node) as C;
80
82
  const deletedResults = super.delete(identifier, callback);
81
83
  for (const {needBalanced} of deletedResults) {
82
84
  if (needBalanced) {
@@ -160,7 +162,7 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
160
162
  // Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
161
163
  switch (
162
164
  this._balanceFactor(A) // second O(1)
163
- ) {
165
+ ) {
164
166
  case -2:
165
167
  if (A && A.left) {
166
168
  if (this._balanceFactor(A.left) <= 0) {
@@ -17,7 +17,7 @@ export class BinaryIndexedTree {
17
17
  * @param - - `frequency`: The default frequency value. It is optional and has a default
18
18
  * value of 0.
19
19
  */
20
- constructor({frequency = 0, max}: { frequency?: number; max: number }) {
20
+ constructor({frequency = 0, max}: {frequency?: number; max: number}) {
21
21
  this._freq = frequency;
22
22
  this._max = max;
23
23
  this._freqMap = {0: 0};