data-structure-typed 1.36.8 → 1.36.9

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 (74) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/README.md +8 -0
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +5 -5
  4. package/dist/data-structures/binary-tree/avl-tree.js +6 -6
  5. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +18 -85
  7. package/dist/data-structures/binary-tree/binary-tree.js +76 -128
  8. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  9. package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -16
  10. package/dist/data-structures/binary-tree/tree-multiset.js +10 -20
  11. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  12. package/dist/data-structures/hash/hash-map.d.ts +1 -1
  13. package/dist/data-structures/hash/hash-map.js +1 -1
  14. package/dist/data-structures/hash/hash-table.d.ts +3 -3
  15. package/dist/data-structures/hash/hash-table.js +3 -3
  16. package/dist/data-structures/heap/heap.js.map +1 -1
  17. package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -3
  18. package/dist/data-structures/linked-list/skip-linked-list.js +3 -3
  19. package/dist/data-structures/queue/deque.d.ts +2 -2
  20. package/dist/data-structures/queue/deque.js +2 -2
  21. package/dist/data-structures/queue/queue.js +1 -1
  22. package/dist/data-structures/trie/trie.d.ts +2 -2
  23. package/dist/data-structures/trie/trie.js +2 -2
  24. package/dist/interfaces/binary-tree.d.ts +1 -1
  25. package/lib/data-structures/binary-tree/avl-tree.d.ts +5 -5
  26. package/lib/data-structures/binary-tree/avl-tree.js +6 -6
  27. package/lib/data-structures/binary-tree/binary-tree.d.ts +18 -85
  28. package/lib/data-structures/binary-tree/binary-tree.js +76 -128
  29. package/lib/data-structures/binary-tree/tree-multiset.d.ts +9 -16
  30. package/lib/data-structures/binary-tree/tree-multiset.js +10 -20
  31. package/lib/data-structures/hash/hash-map.d.ts +1 -1
  32. package/lib/data-structures/hash/hash-map.js +1 -1
  33. package/lib/data-structures/hash/hash-table.d.ts +3 -3
  34. package/lib/data-structures/hash/hash-table.js +3 -3
  35. package/lib/data-structures/linked-list/skip-linked-list.d.ts +3 -3
  36. package/lib/data-structures/linked-list/skip-linked-list.js +3 -3
  37. package/lib/data-structures/queue/deque.d.ts +2 -2
  38. package/lib/data-structures/queue/deque.js +2 -2
  39. package/lib/data-structures/queue/queue.js +1 -1
  40. package/lib/data-structures/trie/trie.d.ts +2 -2
  41. package/lib/data-structures/trie/trie.js +2 -2
  42. package/lib/interfaces/binary-tree.d.ts +1 -1
  43. package/package.json +6 -6
  44. package/src/data-structures/binary-tree/avl-tree.ts +6 -6
  45. package/src/data-structures/binary-tree/binary-tree.ts +79 -214
  46. package/src/data-structures/binary-tree/rb-tree.ts +3 -3
  47. package/src/data-structures/binary-tree/tree-multiset.ts +10 -21
  48. package/src/data-structures/hash/hash-map.ts +1 -1
  49. package/src/data-structures/hash/hash-table.ts +3 -3
  50. package/src/data-structures/heap/heap.ts +5 -2
  51. package/src/data-structures/linked-list/skip-linked-list.ts +3 -3
  52. package/src/data-structures/queue/deque.ts +2 -2
  53. package/src/data-structures/queue/queue.ts +1 -1
  54. package/src/data-structures/trie/trie.ts +2 -2
  55. package/src/interfaces/binary-tree.ts +1 -1
  56. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -14
  57. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
  58. package/test/unit/data-structures/binary-tree/bst.test.ts +28 -28
  59. package/test/unit/data-structures/binary-tree/overall.test.ts +3 -3
  60. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +1 -1
  61. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +28 -28
  62. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  63. package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
  64. package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
  65. package/test/unit/data-structures/hash/hash-table.test.ts +5 -5
  66. package/test/unit/data-structures/heap/heap.test.ts +15 -12
  67. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +7 -7
  68. package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
  69. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
  70. package/test/unit/data-structures/queue/deque.test.ts +3 -3
  71. package/test/unit/data-structures/trie/trie.test.ts +5 -5
  72. package/test/utils/big-o.ts +61 -55
  73. package/umd/bundle.min.js +1 -1
  74. package/umd/bundle.min.js.map +1 -1
@@ -47,12 +47,12 @@ export class TreeMultiset extends AVLTree {
47
47
  }
