deque-typed 1.51.8 → 1.52.0
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/data-structures/base/index.d.ts +2 -1
- package/dist/data-structures/base/index.js +2 -1
- package/dist/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/data-structures/base/iterable-element-base.js +225 -0
- package/dist/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/data-structures/base/{iterable-base.js → iterable-entry-base.js} +12 -189
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
- package/dist/data-structures/binary-tree/avl-tree.js +78 -59
- package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -226
- package/dist/data-structures/binary-tree/binary-tree.js +475 -363
- package/dist/data-structures/binary-tree/bst.d.ts +192 -202
- package/dist/data-structures/binary-tree/bst.js +207 -249
- package/dist/data-structures/binary-tree/rb-tree.d.ts +73 -74
- package/dist/data-structures/binary-tree/rb-tree.js +107 -98
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
- package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
- package/dist/data-structures/graph/abstract-graph.js +10 -15
- package/dist/data-structures/hash/hash-map.d.ts +33 -40
- package/dist/data-structures/hash/hash-map.js +40 -55
- package/dist/data-structures/heap/heap.d.ts +43 -114
- package/dist/data-structures/heap/heap.js +59 -127
- package/dist/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/data-structures/heap/max-heap.js +76 -10
- package/dist/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/data-structures/heap/min-heap.js +68 -11
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/data-structures/queue/deque.d.ts +21 -20
- package/dist/data-structures/queue/deque.js +29 -23
- package/dist/data-structures/queue/queue.d.ts +8 -28
- package/dist/data-structures/queue/queue.js +15 -31
- package/dist/data-structures/stack/stack.d.ts +17 -22
- package/dist/data-structures/stack/stack.js +25 -24
- package/dist/data-structures/trie/trie.d.ts +19 -14
- package/dist/data-structures/trie/trie.js +27 -16
- package/dist/interfaces/binary-tree.d.ts +7 -7
- package/dist/types/common.d.ts +1 -2
- package/dist/types/data-structures/base/base.d.ts +5 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
- package/dist/types/data-structures/binary-tree/bst.d.ts +4 -5
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
- package/dist/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +3 -2
- package/dist/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/types/data-structures/trie/trie.d.ts +3 -2
- package/dist/utils/utils.js +3 -5
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +2 -1
- package/src/data-structures/base/iterable-element-base.ts +250 -0
- package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +144 -95
- package/src/data-structures/binary-tree/avl-tree.ts +96 -69
- package/src/data-structures/binary-tree/binary-tree.ts +535 -403
- package/src/data-structures/binary-tree/bst.ts +247 -277
- package/src/data-structures/binary-tree/rb-tree.ts +123 -103
- package/src/data-structures/binary-tree/tree-multi-map.ts +127 -102
- package/src/data-structures/graph/abstract-graph.ts +10 -10
- package/src/data-structures/hash/hash-map.ts +46 -53
- package/src/data-structures/heap/heap.ts +71 -152
- package/src/data-structures/heap/max-heap.ts +88 -13
- package/src/data-structures/heap/min-heap.ts +78 -15
- package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
- package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
- package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
- package/src/data-structures/priority-queue/priority-queue.ts +81 -4
- package/src/data-structures/queue/deque.ts +37 -26
- package/src/data-structures/queue/queue.ts +23 -36
- package/src/data-structures/stack/stack.ts +31 -26
- package/src/data-structures/trie/trie.ts +35 -20
- package/src/interfaces/binary-tree.ts +9 -9
- package/src/types/common.ts +1 -2
- package/src/types/data-structures/base/base.ts +14 -6
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -6
- package/src/types/data-structures/binary-tree/bst.ts +4 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
- package/src/types/data-structures/heap/heap.ts +4 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
- package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/types/data-structures/queue/deque.ts +3 -1
- package/src/types/data-structures/queue/queue.ts +3 -1
- package/src/types/data-structures/stack/stack.ts +3 -1
- package/src/types/data-structures/trie/trie.ts +3 -1
- package/src/utils/utils.ts +3 -3
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.IterableEntryBase = void 0;
|
|
4
4
|
class IterableEntryBase {
|
|
5
|
+
// protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
|
|
6
|
+
//
|
|
7
|
+
// /**
|
|
8
|
+
// * The function returns the value of the _toEntryFn property.
|
|
9
|
+
// * @returns The function being returned is `this._toEntryFn`.
|
|
10
|
+
// */
|
|
11
|
+
// get toEntryFn() {
|
|
12
|
+
// return this._toEntryFn;
|
|
13
|
+
// }
|
|
5
14
|
/**
|
|
6
15
|
* Time Complexity: O(n)
|
|
7
16
|
* Space Complexity: O(1)
|
|
@@ -262,32 +271,6 @@ class IterableEntryBase {
|
|
|
262
271
|
}
|
|
263
272
|
return accumulator;
|
|
264
273
|
}
|
|
265
|
-
/**
|
|
266
|
-
* Time Complexity: O(n)
|
|
267
|
-
* Space Complexity: O(n)
|
|
268
|
-
*/
|
|
269
|
-
print() {
|
|
270
|
-
console.log([...this]);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
exports.IterableEntryBase = IterableEntryBase;
|
|
274
|
-
class IterableElementBase {
|
|
275
|
-
/**
|
|
276
|
-
* Time Complexity: O(n)
|
|
277
|
-
* Space Complexity: O(1)
|
|
278
|
-
*/
|
|
279
|
-
/**
|
|
280
|
-
* Time Complexity: O(n)
|
|
281
|
-
* Space Complexity: O(1)
|
|
282
|
-
*
|
|
283
|
-
* The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
|
|
284
|
-
* @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
|
|
285
|
-
* allows the function to accept any number of arguments as an array. In this case, the `args`
|
|
286
|
-
* parameter is used to pass any number of arguments to the `_getIterator` method.
|
|
287
|
-
*/
|
|
288
|
-
*[Symbol.iterator](...args) {
|
|
289
|
-
yield* this._getIterator(...args);
|
|
290
|
-
}
|
|
291
274
|
/**
|
|
292
275
|
* Time Complexity: O(n)
|
|
293
276
|
* Space Complexity: O(n)
|
|
@@ -296,170 +279,10 @@ class IterableElementBase {
|
|
|
296
279
|
* Time Complexity: O(n)
|
|
297
280
|
* Space Complexity: O(n)
|
|
298
281
|
*
|
|
299
|
-
* The function
|
|
300
|
-
*/
|
|
301
|
-
*values() {
|
|
302
|
-
for (const item of this) {
|
|
303
|
-
yield item;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Time Complexity: O(n)
|
|
308
|
-
* Space Complexity: O(1)
|
|
309
|
-
*/
|
|
310
|
-
/**
|
|
311
|
-
* Time Complexity: O(n)
|
|
312
|
-
* Space Complexity: O(1)
|
|
313
|
-
*
|
|
314
|
-
* The `every` function checks if every element in the array satisfies a given predicate.
|
|
315
|
-
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
316
|
-
* the current element being processed, its index, and the array it belongs to. It should return a
|
|
317
|
-
* boolean value indicating whether the element satisfies a certain condition or not.
|
|
318
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
319
|
-
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
320
|
-
* passed as the `this` value to the `predicate` function. If `thisArg` is
|
|
321
|
-
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
322
|
-
* the array satisfies the provided predicate function, and `false` otherwise.
|
|
323
|
-
*/
|
|
324
|
-
every(predicate, thisArg) {
|
|
325
|
-
let index = 0;
|
|
326
|
-
for (const item of this) {
|
|
327
|
-
if (!predicate.call(thisArg, item, index++, this)) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return true;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Time Complexity: O(n)
|
|
335
|
-
* Space Complexity: O(1)
|
|
336
|
-
*/
|
|
337
|
-
/**
|
|
338
|
-
* Time Complexity: O(n)
|
|
339
|
-
* Space Complexity: O(1)
|
|
340
|
-
*/
|
|
341
|
-
/**
|
|
342
|
-
* Time Complexity: O(n)
|
|
343
|
-
* Space Complexity: O(1)
|
|
344
|
-
*
|
|
345
|
-
* The "some" function checks if at least one element in a collection satisfies a given predicate.
|
|
346
|
-
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
347
|
-
* `value`, `index`, and `array`. It should return a boolean value indicating whether the current
|
|
348
|
-
* element satisfies the condition.
|
|
349
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
350
|
-
* to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
|
|
351
|
-
* it will be passed as the `this` value to the `predicate` function. If `thisArg
|
|
352
|
-
* @returns a boolean value. It returns true if the predicate function returns true for any element
|
|
353
|
-
* in the collection, and false otherwise.
|
|
354
|
-
*/
|
|
355
|
-
some(predicate, thisArg) {
|
|
356
|
-
let index = 0;
|
|
357
|
-
for (const item of this) {
|
|
358
|
-
if (predicate.call(thisArg, item, index++, this)) {
|
|
359
|
-
return true;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Time Complexity: O(n)
|
|
366
|
-
* Space Complexity: O(1)
|
|
367
|
-
*/
|
|
368
|
-
/**
|
|
369
|
-
* Time Complexity: O(n)
|
|
370
|
-
* Space Complexity: O(1)
|
|
371
|
-
*
|
|
372
|
-
* The `forEach` function iterates over each element in an array-like object and calls a callback
|
|
373
|
-
* function for each element.
|
|
374
|
-
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
375
|
-
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
376
|
-
* element, and the array that forEach was called upon.
|
|
377
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
378
|
-
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
379
|
-
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
380
|
-
*/
|
|
381
|
-
forEach(callbackfn, thisArg) {
|
|
382
|
-
let index = 0;
|
|
383
|
-
for (const item of this) {
|
|
384
|
-
callbackfn.call(thisArg, item, index++, this);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Time Complexity: O(n)
|
|
389
|
-
* Space Complexity: O(1)
|
|
390
|
-
*/
|
|
391
|
-
/**
|
|
392
|
-
* Time Complexity: O(n)
|
|
393
|
-
* Space Complexity: O(1)
|
|
394
|
-
*
|
|
395
|
-
* The `find` function iterates over the elements of an array-like object and returns the first
|
|
396
|
-
* element that satisfies the provided callback function.
|
|
397
|
-
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
398
|
-
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
399
|
-
* element, and the array itself. The function should return a boolean value indicating whether the
|
|
400
|
-
* current element matches the desired condition.
|
|
401
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
402
|
-
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
403
|
-
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
404
|
-
* @returns The `find` method returns the first element in the array that satisfies the provided
|
|
405
|
-
* callback function. If no element satisfies the callback function, `undefined` is returned.
|
|
406
|
-
*/
|
|
407
|
-
find(callbackfn, thisArg) {
|
|
408
|
-
let index = 0;
|
|
409
|
-
for (const item of this) {
|
|
410
|
-
if (callbackfn.call(thisArg, item, index++, this))
|
|
411
|
-
return item;
|
|
412
|
-
}
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Time Complexity: O(n)
|
|
417
|
-
* Space Complexity: O(1)
|
|
418
|
-
*
|
|
419
|
-
* The function checks if a given element exists in a collection.
|
|
420
|
-
* @param {E} element - The parameter "element" is of type E, which means it can be any type. It
|
|
421
|
-
* represents the element that we want to check for existence in the collection.
|
|
422
|
-
* @returns a boolean value. It returns true if the element is found in the collection, and false
|
|
423
|
-
* otherwise.
|
|
424
|
-
*/
|
|
425
|
-
has(element) {
|
|
426
|
-
for (const ele of this) {
|
|
427
|
-
if (ele === element)
|
|
428
|
-
return true;
|
|
429
|
-
}
|
|
430
|
-
return false;
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Time Complexity: O(n)
|
|
434
|
-
* Space Complexity: O(1)
|
|
435
|
-
*/
|
|
436
|
-
/**
|
|
437
|
-
* Time Complexity: O(n)
|
|
438
|
-
* Space Complexity: O(1)
|
|
439
|
-
*
|
|
440
|
-
* The `reduce` function iterates over the elements of an array-like object and applies a callback
|
|
441
|
-
* function to reduce them into a single value.
|
|
442
|
-
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
443
|
-
* the array. It takes four arguments:
|
|
444
|
-
* @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
|
|
445
|
-
* is the value that the accumulator starts with before the reduction operation begins.
|
|
446
|
-
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
447
|
-
* all the elements in the array and applying the callback function to each element.
|
|
448
|
-
*/
|
|
449
|
-
reduce(callbackfn, initialValue) {
|
|
450
|
-
let accumulator = initialValue;
|
|
451
|
-
let index = 0;
|
|
452
|
-
for (const item of this) {
|
|
453
|
-
accumulator = callbackfn(accumulator, item, index++, this);
|
|
454
|
-
}
|
|
455
|
-
return accumulator;
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* Time Complexity: O(n)
|
|
459
|
-
* Space Complexity: O(n)
|
|
282
|
+
* The print function logs the elements of an array to the console.
|
|
460
283
|
*/
|
|
461
284
|
print() {
|
|
462
285
|
console.log([...this]);
|
|
463
286
|
}
|
|
464
287
|
}
|
|
465
|
-
exports.
|
|
288
|
+
exports.IterableEntryBase = IterableEntryBase;
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback,
|
|
8
|
+
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, IterationType, KeyOrNodeOrEntry } from '../../types';
|
|
9
|
+
import { BTNEntry } from '../../types';
|
|
9
10
|
import { IBinaryTree } from '../../interfaces';
|
|
10
11
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
11
|
-
export declare class AVLTreeMultiMapNode<K
|
|
12
|
+
export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
|
|
12
13
|
/**
|
|
13
14
|
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
14
15
|
* @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
|
|
@@ -36,8 +37,16 @@ export declare class AVLTreeMultiMapNode<K extends Comparable, V = any, NODE ext
|
|
|
36
37
|
/**
|
|
37
38
|
* The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
38
39
|
*/
|
|
39
|
-
export declare class AVLTreeMultiMap<K
|
|
40
|
-
|
|
40
|
+
export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMapNested<K, V, R, NODE>>> extends AVLTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
41
|
+
/**
|
|
42
|
+
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
|
|
43
|
+
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
|
|
44
|
+
* iterable object that can contain either keys, nodes, entries, or raw elements.
|
|
45
|
+
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
46
|
+
* behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
|
|
47
|
+
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
48
|
+
*/
|
|
49
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeMultiMapOptions<K, V, R>);
|
|
41
50
|
protected _count: number;
|
|
42
51
|
/**
|
|
43
52
|
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
@@ -59,35 +68,46 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
59
68
|
*/
|
|
60
69
|
getComputedCount(): number;
|
|
61
70
|
/**
|
|
62
|
-
* The function creates a new
|
|
63
|
-
* @param {K} key - The key parameter
|
|
64
|
-
*
|
|
65
|
-
* @param {
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
71
|
+
* The function creates a new AVLTreeMultiMapNode with the specified key, value, and count.
|
|
72
|
+
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
73
|
+
* which is a generic type that can be replaced with any specific type when using the function.
|
|
74
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
75
|
+
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
76
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of a
|
|
77
|
+
* key-value pair in the AVLTreeMultiMapNode. It is an optional parameter, so it can be omitted when
|
|
78
|
+
* calling the `createNode` method. If provided, it specifies the initial count for the node.
|
|
79
|
+
* @returns a new instance of the AVLTreeMultiMapNode class, casted as NODE.
|
|
69
80
|
*/
|
|
70
81
|
createNode(key: K, value?: V, count?: number): NODE;
|
|
71
|
-
createTree(options?: AVLTreeMultiMapOptions<K>): TREE;
|
|
72
|
-
/**
|
|
73
|
-
* The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
|
|
74
|
-
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, which means it
|
|
75
|
-
* can be one of the following:
|
|
76
|
-
* @param {V} [value] - The `value` parameter is an optional argument that represents the value
|
|
77
|
-
* associated with the node. It is of type `V`, which can be any data type. If no value is provided,
|
|
78
|
-
* it defaults to `undefined`.
|
|
79
|
-
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
80
|
-
* times the value should be added to the node. If not provided, it defaults to 1.
|
|
81
|
-
* @returns a node of type `NODE` or `undefined`.
|
|
82
|
-
*/
|
|
83
|
-
keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
|
|
84
82
|
/**
|
|
85
|
-
* The function
|
|
86
|
-
* @param
|
|
87
|
-
*
|
|
88
|
-
* class
|
|
83
|
+
* The function creates a new AVLTreeMultiMap object with the specified options and returns it.
|
|
84
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
85
|
+
* configuration options for creating the AVLTreeMultiMap. It can have the following properties:
|
|
86
|
+
* @returns a new instance of the AVLTreeMultiMap class, with the specified options, as a TREE
|
|
87
|
+
* object.
|
|
88
|
+
*/
|
|
89
|
+
createTree(options?: AVLTreeMultiMapOptions<K, V, R>): TREE;
|
|
90
|
+
/**
|
|
91
|
+
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
92
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
93
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
94
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
95
|
+
* an instance of the `AVLTreeMultiMapNode` class.
|
|
96
|
+
*/
|
|
97
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
98
|
+
/**
|
|
99
|
+
* The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
|
|
100
|
+
* a node object.
|
|
101
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
102
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
103
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
104
|
+
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
105
|
+
* value is provided, it will default to `undefined`.
|
|
106
|
+
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
107
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
108
|
+
* @returns either a NODE object or undefined.
|
|
89
109
|
*/
|
|
90
|
-
|
|
110
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
|
|
91
111
|
/**
|
|
92
112
|
* Time Complexity: O(log n)
|
|
93
113
|
* Space Complexity: O(1)
|
|
@@ -96,19 +116,20 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
96
116
|
* Time Complexity: O(log n)
|
|
97
117
|
* Space Complexity: O(1)
|
|
98
118
|
*
|
|
99
|
-
* The function overrides the add method of a
|
|
100
|
-
*
|
|
101
|
-
*
|
|
119
|
+
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
120
|
+
* and update the count.
|
|
121
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
122
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
|
|
123
|
+
* can also accept a value of type `KeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
|
|
124
|
+
* entry, or raw element
|
|
102
125
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
103
|
-
*
|
|
104
|
-
* method.
|
|
126
|
+
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
105
127
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
106
|
-
* be added to the
|
|
107
|
-
* added once. However, you can specify a different value for `count` if you want to add
|
|
108
|
-
* @returns
|
|
109
|
-
* was not successful.
|
|
128
|
+
* be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
|
|
129
|
+
* be added once. However, you can specify a different value for `count` if you want to add
|
|
130
|
+
* @returns a boolean value.
|
|
110
131
|
*/
|
|
111
|
-
add(
|
|
132
|
+
add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
|
|
112
133
|
/**
|
|
113
134
|
* Time Complexity: O(log n)
|
|
114
135
|
* Space Complexity: O(1)
|
|
@@ -117,19 +138,19 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
117
138
|
* Time Complexity: O(log n)
|
|
118
139
|
* Space Complexity: O(1)
|
|
119
140
|
*
|
|
120
|
-
* The `delete` function in
|
|
121
|
-
*
|
|
122
|
-
* @param identifier - The identifier is the value
|
|
123
|
-
*
|
|
141
|
+
* The `delete` function in a binary tree data structure deletes a node based on its identifier and
|
|
142
|
+
* returns the deleted node along with the parent node that needs to be balanced.
|
|
143
|
+
* @param identifier - The identifier parameter is the value used to identify the node that needs to
|
|
144
|
+
* be deleted from the binary tree. It can be of any type and is the return type of the callback
|
|
124
145
|
* function.
|
|
125
|
-
* @param {C} callback - The `callback` parameter is a function that is used to determine
|
|
126
|
-
*
|
|
127
|
-
* function takes
|
|
128
|
-
*
|
|
146
|
+
* @param {C} callback - The `callback` parameter is a function that is used to determine the
|
|
147
|
+
* equality of nodes in the binary tree. It is optional and has a default value of
|
|
148
|
+
* `this._DEFAULT_CALLBACK`. The `callback` function takes a single argument, which is the identifier
|
|
149
|
+
* of a node, and returns a value that
|
|
129
150
|
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
|
|
130
151
|
* being deleted. If set to true, the count of the node will not be considered and the node will be
|
|
131
|
-
* deleted regardless of its count. If set to false (default), the count of the node will be
|
|
132
|
-
*
|
|
152
|
+
* deleted regardless of its count. If set to false (default), the count of the node will be taken
|
|
153
|
+
* into account and the node
|
|
133
154
|
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
|
|
134
155
|
*/
|
|
135
156
|
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
|
|
@@ -141,7 +162,8 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
141
162
|
* Time Complexity: O(1)
|
|
142
163
|
* Space Complexity: O(1)
|
|
143
164
|
*
|
|
144
|
-
* The clear
|
|
165
|
+
* The "clear" function overrides the parent class's "clear" function and also resets the count to
|
|
166
|
+
* zero.
|
|
145
167
|
*/
|
|
146
168
|
clear(): void;
|
|
147
169
|
/**
|
|
@@ -151,13 +173,14 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
151
173
|
/**
|
|
152
174
|
* Time Complexity: O(n log n)
|
|
153
175
|
* Space Complexity: O(log n)
|
|
154
|
-
*
|
|
155
176
|
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
156
177
|
* tree using either a recursive or iterative approach.
|
|
157
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that
|
|
158
|
-
* type of iteration to use when building the balanced binary search tree. It
|
|
159
|
-
*
|
|
160
|
-
*
|
|
178
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
179
|
+
* specifies the type of iteration to use when building the balanced binary search tree. It has a
|
|
180
|
+
* default value of `this.iterationType`, which means it will use the iteration type currently set in
|
|
181
|
+
* the object.
|
|
182
|
+
* @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
|
|
183
|
+
* balancing operation is successful, and `false` if there are no nodes to balance.
|
|
161
184
|
*/
|
|
162
185
|
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
163
186
|
/**
|
|
@@ -168,27 +191,42 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
168
191
|
* Time complexity: O(n)
|
|
169
192
|
* Space complexity: O(n)
|
|
170
193
|
*
|
|
171
|
-
* The
|
|
194
|
+
* The function overrides the clone method to create a deep copy of a tree object.
|
|
172
195
|
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
173
196
|
*/
|
|
174
197
|
clone(): TREE;
|
|
175
198
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
199
|
+
* Time Complexity: O(1)
|
|
200
|
+
* Space Complexity: O(1)
|
|
201
|
+
*/
|
|
202
|
+
/**
|
|
203
|
+
* Time Complexity: O(1)
|
|
204
|
+
* Space Complexity: O(1)
|
|
205
|
+
*
|
|
206
|
+
* The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
|
|
207
|
+
* in a binary search tree.
|
|
208
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
|
|
209
|
+
* that will be swapped with the `destNode`.
|
|
210
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
|
|
211
|
+
* node where the properties will be swapped with the source node.
|
|
212
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
213
|
+
* If either `srcNode` or `destNode` is undefined, it returns `undefined`.
|
|
183
214
|
*/
|
|
184
|
-
protected _swapProperties(srcNode: BSTNKeyOrNode<K, NODE>, destNode: BSTNKeyOrNode<K, NODE>): NODE | undefined;
|
|
215
|
+
protected _swapProperties(srcNode: R | BSTNKeyOrNode<K, NODE>, destNode: R | BSTNKeyOrNode<K, NODE>): NODE | undefined;
|
|
185
216
|
/**
|
|
217
|
+
* Time Complexity: O(1)
|
|
218
|
+
* Space Complexity: O(1)
|
|
219
|
+
*/
|
|
220
|
+
/**
|
|
221
|
+
* Time Complexity: O(1)
|
|
222
|
+
* Space Complexity: O(1)
|
|
223
|
+
*
|
|
186
224
|
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
187
|
-
* @param {NODE} oldNode - The
|
|
188
|
-
*
|
|
189
|
-
* @param {NODE} newNode - The `newNode` parameter is an
|
|
225
|
+
* @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
226
|
+
* data structure. It is of type NODE.
|
|
227
|
+
* @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
|
|
190
228
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
191
|
-
* superclass,
|
|
229
|
+
* superclass, which is of type `NODE`.
|
|
192
230
|
*/
|
|
193
231
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
194
232
|
}
|