min-heap-typed 1.50.1 → 1.50.2

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 (67) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +114 -9
  2. package/dist/data-structures/base/iterable-base.js +143 -7
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +43 -46
  4. package/dist/data-structures/binary-tree/avl-tree.js +68 -71
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
  6. package/dist/data-structures/binary-tree/binary-tree.js +484 -376
  7. package/dist/data-structures/binary-tree/bst.d.ts +54 -74
  8. package/dist/data-structures/binary-tree/bst.js +30 -71
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +78 -60
  10. package/dist/data-structures/binary-tree/rb-tree.js +84 -89
  11. package/dist/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  12. package/dist/data-structures/binary-tree/tree-multimap.js +64 -85
  13. package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
  14. package/dist/data-structures/graph/abstract-graph.js +3 -0
  15. package/dist/data-structures/graph/directed-graph.d.ts +14 -0
  16. package/dist/data-structures/graph/directed-graph.js +26 -0
  17. package/dist/data-structures/graph/map-graph.d.ts +8 -0
  18. package/dist/data-structures/graph/map-graph.js +14 -0
  19. package/dist/data-structures/graph/undirected-graph.d.ts +16 -0
  20. package/dist/data-structures/graph/undirected-graph.js +25 -0
  21. package/dist/data-structures/hash/hash-map.d.ts +121 -15
  22. package/dist/data-structures/hash/hash-map.js +160 -25
  23. package/dist/data-structures/heap/heap.d.ts +66 -6
  24. package/dist/data-structures/heap/heap.js +66 -6
  25. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  26. package/dist/data-structures/linked-list/doubly-linked-list.js +70 -64
  27. package/dist/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  28. package/dist/data-structures/linked-list/singly-linked-list.js +130 -112
  29. package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  30. package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
  31. package/dist/data-structures/matrix/matrix.d.ts +35 -4
  32. package/dist/data-structures/matrix/matrix.js +50 -11
  33. package/dist/data-structures/queue/deque.d.ts +49 -19
  34. package/dist/data-structures/queue/deque.js +101 -47
  35. package/dist/data-structures/queue/queue.d.ts +39 -5
  36. package/dist/data-structures/queue/queue.js +47 -5
  37. package/dist/data-structures/stack/stack.d.ts +16 -0
  38. package/dist/data-structures/stack/stack.js +22 -0
  39. package/dist/data-structures/trie/trie.d.ts +38 -1
  40. package/dist/data-structures/trie/trie.js +41 -0
  41. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  42. package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
  43. package/dist/types/utils/utils.d.ts +1 -0
  44. package/package.json +2 -2
  45. package/src/data-structures/base/iterable-base.ts +172 -19
  46. package/src/data-structures/binary-tree/avl-tree.ts +97 -97
  47. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  48. package/src/data-structures/binary-tree/bst.ts +89 -131
  49. package/src/data-structures/binary-tree/rb-tree.ts +127 -155
  50. package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
  51. package/src/data-structures/graph/abstract-graph.ts +4 -0
  52. package/src/data-structures/graph/directed-graph.ts +30 -0
  53. package/src/data-structures/graph/map-graph.ts +15 -0
  54. package/src/data-structures/graph/undirected-graph.ts +28 -0
  55. package/src/data-structures/hash/hash-map.ts +175 -34
  56. package/src/data-structures/heap/heap.ts +66 -6
  57. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
  58. package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
  59. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  60. package/src/data-structures/matrix/matrix.ts +52 -12
  61. package/src/data-structures/queue/deque.ts +108 -49
  62. package/src/data-structures/queue/queue.ts +51 -5
  63. package/src/data-structures/stack/stack.ts +24 -0
  64. package/src/data-structures/trie/trie.ts +45 -1
  65. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  66. package/src/types/data-structures/hash/hash-map.ts +4 -3
  67. package/src/types/utils/utils.ts +2 -0