48
48
  /**
49
49
  * The function swaps the location of two nodes in a tree data structure.
50
- * @param {N} srcNode - The source node that we want to swap with the destination node.
50
+ * @param {N} srcNode - The source node that we want to _swap with the destination node.
51
51
  * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
52
52
  * be swapped with.
53
53
  * @returns the `destNode` after swapping its values with the `srcNode`.
54
54
  */
55
- swapLocation(srcNode, destNode) {
55
+ _swap(srcNode, destNode) {
56
56
  const { key, val, count, height } = destNode;
57
57
  const tempNode = this.createNode(key, val, count);
58
58
  if (tempNode) {
@@ -257,15 +257,15 @@ export class TreeMultiset extends AVLTree {
257
257
  }
258
258
  }
259
259
  /**
260
- * The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
260
+ * The `delete` function removes a node from a binary search tree and returns the deleted node along with the parent
261
261
  * node that needs to be balanced.
262
262
  * @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:
263
263
  * @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
264
264
  * whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
265
265
  * not be taken into account when removing it. If `ignoreCount` is set to `false
266
- * @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
266
+ * @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
267
267
  */
268
- remove(nodeOrKey, ignoreCount = false) {
268
+ delete(nodeOrKey, ignoreCount = false) {
269
269
  const bstDeletedResult = [];
270
270
  if (!this.root)
271
271
  return bstDeletedResult;
@@ -299,7 +299,7 @@ export class TreeMultiset extends AVLTree {
299
299
  const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
300
300
  if (leftSubTreeRightMost) {
301
301
  const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
302
- orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
302
+ orgCurrent = this._swap(curr, leftSubTreeRightMost);
303
303
  if (parentOfLeftSubTreeMax) {
304
304
  if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
305
305
  parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
@@ -475,7 +475,7 @@ export class TreeMultiset extends AVLTree {
475
475
  * @returns The BFSCount() function returns an array of numbers, specifically the count property of each node in the
476
476
  * bfs traversal.
477
477
  */
478
- BFSCount() {
478
+ bfsCount() {
479
479
  const nodes = super.bfs('node');
480
480
  return nodes.map(node => node.count);
481
481
  }
@@ -507,22 +507,12 @@ export class TreeMultiset extends AVLTree {
507
507
  * the specified traversal pattern.
508
508
  * @param {'in' | 'pre' | 'post'} [pattern] - The pattern parameter is a string that specifies the traversal order for
509
509
  * the Depth-First Search (dfs) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
510
+ * @param loopType - The loopType parameter is a string that specifies the type of loop to use when traversing the
510
511
  * @returns The dfsCountIterative function returns an array of numbers, which represents the count property of each node
511
512
  * in the dfs traversal.
512
513
  */
513
- dfsCountIterative(pattern = 'in') {
514
- const nodes = super.dfsIterative(pattern, 'node');
515
- return nodes.map(node => node.count);
516
- }
517
- /**
518
- * The dfsCount function returns an array of counts for each node in a depth-first search traversal.
519
- * @param {DFSOrderPattern} [pattern] - The pattern parameter is an optional parameter that specifies the order in which
520
- * the Depth-First Search (dfs) algorithm should traverse the nodes. It can have one of the following values:
521
- * @returns The dfsCount function returns an array of numbers, specifically the count property of each node in the dfs
522
- * traversal.
523
- */
524
- dfsCount(pattern = 'in') {
525
- const nodes = super.dfs(pattern, 'node');
514
+ dfsCount(pattern = 'in', loopType = LoopType.ITERATIVE) {
515
+ const nodes = super.dfs(pattern, 'node', loopType);
526
516
  return nodes.map(node => node.count);
527
517
  }
528
518
  /**
@@ -48,7 +48,7 @@ export declare class HashMap<K, V> {
48
48
  private resizeTable;
49
49
  set(key: K, value: V): void;
50
50
  get(key: K): V | undefined;
51
- remove(key: K): void;
51
+ delete(key: K): void;
52
52
  entries(): IterableIterator<[K, V]>;
53
53
  [Symbol.iterator](): IterableIterator<[K, V]>;
54
54
  clear(): void;
@@ -127,7 +127,7 @@ export class HashMap {
127
127
  }
128
128
  return undefined;
129
129
  }
130
- remove(key) {
130
+ delete(key) {
131
131
  const index = this._hash(key);
132
132
  if (!this.table[index]) {
133
133
  return;
@@ -90,13 +90,13 @@ export declare class HashTable<K, V> {
90
90
  */
91
91
  get(key: K): V | undefined;
92
92
  /**
93
- * The remove function removes a key-value pair from a hash table.
93
+ * The delete function removes a key-value pair from a hash table.
94
94
  * @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
95
95
  * table.
96
- * @returns Nothing is being returned. The `remove` method has a return type of `void`, which means it does not return
96
+ * @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
97
97
  * any value.
98
98
  */
99
- remove(key: K): void;
99
+ delete(key: K): void;
100
100
  /**
101
101
  * The `expand` function increases the capacity of a hash table by creating a new array of buckets with double the
102
102
  * capacity and rehashing all the existing key-value pairs into the new buckets.
@@ -178,13 +178,13 @@ export class HashTable {
178
178
  return undefined; // Key not found
179
179
  }
180
180
  /**
181
- * The remove function removes a key-value pair from a hash table.
181
+ * The delete function removes a key-value pair from a hash table.
182
182
  * @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
183
183
  * table.
184
- * @returns Nothing is being returned. The `remove` method has a return type of `void`, which means it does not return
184
+ * @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
185
185
  * any value.
186
186
  */
187
- remove(key) {
187
+ delete(key) {
188
188
  const index = this._hash(key);
189
189
  let currentNode = this._buckets[index];
190
190
  let prevNode = null;
@@ -52,10 +52,10 @@ export declare class SkipList<K, V> {
52
52
  */
53
53
  get(key: K): V | undefined;
54
54
  /**
55
- * The `remove` function removes a node with a specific key from a Skip List data structure.
55
+ * The `delete` function removes a node with a specific key from a Skip List data structure.
56
56
  * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
57
- * @returns The `remove` method returns a boolean value. It returns `true` if the key was successfully removed from the
57
+ * @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
58
58
  * skip list, and `false` if the key was not found in the skip list.
59
59
  */
60
- remove(key: K): boolean;
60
+ delete(key: K): boolean;
61
61
  }
@@ -105,12 +105,12 @@ export class SkipList {
105
105
  return undefined;
106
106
  }
107
107
  /**
108
- * The `remove` function removes a node with a specific key from a Skip List data structure.
108
+ * The `delete` function removes a node with a specific key from a Skip List data structure.
109
109
  * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
110
- * @returns The `remove` method returns a boolean value. It returns `true` if the key was successfully removed from the
110
+ * @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
111
111
  * skip list, and `false` if the key was not found in the skip list.
112
112
  */
113
- remove(key) {
113
+ delete(key) {
114
114
  const update = new Array(this.maxLevel).fill(this.head);
115
115
  let current = this.head;
116
116
  for (let i = this.level - 1; i >= 0; i--) {
@@ -150,12 +150,12 @@ export declare class ArrayDeque<E> {
150
150
  */
151
151
  insert(index: number, value: E): E[];
152
152
  /**
153
- * The remove function removes an element from an array at a specified index.
153
+ * The delete function removes an element from an array at a specified index.
154
154
  * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
155
155
  * is a number that represents the index of the element to be removed.
156
156
  * @returns The method is returning an array containing the removed element.
157
157
  */
158
- remove(index: number): E[];
158
+ delete(index: number): E[];
159
159
  /**
160
160
  * The function checks if an array called "_nodes" is empty.
161
161
  * @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
@@ -251,12 +251,12 @@ export class ArrayDeque {
251
251
  return this._nodes.splice(index, 0, value);
252
252
  }
253
253
  /**
254
- * The remove function removes an element from an array at a specified index.
254
+ * The delete function removes an element from an array at a specified index.
255
255
  * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
256
256
  * is a number that represents the index of the element to be removed.
257
257
  * @returns The method is returning an array containing the removed element.
258
258
  */
259
- remove(index) {
259
+ delete(index) {
260
260
  return this._nodes.splice(index, 1);
261
261
  }
262
262
  /**
@@ -90,7 +90,7 @@ export class Queue {
90
90
  this.offset += 1;
91
91
  if (this.offset * 2 < this.nodes.length)
92
92
  return first;
93
- // only remove dequeued elements when reaching half size
93
+ // only delete dequeued elements when reaching half size
94
94
  // to decrease latency of shifting elements.
95
95
  this.nodes = this.nodes.slice(this.offset);
96
96
  this.offset = 0;
@@ -45,10 +45,10 @@ export declare class Trie {
45
45
  private _caseProcess;
46
46
  /**
47
47
  * Remove a word from the Trie structure.
48
- * @param{string} word - The word to remove.
48
+ * @param{string} word - The word to delete.
49
49
  * @returns {boolean} True if the word was successfully removed.
50
50
  */
51
- remove(word: string): boolean;
51
+ delete(word: string): boolean;
52
52
  getHeight(): number;
53
53
  /**
54
54
  * Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
@@ -96,10 +96,10 @@ export class Trie {
96
96
  }
97
97
  /**
98
98
  * Remove a word from the Trie structure.
99
- * @param{string} word - The word to remove.
99
+ * @param{string} word - The word to delete.
100
100
  * @returns {boolean} True if the word was successfully removed.
101
101
  */
102
- remove(word) {
102
+ delete(word) {
103
103
  word = this._caseProcess(word);
104
104
  let isDeleted = false;
105
105
  const dfs = (cur, i) => {
@@ -3,5 +3,5 @@ import { BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../types';
3
3
  export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> {
4
4
  createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
5
5
  add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
6
- remove(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
6
+ delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.36.8",
3
+ "version": "1.36.9",
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/index.js",
6
6
  "module": "lib/index.js",
@@ -34,7 +34,7 @@
34
34
  "changelog": "auto-changelog",
35
35
  "coverage:badge": "istanbul-badges-readme",
36
36
  "ci": "env && npm run lint && npm run build && npm run update:individuals && npm run test && git fetch --tags && npm run changelog",
37
- "publish:all": "npm run ci && npm publish && sh /scripts/publish_all_subs.sh && sh /scripts/publish_docs.sh"
37
+ "publish:all": "npm run ci && npm publish && sh scripts/publish_all_subs.sh && sh scripts/publish_docs.sh"
38
38
  },
39
39
  "repository": {
40
40
  "type": "git",
@@ -56,17 +56,17 @@
56
56
  "@typescript-eslint/eslint-plugin": "^6.7.4",
57
57
  "@typescript-eslint/parser": "^6.7.4",
58
58
  "auto-changelog": "^2.4.0",
59
- "avl-tree-typed": "^1.36.6",
59
+ "avl-tree-typed": "^1.36.8",
60
60
  "benchmark": "^2.1.4",
61
- "binary-tree-typed": "^1.36.6",
62
- "bst-typed": "^1.36.6",
61
+ "binary-tree-typed": "^1.36.8",
62
+ "bst-typed": "^1.36.8",
63
63
  "dependency-cruiser": "^14.1.0",
64
64
  "eslint": "^8.50.0",
65
65
  "eslint-config-prettier": "^9.0.0",
66
66
  "eslint-import-resolver-alias": "^1.1.2",
67
67
  "eslint-import-resolver-typescript": "^3.6.1",
68
68
  "eslint-plugin-import": "^2.28.1",
69
- "heap-typed": "^1.36.6",
69
+ "heap-typed": "^1.36.8",
70
70
  "istanbul-badges-readme": "^1.8.5",
71
71
  "jest": "^29.7.0",
72
72
  "prettier": "^3.0.3",
@@ -33,13 +33,13 @@ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends B
33
33
  }
34
34
 
35
35
  /**
36
- * The `swapLocation` function swaps the location of two nodes in a binary tree.
37
- * @param {N} srcNode - The source node that you want to swap with the destination node.
36
+ * The `_swap` function swaps the location of two nodes in a binary tree.
37
+ * @param {N} srcNode - The source node that you want to _swap with the destination node.
38
38
  * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
39
39
  * be swapped to.
40
40
  * @returns The `destNode` is being returned.
41
41
  */
42
- override swapLocation(srcNode: N, destNode: N): N {
42
+ protected override _swap(srcNode: N, destNode: N): N {
43
43
  const {key, val, height} = destNode;
44
44
  const tempNode = this.createNode(key, val);
45
45
 
@@ -85,14 +85,14 @@ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends B
85
85
  }
86
86
 
87
87
  /**
88
- * The function overrides the remove method of a binary tree and performs additional operations to balance the tree after
88
+ * The function overrides the delete method of a binary tree and performs additional operations to balance the tree after
89
89
  * deletion.
90
90
  * @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be
91
91
  * removed.
92
92
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
93
93
  */
94
- override remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[] {
95
- const deletedResults = super.remove(key);
94
+ override delete(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[] {
95
+ const deletedResults = super.delete(key);
96
96
  for (const {needBalanced} of deletedResults) {
97
97
  if (needBalanced) {
98
98
  this._balancePath(needBalanced);