undirected-graph-typed 1.49.0 → 1.49.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 (88) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +11 -0
  2. package/dist/data-structures/base/iterable-base.js +21 -0
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +10 -12
  4. package/dist/data-structures/binary-tree/avl-tree.js +3 -4
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +58 -58
  6. package/dist/data-structures/binary-tree/binary-tree.js +6 -6
  7. package/dist/data-structures/binary-tree/bst.d.ts +15 -15
  8. package/dist/data-structures/binary-tree/bst.js +3 -3
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +11 -11
  10. package/dist/data-structures/binary-tree/rb-tree.js +5 -6
  11. package/dist/data-structures/binary-tree/tree-multimap.d.ts +14 -14
  12. package/dist/data-structures/binary-tree/tree-multimap.js +3 -3
  13. package/dist/data-structures/graph/abstract-graph.d.ts +9 -3
  14. package/dist/data-structures/graph/abstract-graph.js +27 -31
  15. package/dist/data-structures/graph/directed-graph.d.ts +8 -1
  16. package/dist/data-structures/graph/directed-graph.js +1 -8
  17. package/dist/data-structures/graph/map-graph.d.ts +1 -1
  18. package/dist/data-structures/graph/undirected-graph.d.ts +8 -1
  19. package/dist/data-structures/graph/undirected-graph.js +1 -8
  20. package/dist/data-structures/hash/hash-map.d.ts +22 -10
  21. package/dist/data-structures/hash/hash-map.js +28 -16
  22. package/dist/data-structures/hash/hash-table.d.ts +2 -2
  23. package/dist/data-structures/heap/heap.d.ts +20 -38
  24. package/dist/data-structures/heap/heap.js +22 -42
  25. package/dist/data-structures/heap/max-heap.d.ts +11 -1
  26. package/dist/data-structures/heap/max-heap.js +10 -7
  27. package/dist/data-structures/heap/min-heap.d.ts +11 -1
  28. package/dist/data-structures/heap/min-heap.js +10 -7
  29. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +95 -95
  30. package/dist/data-structures/linked-list/doubly-linked-list.js +132 -136
  31. package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -23
  32. package/dist/data-structures/linked-list/singly-linked-list.js +42 -49
  33. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  34. package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
  35. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
  36. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -7
  37. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
  38. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -7
  39. package/dist/data-structures/priority-queue/priority-queue.d.ts +9 -1
  40. package/dist/data-structures/priority-queue/priority-queue.js +8 -7
  41. package/dist/data-structures/queue/deque.d.ts +76 -80
  42. package/dist/data-structures/queue/deque.js +106 -122
  43. package/dist/data-structures/queue/queue.d.ts +30 -16
  44. package/dist/data-structures/queue/queue.js +31 -24
  45. package/dist/data-structures/stack/stack.d.ts +17 -8
  46. package/dist/data-structures/stack/stack.js +9 -9
  47. package/dist/data-structures/trie/trie.d.ts +14 -5
  48. package/dist/data-structures/trie/trie.js +13 -13
  49. package/dist/interfaces/binary-tree.d.ts +4 -4
  50. package/dist/types/common.d.ts +32 -8
  51. package/dist/types/common.js +22 -1
  52. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
  53. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -22
  54. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  55. package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  56. package/package.json +2 -2
  57. package/src/data-structures/base/iterable-base.ts +24 -0
  58. package/src/data-structures/binary-tree/avl-tree.ts +14 -14
  59. package/src/data-structures/binary-tree/binary-tree.ts +74 -77
  60. package/src/data-structures/binary-tree/bst.ts +18 -17
  61. package/src/data-structures/binary-tree/rb-tree.ts +17 -18
  62. package/src/data-structures/binary-tree/tree-multimap.ts +22 -20
  63. package/src/data-structures/graph/abstract-graph.ts +35 -25
  64. package/src/data-structures/graph/directed-graph.ts +2 -2
  65. package/src/data-structures/graph/map-graph.ts +1 -1
  66. package/src/data-structures/graph/undirected-graph.ts +2 -2
  67. package/src/data-structures/hash/hash-map.ts +40 -24
  68. package/src/data-structures/hash/hash-table.ts +3 -3
  69. package/src/data-structures/heap/heap.ts +33 -60
  70. package/src/data-structures/heap/max-heap.ts +11 -2
  71. package/src/data-structures/heap/min-heap.ts +11 -2
  72. package/src/data-structures/linked-list/doubly-linked-list.ts +147 -145
  73. package/src/data-structures/linked-list/singly-linked-list.ts +52 -52
  74. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  75. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  76. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  77. package/src/data-structures/priority-queue/priority-queue.ts +9 -2
  78. package/src/data-structures/queue/deque.ts +129 -144
  79. package/src/data-structures/queue/queue.ts +37 -26
  80. package/src/data-structures/stack/stack.ts +20 -14
  81. package/src/data-structures/trie/trie.ts +18 -13
  82. package/src/interfaces/binary-tree.ts +5 -5
  83. package/src/types/common.ts +37 -12
  84. package/src/types/data-structures/binary-tree/avl-tree.ts +0 -1
  85. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -26
  86. package/src/types/data-structures/binary-tree/bst.ts +0 -1
  87. package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
  88. package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
