directed-graph-typed 1.53.7 → 1.53.8
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/common/index.js +5 -0
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +2 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +2 -2
- package/dist/data-structures/binary-tree/bst.d.ts +53 -23
- package/dist/data-structures/binary-tree/bst.js +59 -25
- package/dist/data-structures/binary-tree/index.d.ts +1 -1
- package/dist/data-structures/binary-tree/index.js +1 -1
- package/dist/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +49 -0
- package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +50 -1
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
- package/dist/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/data-structures/hash/hash-map.d.ts +30 -0
- package/dist/data-structures/hash/hash-map.js +30 -0
- package/dist/data-structures/heap/heap.d.ts +20 -3
- package/dist/data-structures/heap/heap.js +31 -11
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +36 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +56 -9
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +34 -1
- package/dist/data-structures/linked-list/singly-linked-list.js +54 -10
- package/dist/data-structures/queue/deque.d.ts +37 -8
- package/dist/data-structures/queue/deque.js +73 -29
- package/dist/data-structures/queue/queue.d.ts +41 -1
- package/dist/data-structures/queue/queue.js +51 -9
- package/dist/data-structures/stack/stack.d.ts +27 -10
- package/dist/data-structures/stack/stack.js +39 -20
- package/dist/data-structures/trie/trie.d.ts +8 -3
- package/dist/data-structures/trie/trie.js +8 -3
- package/package.json +2 -2
- package/src/common/index.ts +7 -1
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +2 -2
- package/src/data-structures/binary-tree/bst.ts +64 -25
- package/src/data-structures/binary-tree/index.ts +1 -1
- package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +50 -1
- package/src/data-structures/binary-tree/tree-multi-map.ts +3 -3
- package/src/data-structures/hash/hash-map.ts +30 -0
- package/src/data-structures/heap/heap.ts +33 -10
- package/src/data-structures/linked-list/doubly-linked-list.ts +62 -8
- package/src/data-structures/linked-list/singly-linked-list.ts +60 -10
- package/src/data-structures/queue/deque.ts +72 -28
- package/src/data-structures/queue/queue.ts +50 -7
- package/src/data-structures/stack/stack.ts +39 -20
- package/src/data-structures/trie/trie.ts +8 -3
|
@@ -75,6 +75,9 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
75
75
|
return this._hashFn;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
+
* Time Complexity: O(1)
|
|
79
|
+
* Space Complexity: O(1)
|
|
80
|
+
*
|
|
78
81
|
* The function checks if a given element is an array with exactly two elements.
|
|
79
82
|
* @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
|
|
80
83
|
* data type.
|
|
@@ -84,6 +87,9 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
84
87
|
return Array.isArray(rawElement) && rawElement.length === 2;
|
|
85
88
|
}
|
|
86
89
|
/**
|
|
90
|
+
* Time Complexity: O(1)
|
|
91
|
+
* Space Complexity: O(1)
|
|
92
|
+
*
|
|
87
93
|
* The function checks if the size of an object is equal to zero and returns a boolean value.
|
|
88
94
|
* @returns A boolean value indicating whether the size of the object is 0 or not.
|
|
89
95
|
*/
|
|
@@ -91,6 +97,9 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
91
97
|
return this._size === 0;
|
|
92
98
|
}
|
|
93
99
|
/**
|
|
100
|
+
* Time Complexity: O(1)
|
|
101
|
+
* Space Complexity: O(1)
|
|
102
|
+
*
|
|
94
103
|
* The clear() function resets the state of an object by clearing its internal store, object map, and
|
|
95
104
|
* size.
|
|
96
105
|
*/
|
|
@@ -100,6 +109,9 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
100
109
|
this._size = 0;
|
|
101
110
|
}
|
|
102
111
|
/**
|
|
112
|
+
* Time Complexity: O(1)
|
|
113
|
+
* Space Complexity: O(1)
|
|
114
|
+
*
|
|
103
115
|
* The `set` function adds a key-value pair to a map-like data structure, incrementing the size if
|
|
104
116
|
* the key is not already present.
|
|
105
117
|
* @param {K} key - The key parameter is the key used to identify the value in the data structure. It
|
|
@@ -125,6 +137,9 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
125
137
|
return true;
|
|
126
138
|
}
|
|
127
139
|
/**
|
|
140
|
+
* Time Complexity: O(k)
|
|
141
|
+
* Space Complexity: O(k)
|
|
142
|
+
*
|
|
128
143
|
* The function `setMany` takes an iterable collection of objects, maps each object to a key-value
|
|
129
144
|
* pair using a mapping function, and sets each key-value pair in the current object.
|
|
130
145
|
* @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
|
|
@@ -150,6 +165,9 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
150
165
|
return results;
|
|
151
166
|
}
|
|
152
167
|
/**
|
|
168
|
+
* Time Complexity: O(1)
|
|
169
|
+
* Space Complexity: O(1)
|
|
170
|
+
*
|
|
153
171
|
* The `get` function retrieves a value from a map based on a given key, either from an object map or
|
|
154
172
|
* a string map.
|
|
155
173
|
* @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
|
|
@@ -168,6 +186,9 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
168
186
|
}
|
|
169
187
|
}
|
|
170
188
|
/**
|
|
189
|
+
* Time Complexity: O(1)
|
|
190
|
+
* Space Complexity: O(1)
|
|
191
|
+
*
|
|
171
192
|
* The `has` function checks if a given key exists in the `_objMap` or `_store` based on whether it
|
|
172
193
|
* is an object key or not.
|
|
173
194
|
* @param {K} key - The parameter "key" is of type K, which means it can be any type.
|
|
@@ -183,6 +204,9 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
183
204
|
}
|
|
184
205
|
}
|
|
185
206
|
/**
|
|
207
|
+
* Time Complexity: O(1)
|
|
208
|
+
* Space Complexity: O(1)
|
|
209
|
+
*
|
|
186
210
|
* The `delete` function removes an element from a map-like data structure based on the provided key.
|
|
187
211
|
* @param {K} key - The `key` parameter is the key of the element that you want to delete from the
|
|
188
212
|
* data structure.
|
|
@@ -523,6 +547,9 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
523
547
|
return true;
|
|
524
548
|
}
|
|
525
549
|
/**
|
|
550
|
+
* Time Complexity: O(k)
|
|
551
|
+
* Space Complexity: O(k)
|
|
552
|
+
*
|
|
526
553
|
* The function `setMany` takes an iterable collection, converts each element into a key-value pair
|
|
527
554
|
* using a provided function, and sets each key-value pair in the current object, returning an array
|
|
528
555
|
* of booleans indicating the success of each set operation.
|
|
@@ -549,6 +576,9 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
549
576
|
return results;
|
|
550
577
|
}
|
|
551
578
|
/**
|
|
579
|
+
* Time Complexity: O(1)
|
|
580
|
+
* Space Complexity: O(1)
|
|
581
|
+
*
|
|
552
582
|
* The function checks if a given key exists in a map, using different logic depending on whether the
|
|
553
583
|
* key is a weak key or not.
|
|
554
584
|
* @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
|
|
@@ -224,10 +224,27 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R, He
|
|
|
224
224
|
* Time Complexity: O(log n)
|
|
225
225
|
* Space Complexity: O(1)
|
|
226
226
|
*
|
|
227
|
-
*
|
|
228
|
-
* @param element - The element to
|
|
227
|
+
* The add function pushes an element into an array and then triggers a bubble-up operation.
|
|
228
|
+
* @param {E} element - The `element` parameter represents the element that you want to add to the
|
|
229
|
+
* data structure.
|
|
230
|
+
* @returns The `add` method is returning a boolean value, which is the result of calling the
|
|
231
|
+
* `_bubbleUp` method with the index `this.elements.length - 1` as an argument.
|
|
229
232
|
*/
|
|
230
233
|
add(element: E): boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Time Complexity: O(k log n)
|
|
236
|
+
* Space Complexity: O(1)
|
|
237
|
+
*
|
|
238
|
+
* The `addMany` function iterates over elements and adds them to a collection, returning an array of
|
|
239
|
+
* boolean values indicating success or failure.
|
|
240
|
+
* @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `addMany` method is
|
|
241
|
+
* an iterable containing elements of type `E` or `R`. The method iterates over each element in the
|
|
242
|
+
* iterable and adds them to the data structure. If a transformation function `_toElementFn` is
|
|
243
|
+
* provided, it transforms the element
|
|
244
|
+
* @returns The `addMany` method returns an array of boolean values indicating whether each element
|
|
245
|
+
* in the input iterable was successfully added to the data structure.
|
|
246
|
+
*/
|
|
247
|
+
addMany(elements: Iterable<E> | Iterable<R>): boolean[];
|
|
231
248
|
/**
|
|
232
249
|
* Time Complexity: O(log n)
|
|
233
250
|
* Space Complexity: O(1)
|
|
@@ -340,7 +357,7 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R, He
|
|
|
340
357
|
*/
|
|
341
358
|
filter(callback: ElementCallback<E, R, boolean, Heap<E, R>>, thisArg?: any): Heap<E, R>;
|
|
342
359
|
/**
|
|
343
|
-
* Time Complexity: O(n
|
|
360
|
+
* Time Complexity: O(n)
|
|
344
361
|
* Space Complexity: O(n)
|
|
345
362
|
*
|
|
346
363
|
* The `map` function creates a new heap by applying a callback function to each element of the
|
|
@@ -218,14 +218,7 @@ class Heap extends base_1.IterableElementBase {
|
|
|
218
218
|
if (comparator)
|
|
219
219
|
this._comparator = comparator;
|
|
220
220
|
}
|
|
221
|
-
|
|
222
|
-
for (const el of elements) {
|
|
223
|
-
if (this.toElementFn)
|
|
224
|
-
this.add(this.toElementFn(el));
|
|
225
|
-
else
|
|
226
|
-
this.add(el);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
221
|
+
this.addMany(elements);
|
|
229
222
|
}
|
|
230
223
|
/**
|
|
231
224
|
* The function returns an array of elements.
|
|
@@ -261,13 +254,40 @@ class Heap extends base_1.IterableElementBase {
|
|
|
261
254
|
* Time Complexity: O(log n)
|
|
262
255
|
* Space Complexity: O(1)
|
|
263
256
|
*
|
|
264
|
-
*
|
|
265
|
-
* @param element - The element to
|
|
257
|
+
* The add function pushes an element into an array and then triggers a bubble-up operation.
|
|
258
|
+
* @param {E} element - The `element` parameter represents the element that you want to add to the
|
|
259
|
+
* data structure.
|
|
260
|
+
* @returns The `add` method is returning a boolean value, which is the result of calling the
|
|
261
|
+
* `_bubbleUp` method with the index `this.elements.length - 1` as an argument.
|
|
266
262
|
*/
|
|
267
263
|
add(element) {
|
|
268
264
|
this._elements.push(element);
|
|
269
265
|
return this._bubbleUp(this.elements.length - 1);
|
|
270
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Time Complexity: O(k log n)
|
|
269
|
+
* Space Complexity: O(1)
|
|
270
|
+
*
|
|
271
|
+
* The `addMany` function iterates over elements and adds them to a collection, returning an array of
|
|
272
|
+
* boolean values indicating success or failure.
|
|
273
|
+
* @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `addMany` method is
|
|
274
|
+
* an iterable containing elements of type `E` or `R`. The method iterates over each element in the
|
|
275
|
+
* iterable and adds them to the data structure. If a transformation function `_toElementFn` is
|
|
276
|
+
* provided, it transforms the element
|
|
277
|
+
* @returns The `addMany` method returns an array of boolean values indicating whether each element
|
|
278
|
+
* in the input iterable was successfully added to the data structure.
|
|
279
|
+
*/
|
|
280
|
+
addMany(elements) {
|
|
281
|
+
const ans = [];
|
|
282
|
+
for (const el of elements) {
|
|
283
|
+
if (this._toElementFn) {
|
|
284
|
+
ans.push(this.add(this._toElementFn(el)));
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
ans.push(this.add(el));
|
|
288
|
+
}
|
|
289
|
+
return ans;
|
|
290
|
+
}
|
|
271
291
|
/**
|
|
272
292
|
* Time Complexity: O(log n)
|
|
273
293
|
* Space Complexity: O(1)
|
|
@@ -470,7 +490,7 @@ class Heap extends base_1.IterableElementBase {
|
|
|
470
490
|
return filteredList;
|
|
471
491
|
}
|
|
472
492
|
/**
|
|
473
|
-
* Time Complexity: O(n
|
|
493
|
+
* Time Complexity: O(n)
|
|
474
494
|
* Space Complexity: O(n)
|
|
475
495
|
*
|
|
476
496
|
* The `map` function creates a new heap by applying a callback function to each element of the
|
|
@@ -497,7 +497,7 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
497
497
|
* `DoublyLinkedListOptions<E, R>`. It is an optional parameter that allows you to pass additional
|
|
498
498
|
* configuration options to customize the behavior of the DoublyLinkedList.
|
|
499
499
|
*/
|
|
500
|
-
constructor(elements?: Iterable<E> | Iterable<R
|
|
500
|
+
constructor(elements?: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>, options?: DoublyLinkedListOptions<E, R>);
|
|
501
501
|
protected _head: DoublyLinkedListNode<E> | undefined;
|
|
502
502
|
/**
|
|
503
503
|
* The `head` function returns the first node of a doubly linked list.
|
|
@@ -585,6 +585,35 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
585
585
|
* @returns The `unshift` method is returning a boolean value, specifically `true`.
|
|
586
586
|
*/
|
|
587
587
|
unshift(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
588
|
+
/**
|
|
589
|
+
* Time Complexity: O(k)
|
|
590
|
+
* Space Complexity: O(k)
|
|
591
|
+
*
|
|
592
|
+
* The function `pushMany` iterates over elements and pushes them into a data structure, applying a
|
|
593
|
+
* transformation function if provided.
|
|
594
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
|
|
595
|
+
* parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
|
|
596
|
+
* or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and pushes
|
|
597
|
+
* it onto the linked list. If a transformation function `to
|
|
598
|
+
* @returns The `pushMany` function is returning an array of boolean values (`ans`) which indicate
|
|
599
|
+
* the success or failure of pushing each element into the data structure.
|
|
600
|
+
*/
|
|
601
|
+
pushMany(elements: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>): boolean[];
|
|
602
|
+
/**
|
|
603
|
+
* Time Complexity: O(k)
|
|
604
|
+
* Space Complexity: O(k)
|
|
605
|
+
*
|
|
606
|
+
* The function `unshiftMany` iterates through a collection of elements and adds them to the
|
|
607
|
+
* beginning of a Doubly Linked List, returning an array of boolean values indicating the success of
|
|
608
|
+
* each insertion.
|
|
609
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
|
|
610
|
+
* parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
|
|
611
|
+
* `R`, or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and
|
|
612
|
+
* performs an `unshift` operation on the doubly linked list
|
|
613
|
+
* @returns The `unshiftMany` function returns an array of boolean values indicating the success of
|
|
614
|
+
* each unshift operation performed on the elements passed as input.
|
|
615
|
+
*/
|
|
616
|
+
unshiftMany(elements: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>): boolean[];
|
|
588
617
|
/**
|
|
589
618
|
* Time Complexity: O(n)
|
|
590
619
|
* Space Complexity: O(1)
|
|
@@ -830,6 +859,12 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
830
859
|
* Time Complexity: O(n)
|
|
831
860
|
* Space Complexity: O(1)
|
|
832
861
|
*
|
|
862
|
+
* The function `countOccurrences` iterates through a doubly linked list and counts the occurrences
|
|
863
|
+
* of a specified element or nodes that satisfy a given predicate.
|
|
864
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementOrNode
|
|
865
|
+
* - The `elementOrNode` parameter in the `countOccurrences` method can accept three types of values:
|
|
866
|
+
* @returns The `countOccurrences` method returns the number of occurrences of the specified element,
|
|
867
|
+
* node, or predicate function in the doubly linked list.
|
|
833
868
|
*/
|
|
834
869
|
countOccurrences(elementOrNode: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): number;
|
|
835
870
|
/**
|
|
@@ -511,15 +511,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
511
511
|
this._head = undefined;
|
|
512
512
|
this._tail = undefined;
|
|
513
513
|
this._size = 0;
|
|
514
|
-
|
|
515
|
-
for (const el of elements) {
|
|
516
|
-
if (this.toElementFn) {
|
|
517
|
-
this.push(this.toElementFn(el));
|
|
518
|
-
}
|
|
519
|
-
else
|
|
520
|
-
this.push(el);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
514
|
+
this.pushMany(elements);
|
|
523
515
|
}
|
|
524
516
|
/**
|
|
525
517
|
* The `head` function returns the first node of a doubly linked list.
|
|
@@ -673,6 +665,55 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
673
665
|
this._size++;
|
|
674
666
|
return true;
|
|
675
667
|
}
|
|
668
|
+
/**
|
|
669
|
+
* Time Complexity: O(k)
|
|
670
|
+
* Space Complexity: O(k)
|
|
671
|
+
*
|
|
672
|
+
* The function `pushMany` iterates over elements and pushes them into a data structure, applying a
|
|
673
|
+
* transformation function if provided.
|
|
674
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
|
|
675
|
+
* parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
|
|
676
|
+
* or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and pushes
|
|
677
|
+
* it onto the linked list. If a transformation function `to
|
|
678
|
+
* @returns The `pushMany` function is returning an array of boolean values (`ans`) which indicate
|
|
679
|
+
* the success or failure of pushing each element into the data structure.
|
|
680
|
+
*/
|
|
681
|
+
pushMany(elements) {
|
|
682
|
+
const ans = [];
|
|
683
|
+
for (const el of elements) {
|
|
684
|
+
if (this.toElementFn) {
|
|
685
|
+
ans.push(this.push(this.toElementFn(el)));
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
ans.push(this.push(el));
|
|
689
|
+
}
|
|
690
|
+
return ans;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Time Complexity: O(k)
|
|
694
|
+
* Space Complexity: O(k)
|
|
695
|
+
*
|
|
696
|
+
* The function `unshiftMany` iterates through a collection of elements and adds them to the
|
|
697
|
+
* beginning of a Doubly Linked List, returning an array of boolean values indicating the success of
|
|
698
|
+
* each insertion.
|
|
699
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
|
|
700
|
+
* parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
|
|
701
|
+
* `R`, or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and
|
|
702
|
+
* performs an `unshift` operation on the doubly linked list
|
|
703
|
+
* @returns The `unshiftMany` function returns an array of boolean values indicating the success of
|
|
704
|
+
* each unshift operation performed on the elements passed as input.
|
|
705
|
+
*/
|
|
706
|
+
unshiftMany(elements) {
|
|
707
|
+
const ans = [];
|
|
708
|
+
for (const el of elements) {
|
|
709
|
+
if (this.toElementFn) {
|
|
710
|
+
ans.push(this.unshift(this.toElementFn(el)));
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
ans.push(this.unshift(el));
|
|
714
|
+
}
|
|
715
|
+
return ans;
|
|
716
|
+
}
|
|
676
717
|
/**
|
|
677
718
|
* Time Complexity: O(n)
|
|
678
719
|
* Space Complexity: O(1)
|
|
@@ -1124,6 +1165,12 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
1124
1165
|
* Time Complexity: O(n)
|
|
1125
1166
|
* Space Complexity: O(1)
|
|
1126
1167
|
*
|
|
1168
|
+
* The function `countOccurrences` iterates through a doubly linked list and counts the occurrences
|
|
1169
|
+
* of a specified element or nodes that satisfy a given predicate.
|
|
1170
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementOrNode
|
|
1171
|
+
* - The `elementOrNode` parameter in the `countOccurrences` method can accept three types of values:
|
|
1172
|
+
* @returns The `countOccurrences` method returns the number of occurrences of the specified element,
|
|
1173
|
+
* node, or predicate function in the doubly linked list.
|
|
1127
1174
|
*/
|
|
1128
1175
|
countOccurrences(elementOrNode) {
|
|
1129
1176
|
const predicate = this._ensurePredicate(elementOrNode);
|
|
@@ -41,7 +41,7 @@ export declare class SinglyLinkedListNode<E = any> {
|
|
|
41
41
|
set next(value: SinglyLinkedListNode<E> | undefined);
|
|
42
42
|
}
|
|
43
43
|
export declare class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R, SinglyLinkedList<E, R>> {
|
|
44
|
-
constructor(elements?: Iterable<E> | Iterable<R
|
|
44
|
+
constructor(elements?: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>, options?: SinglyLinkedListOptions<E, R>);
|
|
45
45
|
protected _head: SinglyLinkedListNode<E> | undefined;
|
|
46
46
|
/**
|
|
47
47
|
* The `head` function returns the first node of a singly linked list.
|
|
@@ -111,6 +111,33 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
111
111
|
* @returns The `unshift` method is returning a boolean value, specifically `true`.
|
|
112
112
|
*/
|
|
113
113
|
unshift(elementOrNode: E | SinglyLinkedListNode<E>): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Time Complexity: O(k)
|
|
116
|
+
* Space Complexity: O(k)
|
|
117
|
+
*
|
|
118
|
+
* The function `pushMany` iterates over elements and pushes them into a data structure, applying a
|
|
119
|
+
* transformation function if provided.
|
|
120
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
|
|
121
|
+
* parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
|
|
122
|
+
* or `SinglyLinkedListNode<E>`.
|
|
123
|
+
* @returns The `pushMany` function returns an array of boolean values indicating whether each
|
|
124
|
+
* element was successfully pushed into the data structure.
|
|
125
|
+
*/
|
|
126
|
+
pushMany(elements: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>): boolean[];
|
|
127
|
+
/**
|
|
128
|
+
* Time Complexity: O(k)
|
|
129
|
+
* Space Complexity: O(k)
|
|
130
|
+
*
|
|
131
|
+
* The function `unshiftMany` iterates over elements and adds them to a data structure, optionally
|
|
132
|
+
* converting them using a provided function.
|
|
133
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
|
|
134
|
+
* parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
|
|
135
|
+
* `R`, or `SinglyLinkedListNode<E>`. The function iterates over each element in the iterable and
|
|
136
|
+
* performs an `unshift` operation on the linked list for each
|
|
137
|
+
* @returns The `unshiftMany` function is returning an array of boolean values, where each value
|
|
138
|
+
* represents the result of calling the `unshift` method on the current instance of the class.
|
|
139
|
+
*/
|
|
140
|
+
unshiftMany(elements: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>): boolean[];
|
|
114
141
|
/**
|
|
115
142
|
* Time Complexity: O(n)
|
|
116
143
|
* Space Complexity: O(1)
|
|
@@ -199,12 +226,18 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
199
226
|
*/
|
|
200
227
|
addAt(index: number, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
|
|
201
228
|
/**
|
|
229
|
+
* Time Complexity: O(1)
|
|
230
|
+
* Space Complexity: O(1)
|
|
231
|
+
*
|
|
202
232
|
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
|
|
203
233
|
* whether it is empty or not.
|
|
204
234
|
* @returns A boolean value indicating whether the length of the object is equal to 0.
|
|
205
235
|
*/
|
|
206
236
|
isEmpty(): boolean;
|
|
207
237
|
/**
|
|
238
|
+
* Time Complexity: O(1)
|
|
239
|
+
* Space Complexity: O(1)
|
|
240
|
+
*
|
|
208
241
|
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
209
242
|
*/
|
|
210
243
|
clear(): void;
|
|
@@ -49,16 +49,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
49
49
|
constructor(elements = [], options) {
|
|
50
50
|
super(options);
|
|
51
51
|
this._size = 0;
|
|
52
|
-
|
|
53
|
-
for (const el of elements) {
|
|
54
|
-
if (this.toElementFn) {
|
|
55
|
-
this.push(this.toElementFn(el));
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
this.push(el);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
52
|
+
this.pushMany(elements);
|
|
62
53
|
}
|
|
63
54
|
/**
|
|
64
55
|
* The `head` function returns the first node of a singly linked list.
|
|
@@ -188,6 +179,53 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
188
179
|
this._size++;
|
|
189
180
|
return true;
|
|
190
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Time Complexity: O(k)
|
|
184
|
+
* Space Complexity: O(k)
|
|
185
|
+
*
|
|
186
|
+
* The function `pushMany` iterates over elements and pushes them into a data structure, applying a
|
|
187
|
+
* transformation function if provided.
|
|
188
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
|
|
189
|
+
* parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
|
|
190
|
+
* or `SinglyLinkedListNode<E>`.
|
|
191
|
+
* @returns The `pushMany` function returns an array of boolean values indicating whether each
|
|
192
|
+
* element was successfully pushed into the data structure.
|
|
193
|
+
*/
|
|
194
|
+
pushMany(elements) {
|
|
195
|
+
const ans = [];
|
|
196
|
+
for (const el of elements) {
|
|
197
|
+
if (this.toElementFn) {
|
|
198
|
+
ans.push(this.push(this.toElementFn(el)));
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
ans.push(this.push(el));
|
|
202
|
+
}
|
|
203
|
+
return ans;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Time Complexity: O(k)
|
|
207
|
+
* Space Complexity: O(k)
|
|
208
|
+
*
|
|
209
|
+
* The function `unshiftMany` iterates over elements and adds them to a data structure, optionally
|
|
210
|
+
* converting them using a provided function.
|
|
211
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
|
|
212
|
+
* parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
|
|
213
|
+
* `R`, or `SinglyLinkedListNode<E>`. The function iterates over each element in the iterable and
|
|
214
|
+
* performs an `unshift` operation on the linked list for each
|
|
215
|
+
* @returns The `unshiftMany` function is returning an array of boolean values, where each value
|
|
216
|
+
* represents the result of calling the `unshift` method on the current instance of the class.
|
|
217
|
+
*/
|
|
218
|
+
unshiftMany(elements) {
|
|
219
|
+
const ans = [];
|
|
220
|
+
for (const el of elements) {
|
|
221
|
+
if (this.toElementFn) {
|
|
222
|
+
ans.push(this.unshift(this.toElementFn(el)));
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
ans.push(this.unshift(el));
|
|
226
|
+
}
|
|
227
|
+
return ans;
|
|
228
|
+
}
|
|
191
229
|
/**
|
|
192
230
|
* Time Complexity: O(n)
|
|
193
231
|
* Space Complexity: O(1)
|
|
@@ -366,6 +404,9 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
366
404
|
return true;
|
|
367
405
|
}
|
|
368
406
|
/**
|
|
407
|
+
* Time Complexity: O(1)
|
|
408
|
+
* Space Complexity: O(1)
|
|
409
|
+
*
|
|
369
410
|
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
|
|
370
411
|
* whether it is empty or not.
|
|
371
412
|
* @returns A boolean value indicating whether the length of the object is equal to 0.
|
|
@@ -374,6 +415,9 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
374
415
|
return this._size === 0;
|
|
375
416
|
}
|
|
376
417
|
/**
|
|
418
|
+
* Time Complexity: O(1)
|
|
419
|
+
* Space Complexity: O(1)
|
|
420
|
+
*
|
|
377
421
|
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
378
422
|
*/
|
|
379
423
|
clear() {
|
|
@@ -115,6 +115,16 @@ export declare class Deque<E = any, R = any> extends IterableElementBase<E, R, D
|
|
|
115
115
|
* @returns The element that was removed from the data structure is being returned.
|
|
116
116
|
*/
|
|
117
117
|
pop(): E | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Time Complexity: O(1)
|
|
120
|
+
* Space Complexity: O(1)
|
|
121
|
+
*
|
|
122
|
+
* The `shift()` function removes and returns the first element from a data structure, updating the
|
|
123
|
+
* internal state variables accordingly.
|
|
124
|
+
* @returns The element that is being removed from the beginning of the data structure is being
|
|
125
|
+
* returned.
|
|
126
|
+
*/
|
|
127
|
+
shift(): E | undefined;
|
|
118
128
|
/**
|
|
119
129
|
* Time Complexity: Amortized O(1)
|
|
120
130
|
* Space Complexity: O(n)
|
|
@@ -127,15 +137,34 @@ export declare class Deque<E = any, R = any> extends IterableElementBase<E, R, D
|
|
|
127
137
|
*/
|
|
128
138
|
unshift(element: E): boolean;
|
|
129
139
|
/**
|
|
130
|
-
* Time Complexity: O(
|
|
131
|
-
* Space Complexity: O(
|
|
140
|
+
* Time Complexity: O(k)
|
|
141
|
+
* Space Complexity: O(k)
|
|
132
142
|
*
|
|
133
|
-
* The `
|
|
134
|
-
*
|
|
135
|
-
* @
|
|
136
|
-
*
|
|
137
|
-
|
|
138
|
-
|
|
143
|
+
* The function `pushMany` iterates over elements and pushes them into an array after applying a
|
|
144
|
+
* transformation function if provided.
|
|
145
|
+
* @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
|
|
146
|
+
* parameter in the `pushMany` function is expected to be an iterable containing elements of type `E`
|
|
147
|
+
* or `R`. It can be either an `IterableWithSizeOrLength<E>` or an `IterableWithSizeOrLength<R>`. The
|
|
148
|
+
* function iterates over each element
|
|
149
|
+
* @returns The `pushMany` function is returning an array of boolean values, where each value
|
|
150
|
+
* represents the result of calling the `push` method on the current object instance with the
|
|
151
|
+
* corresponding element from the input `elements` iterable.
|
|
152
|
+
*/
|
|
153
|
+
pushMany(elements: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
|
|
154
|
+
/**
|
|
155
|
+
* Time Complexity: O(k)
|
|
156
|
+
* Space Complexity: O(k)
|
|
157
|
+
*
|
|
158
|
+
* The `unshiftMany` function in TypeScript iterates over elements and adds them to the beginning of
|
|
159
|
+
* an array, optionally converting them using a provided function.
|
|
160
|
+
* @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
|
|
161
|
+
* parameter in the `unshiftMany` function is an iterable containing elements of type `E` or `R`. It
|
|
162
|
+
* can be an array or any other iterable data structure that has a known size or length. The function
|
|
163
|
+
* iterates over each element in the `elements` iterable and
|
|
164
|
+
* @returns The `unshiftMany` function returns an array of boolean values indicating whether each
|
|
165
|
+
* element was successfully added to the beginning of the array.
|
|
166
|
+
*/
|
|
167
|
+
unshiftMany(elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
|
|
139
168
|
/**
|
|
140
169
|
* Time Complexity: O(1)
|
|
141
170
|
* Space Complexity: O(1)
|