avl-tree-typed 1.53.8 → 1.54.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/iterable-entry-base.js +4 -4
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +34 -27
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +62 -52
- package/dist/data-structures/binary-tree/avl-tree.d.ts +3 -14
- package/dist/data-structures/binary-tree/avl-tree.js +22 -25
- package/dist/data-structures/binary-tree/binary-tree.d.ts +32 -16
- package/dist/data-structures/binary-tree/binary-tree.js +43 -24
- package/dist/data-structures/binary-tree/bst.d.ts +14 -23
- package/dist/data-structures/binary-tree/bst.js +28 -29
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +26 -16
- package/dist/data-structures/binary-tree/red-black-tree.js +43 -59
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +18 -14
- package/dist/data-structures/binary-tree/tree-multi-map.js +36 -23
- package/dist/data-structures/graph/abstract-graph.js +2 -2
- package/dist/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/data-structures/hash/hash-map.js +5 -5
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +10 -10
- package/dist/data-structures/linked-list/doubly-linked-list.js +12 -12
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +10 -10
- package/dist/data-structures/linked-list/singly-linked-list.js +16 -16
- package/dist/interfaces/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -4
- package/package.json +2 -2
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +83 -64
- package/src/data-structures/binary-tree/avl-tree.ts +40 -34
- package/src/data-structures/binary-tree/binary-tree.ts +74 -30
- package/src/data-structures/binary-tree/bst.ts +57 -43
- package/src/data-structures/binary-tree/red-black-tree.ts +66 -70
- package/src/data-structures/binary-tree/tree-multi-map.ts +56 -30
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +7 -7
- package/src/data-structures/linked-list/doubly-linked-list.ts +13 -13
- package/src/data-structures/linked-list/singly-linked-list.ts +17 -17
- package/src/interfaces/binary-tree.ts +4 -1
- package/src/types/data-structures/base/base.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -2
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +3 -3
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -4
|
@@ -450,7 +450,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
450
450
|
* @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
|
|
451
451
|
* function.
|
|
452
452
|
*/
|
|
453
|
-
map<
|
|
453
|
+
map<MK, MV>(callback: EntryCallback<K, V, [MK, MV]>, thisArg?: any): LinkedHashMap<MK, MV>;
|
|
454
454
|
/**
|
|
455
455
|
* Time Complexity: O(n)
|
|
456
456
|
* Space Complexity: O(1)
|
|
@@ -261,7 +261,7 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
261
261
|
const resultMap = new HashMap();
|
|
262
262
|
let index = 0;
|
|
263
263
|
for (const [key, value] of this) {
|
|
264
|
-
resultMap.set(key, callbackfn.call(thisArg,
|
|
264
|
+
resultMap.set(key, callbackfn.call(thisArg, key, value, index++, this));
|
|
265
265
|
}
|
|
266
266
|
return resultMap;
|
|
267
267
|
}
|
|
@@ -285,7 +285,7 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
285
285
|
const filteredMap = new HashMap();
|
|
286
286
|
let index = 0;
|
|
287
287
|
for (const [key, value] of this) {
|
|
288
|
-
if (predicate.call(thisArg,
|
|
288
|
+
if (predicate.call(thisArg, key, value, index++, this)) {
|
|
289
289
|
filteredMap.set(key, value);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
@@ -758,7 +758,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
758
758
|
const filteredMap = new LinkedHashMap();
|
|
759
759
|
let index = 0;
|
|
760
760
|
for (const [key, value] of this) {
|
|
761
|
-
if (predicate.call(thisArg,
|
|
761
|
+
if (predicate.call(thisArg, key, value, index, this)) {
|
|
762
762
|
filteredMap.set(key, value);
|
|
763
763
|
}
|
|
764
764
|
index++;
|
|
@@ -786,8 +786,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
786
786
|
const mappedMap = new LinkedHashMap();
|
|
787
787
|
let index = 0;
|
|
788
788
|
for (const [key, value] of this) {
|
|
789
|
-
const newValue = callback.call(thisArg,
|
|
790
|
-
mappedMap.set(
|
|
789
|
+
const [newKey, newValue] = callback.call(thisArg, key, value, index, this);
|
|
790
|
+
mappedMap.set(newKey, newValue);
|
|
791
791
|
index++;
|
|
792
792
|
}
|
|
793
793
|
return mappedMap;
|
|
@@ -533,6 +533,16 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
533
533
|
* @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
534
534
|
*/
|
|
535
535
|
get last(): E | undefined;
|
|
536
|
+
/**
|
|
537
|
+
* Time Complexity: O(n)
|
|
538
|
+
* Space Complexity: O(n)
|
|
539
|
+
*
|
|
540
|
+
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
541
|
+
* given array.
|
|
542
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
543
|
+
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
544
|
+
*/
|
|
545
|
+
static fromArray<E>(data: E[]): DoublyLinkedList<E, any>;
|
|
536
546
|
/**
|
|
537
547
|
* Time Complexity: O(1)
|
|
538
548
|
* Space Complexity: O(1)
|
|
@@ -867,16 +877,6 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
867
877
|
* node, or predicate function in the doubly linked list.
|
|
868
878
|
*/
|
|
869
879
|
countOccurrences(elementOrNode: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): number;
|
|
870
|
-
/**
|
|
871
|
-
* Time Complexity: O(n)
|
|
872
|
-
* Space Complexity: O(n)
|
|
873
|
-
*
|
|
874
|
-
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
875
|
-
* given array.
|
|
876
|
-
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
877
|
-
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
878
|
-
*/
|
|
879
|
-
static fromArray<E>(data: E[]): DoublyLinkedList<E, any>;
|
|
880
880
|
/**
|
|
881
881
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
882
882
|
*/
|
|
@@ -557,6 +557,18 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
557
557
|
var _a;
|
|
558
558
|
return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value;
|
|
559
559
|
}
|
|
560
|
+
/**
|
|
561
|
+
* Time Complexity: O(n)
|
|
562
|
+
* Space Complexity: O(n)
|
|
563
|
+
*
|
|
564
|
+
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
565
|
+
* given array.
|
|
566
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
567
|
+
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
568
|
+
*/
|
|
569
|
+
static fromArray(data) {
|
|
570
|
+
return new DoublyLinkedList(data);
|
|
571
|
+
}
|
|
560
572
|
/**
|
|
561
573
|
* Time Complexity: O(1)
|
|
562
574
|
* Space Complexity: O(1)
|
|
@@ -1184,18 +1196,6 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
1184
1196
|
}
|
|
1185
1197
|
return count;
|
|
1186
1198
|
}
|
|
1187
|
-
/**
|
|
1188
|
-
* Time Complexity: O(n)
|
|
1189
|
-
* Space Complexity: O(n)
|
|
1190
|
-
*
|
|
1191
|
-
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
1192
|
-
* given array.
|
|
1193
|
-
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
1194
|
-
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
1195
|
-
*/
|
|
1196
|
-
static fromArray(data) {
|
|
1197
|
-
return new DoublyLinkedList(data);
|
|
1198
|
-
}
|
|
1199
1199
|
/**
|
|
1200
1200
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
1201
1201
|
*/
|
|
@@ -72,6 +72,16 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
72
72
|
* @returns The size of the object, which is a number.
|
|
73
73
|
*/
|
|
74
74
|
get size(): number;
|
|
75
|
+
/**
|
|
76
|
+
* Time Complexity: O(n)
|
|
77
|
+
* Space Complexity: O(n)
|
|
78
|
+
*
|
|
79
|
+
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
|
|
80
|
+
* array.
|
|
81
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
82
|
+
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
|
|
83
|
+
*/
|
|
84
|
+
static fromArray<E>(data: E[]): SinglyLinkedList<E, any>;
|
|
75
85
|
/**
|
|
76
86
|
* Time Complexity: O(1)
|
|
77
87
|
* Space Complexity: O(1)
|
|
@@ -384,16 +394,6 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
384
394
|
* The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
|
|
385
395
|
*/
|
|
386
396
|
protected _getIterator(): IterableIterator<E>;
|
|
387
|
-
/**
|
|
388
|
-
* Time Complexity: O(n)
|
|
389
|
-
* Space Complexity: O(n)
|
|
390
|
-
*
|
|
391
|
-
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
|
|
392
|
-
* array.
|
|
393
|
-
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
394
|
-
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
|
|
395
|
-
*/
|
|
396
|
-
static fromArray<E>(data: E[]): SinglyLinkedList<E, any>;
|
|
397
397
|
/**
|
|
398
398
|
* The _isPredicate function in TypeScript checks if the input is a function that takes a
|
|
399
399
|
* SinglyLinkedListNode as an argument and returns a boolean.
|
|
@@ -90,6 +90,22 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
90
90
|
get size() {
|
|
91
91
|
return this._size;
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Time Complexity: O(n)
|
|
95
|
+
* Space Complexity: O(n)
|
|
96
|
+
*
|
|
97
|
+
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
|
|
98
|
+
* array.
|
|
99
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
100
|
+
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
|
|
101
|
+
*/
|
|
102
|
+
static fromArray(data) {
|
|
103
|
+
const singlyLinkedList = new SinglyLinkedList();
|
|
104
|
+
for (const item of data) {
|
|
105
|
+
singlyLinkedList.push(item);
|
|
106
|
+
}
|
|
107
|
+
return singlyLinkedList;
|
|
108
|
+
}
|
|
93
109
|
/**
|
|
94
110
|
* Time Complexity: O(1)
|
|
95
111
|
* Space Complexity: O(1)
|
|
@@ -690,22 +706,6 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
690
706
|
current = current.next;
|
|
691
707
|
}
|
|
692
708
|
}
|
|
693
|
-
/**
|
|
694
|
-
* Time Complexity: O(n)
|
|
695
|
-
* Space Complexity: O(n)
|
|
696
|
-
*
|
|
697
|
-
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
|
|
698
|
-
* array.
|
|
699
|
-
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
700
|
-
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
|
|
701
|
-
*/
|
|
702
|
-
static fromArray(data) {
|
|
703
|
-
const singlyLinkedList = new SinglyLinkedList();
|
|
704
|
-
for (const item of data) {
|
|
705
|
-
singlyLinkedList.push(item);
|
|
706
|
-
}
|
|
707
|
-
return singlyLinkedList;
|
|
708
|
-
}
|
|
709
709
|
/**
|
|
710
710
|
* The _isPredicate function in TypeScript checks if the input is a function that takes a
|
|
711
711
|
* SinglyLinkedListNode as an argument and returns a boolean.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
2
|
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNRep, NodePredicate } from '../types';
|
|
3
|
-
export interface IBinaryTree<K = any, V = any, R = object, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTreeNested<K, V, R, NODE>> {
|
|
3
|
+
export interface IBinaryTree<K = any, V = any, R = object, MK = any, MV = any, MR = object, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, R, MK, MV, MR, NODE, TREE> = BinaryTreeNested<K, V, R, MK, MV, MR, NODE>> {
|
|
4
4
|
createNode(key: K, value?: NODE['value']): NODE;
|
|
5
5
|
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
|
|
6
6
|
add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, NODE>, value?: V, count?: number): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
|
|
2
|
-
export type EntryCallback<K, V, R> = (
|
|
2
|
+
export type EntryCallback<K, V, R> = (key: K, value: V, index: number, container: IterableEntryBase<K, V>) => R;
|
|
3
3
|
export type ElementCallback<E, R, RT, C> = (element: E, index: number, container: IterableElementBase<E, R, C>) => RT;
|
|
4
4
|
export type ReduceEntryCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
|
|
5
5
|
export type ReduceElementCallback<E, R, RT, C> = (accumulator: RT, element: E, index: number, container: IterableElementBase<E, R, C>) => RT;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../data-structures';
|
|
2
2
|
import type { AVLTreeOptions } from './avl-tree';
|
|
3
|
-
export type AVLTreeMultiMapNodeNested<K, V> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V,
|
|
4
|
-
export type AVLTreeMultiMapNested<K, V, R,
|
|
3
|
+
export type AVLTreeMultiMapNodeNested<K, V> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, any>>>;
|
|
4
|
+
export type AVLTreeMultiMapNested<K, V, R, MK, MV, MR, NODE extends AVLTreeMultiMapNode<K, V, NODE>> = AVLTreeMultiMap<K, V, R, MK, MV, MR, NODE, AVLTreeMultiMap<K, V, R, MK, MV, MR, NODE, AVLTreeMultiMap<K, V, R, MK, MV, MR, NODE, any>>>;
|
|
5
5
|
export type AVLTreeMultiMapOptions<K, V, R> = AVLTreeOptions<K, V, R> & {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AVLTree, AVLTreeNode } from '../../../data-structures';
|
|
2
2
|
import { BSTOptions } from './bst';
|
|
3
|
-
export type AVLTreeNodeNested<K, V> = AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V,
|
|
4
|
-
export type AVLTreeNested<K, V, R,
|
|
3
|
+
export type AVLTreeNodeNested<K, V> = AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, any>>>;
|
|
4
|
+
export type AVLTreeNested<K, V, R, MK, MV, MR, NODE extends AVLTreeNode<K, V, NODE>> = AVLTree<K, V, R, MK, MV, MR, NODE, AVLTree<K, V, R, MK, MV, MR, NODE, AVLTree<K, V, R, MK, MV, MR, NODE, any>>>;
|
|
5
5
|
export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
2
|
import { IterationType, OptValue } from '../../common';
|
|
3
3
|
import { DFSOperation } from '../../../common';
|
|
4
|
-
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V,
|
|
5
|
-
export type BinaryTreeNested<K, V, R,
|
|
4
|
+
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>;
|
|
5
|
+
export type BinaryTreeNested<K, V, R, MK, MV, MR, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, R, MK, MV, MR, NODE, BinaryTree<K, V, R, MK, MV, MR, NODE, BinaryTree<K, V, R, MK, MV, MR, NODE, any>>>;
|
|
6
6
|
export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
|
|
7
7
|
export type BinaryTreeOptions<K, V, R> = {
|
|
8
8
|
iterationType?: IterationType;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BST, BSTNode } from '../../../data-structures';
|
|
2
2
|
import type { BinaryTreeOptions } from './binary-tree';
|
|
3
3
|
import { Comparable } from '../../utils';
|
|
4
|
-
export type BSTNodeNested<K, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V,
|
|
5
|
-
export type BSTNested<K, V, R,
|
|
4
|
+
export type BSTNodeNested<K, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, any>>>;
|
|
5
|
+
export type BSTNested<K, V, R, MK, MV, MR, NODE extends BSTNode<K, V, NODE>> = BST<K, V, R, MK, MV, MR, NODE, BST<K, V, R, MK, MV, MR, NODE, BST<K, V, R, MK, MV, MR, NODE, any>>>;
|
|
6
6
|
export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
|
|
7
|
-
|
|
7
|
+
specifyComparable?: (key: K) => Comparable;
|
|
8
8
|
isReverse?: boolean;
|
|
9
9
|
};
|
|
10
10
|
export type BSTNOptKey<K> = K | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RedBlackTree, RedBlackTreeNode } from '../../../data-structures';
|
|
2
2
|
import type { BSTOptions } from "./bst";
|
|
3
3
|
export type RBTNColor = 'RED' | 'BLACK';
|
|
4
|
-
export type RedBlackTreeNodeNested<K, V> = RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V,
|
|
5
|
-
export type RedBlackTreeNested<K, V, R,
|
|
6
|
-
export type
|
|
4
|
+
export type RedBlackTreeNodeNested<K, V> = RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, any>>>;
|
|
5
|
+
export type RedBlackTreeNested<K, V, R, MK, MV, MR, NODE extends RedBlackTreeNode<K, V, NODE>> = RedBlackTree<K, V, R, MK, MV, MR, NODE, RedBlackTree<K, V, R, MK, MV, MR, NODE, RedBlackTree<K, V, R, MK, MV, MR, NODE, any>>>;
|
|
6
|
+
export type RedBlackTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TreeMultiMap, TreeMultiMapNode } from '../../../data-structures';
|
|
2
|
-
import type {
|
|
3
|
-
export type TreeMultiMapNodeNested<K, V> = TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V,
|
|
4
|
-
export type TreeMultiMapNested<K, V, R,
|
|
5
|
-
export type TreeMultiMapOptions<K, V, R> =
|
|
2
|
+
import type { RedBlackTreeOptions } from './rb-tree';
|
|
3
|
+
export type TreeMultiMapNodeNested<K, V> = TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, any>>>;
|
|
4
|
+
export type TreeMultiMapNested<K, V, R, MK, MV, MR, NODE extends TreeMultiMapNode<K, V, NODE>> = TreeMultiMap<K, V, R, MK, MV, MR, NODE, TreeMultiMap<K, V, R, MK, MV, MR, NODE, TreeMultiMap<K, V, R, MK, MV, MR, NODE, any>>>;
|
|
5
|
+
export type TreeMultiMapOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "avl-tree-typed",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.54.0",
|
|
4
4
|
"description": "AVLTree(Adelson-Velsky and Landis Tree). Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -163,6 +163,6 @@
|
|
|
163
163
|
"typescript": "^4.9.5"
|
|
164
164
|
},
|
|
165
165
|
"dependencies": {
|
|
166
|
-
"data-structure-typed": "^1.
|
|
166
|
+
"data-structure-typed": "^1.54.0"
|
|
167
167
|
}
|
|
168
168
|
}
|
|
@@ -70,7 +70,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
70
70
|
every(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
|
|
71
71
|
let index = 0;
|
|
72
72
|
for (const item of this) {
|
|
73
|
-
if (!predicate.call(thisArg, item[
|
|
73
|
+
if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
|
|
74
74
|
return false;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -95,7 +95,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
95
95
|
some(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
|
|
96
96
|
let index = 0;
|
|
97
97
|
for (const item of this) {
|
|
98
|
-
if (predicate.call(thisArg, item[
|
|
98
|
+
if (predicate.call(thisArg, item[0], item[1], index++, this)) {
|
|
99
99
|
return true;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -119,7 +119,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
119
119
|
let index = 0;
|
|
120
120
|
for (const item of this) {
|
|
121
121
|
const [key, value] = item;
|
|
122
|
-
callbackfn.call(thisArg,
|
|
122
|
+
callbackfn.call(thisArg, key, value, index++, this);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -144,7 +144,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
144
144
|
let index = 0;
|
|
145
145
|
for (const item of this) {
|
|
146
146
|
const [key, value] = item;
|
|
147
|
-
if (callbackfn.call(thisArg,
|
|
147
|
+
if (callbackfn.call(thisArg, key, value, index++, this)) return item;
|
|
148
148
|
}
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
BinaryTreeDeleteResult,
|
|
13
13
|
BSTNOptKeyOrNode,
|
|
14
14
|
BTNRep,
|
|
15
|
+
EntryCallback,
|
|
15
16
|
IterationType
|
|
16
17
|
} from '../../types';
|
|
17
18
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -36,25 +37,6 @@ export class AVLTreeMultiMapNode<
|
|
|
36
37
|
super(key, value);
|
|
37
38
|
this.count = count;
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
protected _count: number = 1;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The function returns the value of the protected variable _count.
|
|
44
|
-
* @returns The count property of the object, which is of type number.
|
|
45
|
-
*/
|
|
46
|
-
get count(): number {
|
|
47
|
-
return this._count;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The above function sets the value of the count property.
|
|
52
|
-
* @param {number} value - The value parameter is of type number, which means it can accept any
|
|
53
|
-
* numeric value.
|
|
54
|
-
*/
|
|
55
|
-
set count(value: number) {
|
|
56
|
-
this._count = value;
|
|
57
|
-
}
|
|
58
40
|
}
|
|
59
41
|
|
|
60
42
|
/**
|
|
@@ -64,17 +46,23 @@ export class AVLTreeMultiMap<
|
|
|
64
46
|
K = any,
|
|
65
47
|
V = any,
|
|
66
48
|
R = object,
|
|
49
|
+
MK = any,
|
|
50
|
+
MV = any,
|
|
51
|
+
MR = object,
|
|
67
52
|
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
|
|
68
|
-
TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<
|
|
53
|
+
TREE extends AVLTreeMultiMap<K, V, R, MK, MV, MR, NODE, TREE> = AVLTreeMultiMap<
|
|
69
54
|
K,
|
|
70
55
|
V,
|
|
71
56
|
R,
|
|
57
|
+
MK,
|
|
58
|
+
MV,
|
|
59
|
+
MR,
|
|
72
60
|
NODE,
|
|
73
|
-
AVLTreeMultiMapNested<K, V, R, NODE>
|
|
61
|
+
AVLTreeMultiMapNested<K, V, R, MK, MV, MR, NODE>
|
|
74
62
|
>
|
|
75
63
|
>
|
|
76
|
-
extends AVLTree<K, V, R, NODE, TREE>
|
|
77
|
-
implements IBinaryTree<K, V, R, NODE, TREE>
|
|
64
|
+
extends AVLTree<K, V, R, MK, MV, MR, NODE, TREE>
|
|
65
|
+
implements IBinaryTree<K, V, R, MK, MV, MR, NODE, TREE>
|
|
78
66
|
{
|
|
79
67
|
/**
|
|
80
68
|
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
|
|
@@ -140,10 +128,10 @@ export class AVLTreeMultiMap<
|
|
|
140
128
|
* object.
|
|
141
129
|
*/
|
|
142
130
|
override createTree(options?: AVLTreeMultiMapOptions<K, V, R>): TREE {
|
|
143
|
-
return new AVLTreeMultiMap<K, V, R, NODE, TREE>([], {
|
|
131
|
+
return new AVLTreeMultiMap<K, V, R, MK, MV, MR, NODE, TREE>([], {
|
|
144
132
|
iterationType: this.iterationType,
|
|
145
133
|
isMapMode: this._isMapMode,
|
|
146
|
-
|
|
134
|
+
specifyComparable: this._specifyComparable,
|
|
147
135
|
toEntryFn: this._toEntryFn,
|
|
148
136
|
isReverse: this._isReverse,
|
|
149
137
|
...options
|
|
@@ -161,44 +149,6 @@ export class AVLTreeMultiMap<
|
|
|
161
149
|
return keyNodeEntryOrRaw instanceof AVLTreeMultiMapNode;
|
|
162
150
|
}
|
|
163
151
|
|
|
164
|
-
/**
|
|
165
|
-
* The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
|
|
166
|
-
* a node object.
|
|
167
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
168
|
-
* `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
169
|
-
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
170
|
-
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
171
|
-
* value is provided, it will default to `undefined`.
|
|
172
|
-
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
173
|
-
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
174
|
-
* @returns either a NODE object or undefined.
|
|
175
|
-
*/
|
|
176
|
-
protected override _keyValueNodeEntryRawToNodeAndValue(
|
|
177
|
-
keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R,
|
|
178
|
-
value?: V,
|
|
179
|
-
count = 1
|
|
180
|
-
): [NODE | undefined, V | undefined] {
|
|
181
|
-
if (keyNodeEntryOrRaw === undefined || keyNodeEntryOrRaw === null) return [undefined, undefined];
|
|
182
|
-
if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
|
|
183
|
-
|
|
184
|
-
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
185
|
-
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
186
|
-
if (key === undefined || key === null) return [undefined, undefined];
|
|
187
|
-
const finalValue = value ?? entryValue;
|
|
188
|
-
return [this.createNode(key, finalValue, count), finalValue];
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
192
|
-
const [key, entryValue] = this._toEntryFn!(keyNodeEntryOrRaw);
|
|
193
|
-
const finalValue = value ?? entryValue;
|
|
194
|
-
if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
|
|
198
|
-
|
|
199
|
-
return [undefined, undefined];
|
|
200
|
-
}
|
|
201
|
-
|
|
202
152
|
/**
|
|
203
153
|
* Time Complexity: O(log n)
|
|
204
154
|
* Space Complexity: O(1)
|
|
@@ -264,7 +214,7 @@ export class AVLTreeMultiMap<
|
|
|
264
214
|
} else {
|
|
265
215
|
if (!curr.left) {
|
|
266
216
|
if (!parent) {
|
|
267
|
-
if (curr.right !== undefined) this._setRoot(curr.right);
|
|
217
|
+
if (curr.right !== undefined && curr.right !== null) this._setRoot(curr.right);
|
|
268
218
|
} else {
|
|
269
219
|
const { familyPosition: fp } = curr;
|
|
270
220
|
if (fp === 'LEFT' || fp === 'ROOT_LEFT') {
|
|
@@ -382,6 +332,75 @@ export class AVLTreeMultiMap<
|
|
|
382
332
|
return cloned;
|
|
383
333
|
}
|
|
384
334
|
|
|
335
|
+
/**
|
|
336
|
+
* The `map` function in TypeScript overrides the default behavior to create a new AVLTreeMultiMap
|
|
337
|
+
* with modified entries based on a provided callback.
|
|
338
|
+
* @param callback - The `callback` parameter is a function that will be called for each entry in the
|
|
339
|
+
* AVLTreeMultiMap. It takes four arguments:
|
|
340
|
+
* @param [options] - The `options` parameter in the `override map` function is of type
|
|
341
|
+
* `AVLTreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional
|
|
342
|
+
* configuration options when creating a new `AVLTreeMultiMap` instance within the `map` function.
|
|
343
|
+
* These options
|
|
344
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
345
|
+
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
346
|
+
* (value of `this`) for the callback function. This can be useful when you want to access properties
|
|
347
|
+
* or
|
|
348
|
+
* @returns The `map` method is returning a new `AVLTreeMultiMap` instance with the entries
|
|
349
|
+
* transformed by the provided `callback` function. Each entry in the original tree is passed to the
|
|
350
|
+
* `callback` function along with the index and the original tree itself. The transformed entries are
|
|
351
|
+
* then added to the new `AVLTreeMultiMap` instance, which is returned at the end.
|
|
352
|
+
*/
|
|
353
|
+
override map<MK, MV, MR>(
|
|
354
|
+
callback: EntryCallback<K, V | undefined, [MK, MV]>,
|
|
355
|
+
options?: AVLTreeMultiMapOptions<MK, MV, MR>,
|
|
356
|
+
thisArg?: any
|
|
357
|
+
): AVLTreeMultiMap<MK, MV, MR> {
|
|
358
|
+
const newTree = new AVLTreeMultiMap<MK, MV, MR>([], options);
|
|
359
|
+
let index = 0;
|
|
360
|
+
for (const [key, value] of this) {
|
|
361
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
362
|
+
}
|
|
363
|
+
return newTree;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
|
|
368
|
+
* a node object.
|
|
369
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
370
|
+
* `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
371
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
372
|
+
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
373
|
+
* value is provided, it will default to `undefined`.
|
|
374
|
+
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
375
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
376
|
+
* @returns either a NODE object or undefined.
|
|
377
|
+
*/
|
|
378
|
+
protected override _keyValueNodeEntryRawToNodeAndValue(
|
|
379
|
+
keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R,
|
|
380
|
+
value?: V,
|
|
381
|
+
count = 1
|
|
382
|
+
): [NODE | undefined, V | undefined] {
|
|
383
|
+
if (keyNodeEntryOrRaw === undefined || keyNodeEntryOrRaw === null) return [undefined, undefined];
|
|
384
|
+
if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
|
|
385
|
+
|
|
386
|
+
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
387
|
+
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
388
|
+
if (key === undefined || key === null) return [undefined, undefined];
|
|
389
|
+
const finalValue = value ?? entryValue;
|
|
390
|
+
return [this.createNode(key, finalValue, count), finalValue];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
394
|
+
const [key, entryValue] = this._toEntryFn!(keyNodeEntryOrRaw);
|
|
395
|
+
const finalValue = value ?? entryValue;
|
|
396
|
+
if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
|
|
400
|
+
|
|
401
|
+
return [undefined, undefined];
|
|
402
|
+
}
|
|
403
|
+
|
|
385
404
|
/**
|
|
386
405
|
* Time Complexity: O(1)
|
|
387
406
|
* Space Complexity: O(1)
|