@@ -1,5 +1,3 @@
1
- import { IterableElementBase } from "../base";
2
- import { ElementCallback } from "../../types";
3
1
  /**
4
2
  * data-structure-typed
5
3
  *
@@ -7,6 +5,8 @@ import { ElementCallback } from "../../types";
7
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
8
6
  * @license MIT License
9
7
  */
8
+ import type { ElementCallback } from '../../types';
9
+ import { IterableElementBase } from '../base';
10
10
  export declare class DoublyLinkedListNode<E = any> {
11
11
  value: E;
12
12
  next: DoublyLinkedListNode<E> | undefined;
@@ -18,24 +18,29 @@ export declare class DoublyLinkedListNode<E = any> {
18
18
  */
19
19
  constructor(value: E);
20
20
  }
21
+ /**
22
+ * 1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
23
+ * 2. Bidirectional Traversal: Unlike singly linked lists, doubly linked lists can be easily traversed forwards or backwards. This makes insertions and deletions in the list more flexible and efficient.
24
+ * 3. No Centralized Index: Unlike arrays, elements in a linked list are not stored contiguously, so there is no centralized index. Accessing elements in a linked list typically requires traversing from the head or tail node.
25
+ * 4. High Efficiency in Insertion and Deletion: Adding or removing elements in a linked list does not require moving other elements, making these operations more efficient than in arrays.
26
+ */
21
27
  export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
22
28
  /**
23
- * The constructor initializes the linked list with an empty head, tail, and length.
29
+ * The constructor initializes the linked list with an empty head, tail, and size.
24
30
  */
25
31
  constructor(elements?: Iterable<E>);
26
32
  protected _head: DoublyLinkedListNode<E> | undefined;
27
33
  get head(): DoublyLinkedListNode<E> | undefined;
28
34
  protected _tail: DoublyLinkedListNode<E> | undefined;
29
35
  get tail(): DoublyLinkedListNode<E> | undefined;
30
- protected _length: number;
31
- get length(): number;
36
+ protected _size: number;
32
37
  get size(): number;
33
38
  /**
34
- * Time Complexity: O(n), where n is the length of the input array.
39
+ * Time Complexity: O(n), where n is the size of the input array.
35
40
  * Space Complexity: O(n)
36
41
  */
37
42
  /**
38
- * Time Complexity: O(n), where n is the length of the input array.
43
+ * Time Complexity: O(n), where n is the size of the input array.
39
44
  * Space Complexity: O(n)
40
45
  *
41
46
  * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
@@ -55,19 +60,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
55
60
  * The push function adds a new node with the given value to the end of the doubly linked list.
56
61
  * @param {E} value - The value to be added to the linked list.
57
62
  */
58
- push(value: E): void;
59
- /**
60
- * Time Complexity: O(1)
61
- * Space Complexity: O(1)
62
- */
63
- /**
64
- * Time Complexity: O(1)
65
- * Space Complexity: O(1)
66
- *
67
- * The addLast function adds a new node with the given value to the end of the doubly linked list.
68
- * @param {E} value - The value to be added to the linked list.
69
- */
70
- addLast(value: E): void;
63
+ push(value: E): boolean;
71
64
  /**
72
65
  * Time Complexity: O(1)
73
66
  * Space Complexity: O(1)
@@ -81,19 +74,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
81
74
  * list is empty, it returns undefined.
82
75
  */
83
76
  pop(): E | undefined;
84
- /**
85
- * Time Complexity: O(1)
86
- * Space Complexity: O(1)
87
- */
88
- /**
89
- * Time Complexity: O(1)
90
- * Space Complexity: O(1)
91
- *
92
- * The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
93
- * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
94
- * list is empty, it returns undefined.
95
- */
96
- pollLast(): E | undefined;
97
77
  /**
98
78
  * Time Complexity: O(1)
99
79
  * Space Complexity: O(1)
@@ -107,19 +87,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
107
87
  * list.
108
88
  */
109
89
  shift(): E | undefined;
110
- /**
111
- * Time Complexity: O(1)
112
- * Space Complexity: O(1)
113
- */
114
- /**
115
- * Time Complexity: O(1)
116
- * Space Complexity: O(1)
117
- *
118
- * The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
119
- * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
120
- * list.
121
- */
122
- pollFirst(): E | undefined;
123
90
  /**
124
91
  * Time Complexity: O(1)
125
92
  * Space Complexity: O(1)
@@ -132,44 +99,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
132
99
  * @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
133
100
  * doubly linked list.
134
101
  */
135
- unshift(value: E): void;
136
- /**
137
- * Time Complexity: O(1)
138
- * Space Complexity: O(1)
139
- */
140
- /**
141
- * Time Complexity: O(1)
142
- * Space Complexity: O(1)
143
- *
144
- * The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
145
- * @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
146
- * doubly linked list.
147
- */
148
- addFirst(value: E): void;
149
- /**
150
- * Time Complexity: O(n), where n is the number of elements in the linked list.
151
- * Space Complexity: O(1)
152
- */
153
- /**
154
- * Time Complexity: O(n), where n is the number of elements in the linked list.
155
- * Space Complexity: O(1)
156
- *
157
- * The `getFirst` function returns the first node in a doubly linked list, or undefined if the list is empty.
158
- * @returns The method `getFirst()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
159
- */
160
- getFirst(): E | undefined;
161
- /**
162
- * Time Complexity: O(n), where n is the number of elements in the linked list.
163
- * Space Complexity: O(1)
164
- */
165
- /**
166
- * Time Complexity: O(n), where n is the number of elements in the linked list.
167
- * Space Complexity: O(1)
168
- *
169
- * The `getLast` function returns the last node in a doubly linked list, or undefined if the list is empty.
170
- * @returns The method `getLast()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
171
- */
172
- getLast(): E | undefined;
102
+ unshift(value: E): boolean;
173
103
  /**
174
104
  * Time Complexity: O(n), where n is the number of elements in the linked list.
175
105
  * Space Complexity: O(1)
@@ -232,7 +162,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
232
162
  * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
233
163
  * if the index is out of bounds.
234
164
  */
235
- insertAt(index: number, value: E): boolean;
165
+ addAt(index: number, value: E): boolean;
236
166
  /**
237
167
  * Time Complexity: O(n), where n is the number of elements in the linked list.
238
168
  * Space Complexity: O(1)
@@ -241,7 +171,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
241
171
  * Time Complexity: O(n), where n is the number of elements in the linked list.
242
172
  * Space Complexity: O(1)
243
173
  *
244
- * The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
174
+ * The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
245
175
  * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
246
176
  * before which the new value will be inserted. It can be either the value of the existing node or the existing node
247
177
  * itself.
@@ -250,7 +180,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
250
180
  * @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
251
181
  * insertion fails.
252
182
  */
253
- insertBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
183
+ addBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
254
184
  /**
255
185
  * Time Complexity: O(n), where n is the number of elements in the linked list.
256
186
  * Space Complexity: O(1)
@@ -259,7 +189,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
259
189
  * Time Complexity: O(n), where n is the number of elements in the linked list.
260
190
  * Space Complexity: O(1)
261
191
  *
262
- * The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
192
+ * The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
263
193
  * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
264
194
  * after which the new value will be inserted. It can be either the value of the existing node or the existing node
265
195
  * itself.
@@ -267,7 +197,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
267
197
  * @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
268
198
  * existing value or node is not found in the doubly linked list.
269
199
  */
270
- insertAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
200
+ addAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
271
201
  /**
272
202
  * Time Complexity: O(n), where n is the number of elements in the linked list.
273
203
  * Space Complexity: O(1)
@@ -282,7 +212,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
282
212
  * @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
283
213
  * bounds.
284
214
  */
285
- deleteAt(index: number): E | undefined;
215
+ deleteAt(index: number): boolean;
286
216
  /**
287
217
  * Time Complexity: O(n), where n is the number of elements in the linked list.
288
218
  * Space Complexity: O(1)
@@ -299,12 +229,12 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
299
229
  */
300
230
  delete(valOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
301
231
  /**
302
- * The function checks if a variable has a length greater than zero and returns a boolean value.
232
+ * The function checks if a variable has a size greater than zero and returns a boolean value.
303
233
  * @returns A boolean value is being returned.
304
234
  */
305
235
  isEmpty(): boolean;
306
236
  /**
307
- * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
237
+ * The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
308
238
  */
309
239
  clear(): void;
310
240
  /**
@@ -363,7 +293,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
363
293
  *
364
294
  * The `reverse` function reverses the order of the elements in a doubly linked list.
365
295
  */
366
- reverse(): void;
296
+ reverse(): this;
367
297
  /**
368
298
  * Time Complexity: O(n), where n is the number of elements in the linked list.
369
299
  * Space Complexity: O(n)
@@ -432,11 +362,81 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
432
362
  * object.
433
363
  */
434
364
  map<T>(callback: ElementCallback<E, T>, thisArg?: any): DoublyLinkedList<T>;
365
+ /**
366
+ * Time Complexity: O(1)
367
+ * Space Complexity: O(1)
368
+ */
369
+ /**
370
+ * Time Complexity: O(1)
371
+ * Space Complexity: O(1)
372
+ *
373
+ * The addLast function adds a new node with the given value to the end of the doubly linked list.
374
+ * @param {E} value - The value to be added to the linked list.
375
+ */
376
+ addLast(value: E): boolean;
377
+ /**
378
+ * Time Complexity: O(1)
379
+ * Space Complexity: O(1)
380
+ */
381
+ /**
382
+ * Time Complexity: O(1)
383
+ * Space Complexity: O(1)
384
+ *
385
+ * The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
386
+ * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
387
+ * list is empty, it returns undefined.
388
+ */
389
+ pollLast(): E | undefined;
390
+ /**
391
+ * Time Complexity: O(1)
392
+ * Space Complexity: O(1)
393
+ */
394
+ /**
395
+ * Time Complexity: O(1)
396
+ * Space Complexity: O(1)
397
+ *
398
+ * The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
399
+ * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
400
+ * list.
401
+ */
402
+ pollFirst(): E | undefined;
403
+ /**
404
+ * Time Complexity: O(1)
405
+ * Space Complexity: O(1)
406
+ */
407
+ /**
408
+ * Time Complexity: O(1)
409
+ * Space Complexity: O(1)
410
+ *
411
+ * The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
412
+ * @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
413
+ * doubly linked list.
414
+ */
415
+ addFirst(value: E): void;
435
416
  /**
436
417
  * Time Complexity: O(n), where n is the number of elements in the linked list.
437
- * Space Complexity: O(n)
418
+ * Space Complexity: O(1)
419
+ */
420
+ /**
421
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
422
+ * Space Complexity: O(1)
423
+ *
424
+ * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
425
+ * @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
426
+ */
427
+ get first(): E | undefined;
428
+ /**
429
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
430
+ * Space Complexity: O(1)
431
+ */
432
+ /**
433
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
434
+ * Space Complexity: O(1)
435
+ *
436
+ * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
437
+ * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
438
438
  */
439
- print(): void;
439
+ get last(): E | undefined;
440
440
  /**
441
441
  * The function returns an iterator that iterates over the values of a linked list.
442
442
  */