@@ -32,12 +32,20 @@ export class Queue<E = any> extends IterableElementBase<E> {
32
32
 
33
33
  protected _elements: E[] = [];
34
34
 
35
+ /**
36
+ * The elements function returns the elements of this set.
37
+ * @return An array of the elements in the stack
38
+ */
35
39
  get elements(): E[] {
36
40
  return this._elements;
37
41
  }
38
42
 
39
43
  protected _offset: number = 0;
40
44
 
45
+ /**
46
+ * The offset function returns the offset of the current page.
47
+ * @return The value of the private variable _offset
48
+ */
41
49
  get offset(): number {
42
50
  return this._offset;
43
51
  }
@@ -142,6 +150,26 @@ export class Queue<E = any> extends IterableElementBase<E> {
142
150
  return first;
143
151
  }
144
152
 
153
+ /**
154
+ * The delete function removes an element from the list.
155
+ * @param element: E Specify the element to be deleted
156
+ * @return A boolean value indicating whether the element was successfully deleted or not
157
+ */
158
+ delete(element: E): boolean {
159
+ const index = this.elements.indexOf(element);
160
+ return this.deleteAt(index);
161
+ }
162
+
163
+ /**
164
+ * The deleteAt function deletes the element at a given index.
165
+ * @param index: number Determine the index of the element to be deleted
166
+ * @return A boolean value
167
+ */
168
+ deleteAt(index: number): boolean {
169
+ const spliced = this.elements.splice(index, 1);
170
+ return spliced.length === 1;
171
+ }
172
+
145
173
  /**
146
174
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
147
175
  * Space Complexity: O(1) - no additional space is used.
@@ -219,7 +247,7 @@ export class Queue<E = any> extends IterableElementBase<E> {
219
247
  *
220
248
  * @param index
221
249
  */
222
- getAt(index: number): E | undefined {
250
+ at(index: number): E | undefined {
223
251
  return this.elements[index];
224
252
  }
225
253
 
@@ -264,13 +292,14 @@ export class Queue<E = any> extends IterableElementBase<E> {
264
292
  }
265
293
 
266
294
  /**
267
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
268
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
295
+ * Time Complexity: O(n)
296
+ * Space Complexity: O(n)
297
+ * where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
269
298
  */
270
299
 
271
300
  /**
272
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
273
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
301
+ * Time Complexity: O(n)
302
+ * Space Complexity: O(n)
274
303
  *
275
304
  * The `clone()` function returns a new Queue object with the same elements as the original Queue.
276
305
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
@@ -390,4 +419,21 @@ export class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
390
419
  peek(): E | undefined {
391
420
  return this.first;
392
421
  }
422
+
423
+ /**
424
+ * Time Complexity: O(n)
425
+ * Space Complexity: O(n)
426
+ */
427
+
428
+ /**
429
+ * Time Complexity: O(n)
430
+ * Space Complexity: O(n)
431
+ * The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
432
+ * the current instance.
433
+ * @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
434
+ * values as the original `LinkedListQueue`.
435
+ */
436
+ clone(): LinkedListQueue<E> {
437
+ return new LinkedListQueue<E>(this.values());
438
+ }
393
439
  }
@@ -32,6 +32,10 @@ export class Stack<E = any> extends IterableElementBase<E> {
32
32
 
33
33
  protected _elements: E[] = [];
34
34
 
35
+ /**
36
+ * The elements function returns the elements of this set.
37
+ * @return An array of elements
38
+ */
35
39
  get elements(): E[] {
36
40
  return this._elements;
37
41
  }
@@ -125,6 +129,26 @@ export class Stack<E = any> extends IterableElementBase<E> {
125
129
  return this.elements.pop();
126
130
  }
127
131
 
132
+ /**
133
+ * The delete function removes an element from the stack.
134
+ * @param element: E Specify the element to be deleted
135
+ * @return A boolean value indicating whether the element was successfully deleted or not
136
+ */
137
+ delete(element: E): boolean {
138
+ const index = this.elements.indexOf(element);
139
+ return this.deleteAt(index);
140
+ }
141
+
142
+ /**
143
+ * The deleteAt function deletes the element at a given index.
144
+ * @param index: number Determine the index of the element to be deleted
145
+ * @return A boolean value
146
+ */
147
+ deleteAt(index: number): boolean {
148
+ const spliced = this.elements.splice(index, 1);
149
+ return spliced.length === 1;
150
+ }
151
+
128
152
  /**
129
153
  * Time Complexity: O(n)
130
154
  * Space Complexity: O(n)
@@ -37,7 +37,13 @@ export class TrieNode {
37
37
  * 10. IP Routing: Used in certain types of IP routing algorithms.
38
38
  * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
39
39
  */
40
- export class Trie extends IterableElementBase<string> {
40
+ export class Trie extends IterableElementBase<string, Trie> {
41
+ /**
42
+ * The constructor function for the Trie class.
43
+ * @param words: Iterable string Initialize the trie with a set of words
44
+ * @param options?: TrieOptions Allow the user to pass in options for the trie
45
+ * @return This
46
+ */
41
47
  constructor(words: Iterable<string> = [], options?: TrieOptions) {
42
48
  super();
43
49
  if (options) {
@@ -51,18 +57,31 @@ export class Trie extends IterableElementBase<string> {
51
57
 
52
58
  protected _size: number = 0;
53
59
 
60
+ /**
61
+ * The size function returns the size of the stack.
62
+ * @return The number of elements in the list
63
+ */
54
64
  get size(): number {
55
65
  return this._size;
56
66
  }
57
67
 
58
68
  protected _caseSensitive: boolean = true;
59
69
 
70
+ /**
71
+ * The caseSensitive function is a getter that returns the value of the private _caseSensitive property.
72
+ *
73
+ * @return The value of the _casesensitive private variable
74
+ */
60
75
  get caseSensitive(): boolean {
61
76
  return this._caseSensitive;
62
77
  }
63
78
 
64
79
  protected _root: TrieNode = new TrieNode('');
65
80
 
81
+ /**
82
+ * The root function returns the root node of the tree.
83
+ * @return The root node
84
+ */
66
85
  get root() {
67
86
  return this._root;
68
87
  }
@@ -124,6 +143,14 @@ export class Trie extends IterableElementBase<string> {
124
143
  return cur.isEnd;
125
144
  }
126
145
 
146
+ /**
147
+ * The isEmpty function checks if the size of the queue is 0.
148
+ * @return True if the size of the queue is 0
149
+ */
150
+ isEmpty(): boolean {
151
+ return this.size === 0;
152
+ }
153
+
127
154
  /**
128
155
  * Time Complexity: O(M), where M is the length of the word being deleted.
129
156
  * Space Complexity: O(M) - Due to the recursive DFS approach.
@@ -351,6 +378,23 @@ export class Trie extends IterableElementBase<string> {
351
378
  return words;
352
379
  }
353
380
 
381
+ /**
382
+ * Time Complexity: O(n)
383
+ * Space Complexity: O(n)
384
+ */
385
+
386
+ /**
387
+ * Time Complexity: O(n)
388
+ * Space Complexity: O(n)
389
+ *
390
+ * The `clone` function returns a new instance of the Trie class with the same values and case
391
+ * sensitivity as the original Trie.
392
+ * @returns A new instance of the Trie class is being returned.
393
+ */
394
+ clone(): Trie {
395
+ return new Trie(this.values(), { caseSensitive: this.caseSensitive });
396
+ }
397
+
354
398
  /**
355
399
  * Time Complexity: O(n)
356
400
  * Space Complexity: O(n)
@@ -3,7 +3,7 @@ import { IterationType } from "../../common";
3
3
 
4
4
  export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
5
5
 
6
- export type BinaryTreeNested<K, V, N extends BinaryTreeNode<K, V, N>> = BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
6
+ export type BinaryTreeNested<K, V, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
7
 
8
8
  export type BinaryTreeOptions<K> = {
9
9
  iterationType?: IterationType,
@@ -5,14 +5,15 @@ export type HashMapLinkedNode<K, V> = {
5
5
  prev: HashMapLinkedNode<K, V>;
6
6
  };
7
7
 
8
- export type LinkedHashMapOptions<K> = {
8
+ export type LinkedHashMapOptions<K, V, R> = {
9
9
  hashFn?: (key: K) => string;
10
10
  objHashFn?: (key: K) => object;
11
+ toEntryFn?: (rawElement: R) => [K, V];
11
12
  };
12
13
 
13
- export type HashMapOptions<K, V, T> = {
14
+ export type HashMapOptions<K, V, R> = {
14
15
  hashFn?: (key: K) => string;
15
- toEntryFn?: (rawElement: T) => [K, V];
16
+ toEntryFn?: (rawElement: R) => [K, V];
16
17
  };
17
18
 
18
19
  export type HashMapStoreItem<K, V> = { key: K; value: V };
@@ -4,3 +4,5 @@ export type TrlFn = (...args: any[]) => any;
4
4
  export type TrlAsyncFn = (...args: any[]) => any;
5
5
 
6
6
  export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
7
+
8
+ export type Any = string | number | boolean | object | null | undefined | symbol;