max-priority-queue-typed 2.4.4 → 2.5.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/README.md +63 -0
- package/dist/cjs/index.cjs +403 -98
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +402 -97
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +403 -99
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +402 -98
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +23 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +128 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +210 -164
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +439 -78
- package/dist/types/data-structures/binary-tree/bst.d.ts +311 -28
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +217 -31
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +218 -152
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1281 -5
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1087 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +858 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1133 -5
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +220 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +218 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +230 -77
- package/dist/types/data-structures/heap/heap.d.ts +287 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +286 -44
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +278 -65
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +415 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +331 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +313 -66
- package/dist/types/data-structures/queue/queue.d.ts +211 -42
- package/dist/types/data-structures/stack/stack.d.ts +174 -32
- package/dist/types/data-structures/trie/trie.d.ts +213 -43
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/types/types/data-structures/queue/deque.d.ts +6 -0
- package/dist/umd/max-priority-queue-typed.js +400 -95
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js +1 -1
- package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +60 -0
- package/src/common/index.ts +2 -0
- package/src/data-structures/base/iterable-element-base.ts +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +134 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +303 -247
- package/src/data-structures/binary-tree/binary-tree.ts +542 -121
- package/src/data-structures/binary-tree/bst.ts +346 -37
- package/src/data-structures/binary-tree/red-black-tree.ts +309 -96
- package/src/data-structures/binary-tree/segment-tree.ts +372 -248
- package/src/data-structures/binary-tree/tree-map.ts +1292 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +1098 -215
- package/src/data-structures/binary-tree/tree-multi-set.ts +863 -69
- package/src/data-structures/binary-tree/tree-set.ts +1143 -15
- package/src/data-structures/graph/abstract-graph.ts +106 -1
- package/src/data-structures/graph/directed-graph.ts +223 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +299 -59
- package/src/data-structures/hash/hash-map.ts +243 -79
- package/src/data-structures/heap/heap.ts +291 -102
- package/src/data-structures/heap/max-heap.ts +48 -3
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +286 -44
- package/src/data-structures/linked-list/singly-linked-list.ts +278 -65
- package/src/data-structures/linked-list/skip-linked-list.ts +689 -90
- package/src/data-structures/matrix/matrix.ts +425 -22
- package/src/data-structures/priority-queue/max-priority-queue.ts +59 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +343 -68
- package/src/data-structures/queue/queue.ts +211 -42
- package/src/data-structures/stack/stack.ts +174 -32
- package/src/data-structures/trie/trie.ts +215 -44
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
- package/src/types/data-structures/queue/deque.ts +7 -0
- package/src/utils/utils.ts +4 -2
|
@@ -8,14 +8,6 @@
|
|
|
8
8
|
import type { Comparator, TreeMultiMapOptions } from '../../types';
|
|
9
9
|
import { Range } from '../../common';
|
|
10
10
|
import { RedBlackTreeNode } from './red-black-tree';
|
|
11
|
-
/**
|
|
12
|
-
* Node type used by TreeMultiMap (alias to RedBlackTreeNode for backward compatibility).
|
|
13
|
-
*
|
|
14
|
-
* @deprecated Direct node manipulation is discouraged. Use TreeMultiMap methods instead.
|
|
15
|
-
*/
|
|
16
|
-
export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode<K, V[]> {
|
|
17
|
-
constructor(key: K, value?: V[]);
|
|
18
|
-
}
|
|
19
11
|
/**
|
|
20
12
|
* TreeMultiMap (ordered MultiMap) — key → bucket (Array of values).
|
|
21
13
|
*
|
|
@@ -25,169 +17,10 @@ export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode
|
|
|
25
17
|
* - Default iteration yields bucket entries: `[K, V[]]`.
|
|
26
18
|
* - Navigable operations (`first/last/ceiling/...`) return entry tuples like TreeMap.
|
|
27
19
|
* @example
|
|
28
|
-
* //
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* level: number;
|
|
33
|
-
* };
|
|
34
|
-
*
|
|
35
|
-
* type Player = {
|
|
36
|
-
* name: string;
|
|
37
|
-
* score: number;
|
|
38
|
-
* equipments: Equipment[];
|
|
39
|
-
* };
|
|
40
|
-
*
|
|
41
|
-
* // Mock player data with their scores and equipment
|
|
42
|
-
* const players: Player[] = [
|
|
43
|
-
* {
|
|
44
|
-
* name: 'DragonSlayer',
|
|
45
|
-
* score: 8750,
|
|
46
|
-
* equipments: [
|
|
47
|
-
* { name: 'AWM', quality: 'legendary', level: 85 },
|
|
48
|
-
* { name: 'Level 3 Helmet', quality: 'epic', level: 80 },
|
|
49
|
-
* { name: 'Extended Quickdraw Mag', quality: 'rare', level: 75 },
|
|
50
|
-
* { name: 'Compensator', quality: 'epic', level: 78 },
|
|
51
|
-
* { name: 'Vertical Grip', quality: 'rare', level: 72 }
|
|
52
|
-
* ]
|
|
53
|
-
* },
|
|
54
|
-
* {
|
|
55
|
-
* name: 'ShadowNinja',
|
|
56
|
-
* score: 7200,
|
|
57
|
-
* equipments: [
|
|
58
|
-
* { name: 'M416', quality: 'epic', level: 75 },
|
|
59
|
-
* { name: 'Ghillie Suit', quality: 'rare', level: 70 },
|
|
60
|
-
* { name: 'Red Dot Sight', quality: 'common', level: 65 },
|
|
61
|
-
* { name: 'Extended QuickDraw Mag', quality: 'rare', level: 68 }
|
|
62
|
-
* ]
|
|
63
|
-
* },
|
|
64
|
-
* {
|
|
65
|
-
* name: 'RuneMaster',
|
|
66
|
-
* score: 9100,
|
|
67
|
-
* equipments: [
|
|
68
|
-
* { name: 'KAR98K', quality: 'legendary', level: 90 },
|
|
69
|
-
* { name: 'Level 3 Vest', quality: 'legendary', level: 85 },
|
|
70
|
-
* { name: 'Holographic Sight', quality: 'epic', level: 82 },
|
|
71
|
-
* { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
72
|
-
* { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
|
|
73
|
-
* ]
|
|
74
|
-
* },
|
|
75
|
-
* {
|
|
76
|
-
* name: 'BattleKing',
|
|
77
|
-
* score: 8500,
|
|
78
|
-
* equipments: [
|
|
79
|
-
* { name: 'AUG', quality: 'epic', level: 82 },
|
|
80
|
-
* { name: 'Red Dot Sight', quality: 'rare', level: 75 },
|
|
81
|
-
* { name: 'Extended Mag', quality: 'common', level: 70 },
|
|
82
|
-
* { name: 'Tactical Stock', quality: 'rare', level: 76 }
|
|
83
|
-
* ]
|
|
84
|
-
* },
|
|
85
|
-
* {
|
|
86
|
-
* name: 'SniperElite',
|
|
87
|
-
* score: 7800,
|
|
88
|
-
* equipments: [
|
|
89
|
-
* { name: 'M24', quality: 'legendary', level: 88 },
|
|
90
|
-
* { name: 'Compensator', quality: 'epic', level: 80 },
|
|
91
|
-
* { name: 'Scope 8x', quality: 'legendary', level: 85 },
|
|
92
|
-
* { name: 'Level 2 Helmet', quality: 'rare', level: 75 }
|
|
93
|
-
* ]
|
|
94
|
-
* },
|
|
95
|
-
* {
|
|
96
|
-
* name: 'RushMaster',
|
|
97
|
-
* score: 7500,
|
|
98
|
-
* equipments: [
|
|
99
|
-
* { name: 'Vector', quality: 'rare', level: 72 },
|
|
100
|
-
* { name: 'Level 2 Helmet', quality: 'common', level: 65 },
|
|
101
|
-
* { name: 'Quickdraw Mag', quality: 'common', level: 60 },
|
|
102
|
-
* { name: 'Laser Sight', quality: 'rare', level: 68 }
|
|
103
|
-
* ]
|
|
104
|
-
* },
|
|
105
|
-
* {
|
|
106
|
-
* name: 'GhostWarrior',
|
|
107
|
-
* score: 8200,
|
|
108
|
-
* equipments: [
|
|
109
|
-
* { name: 'SCAR-L', quality: 'epic', level: 78 },
|
|
110
|
-
* { name: 'Extended Quickdraw Mag', quality: 'rare', level: 70 },
|
|
111
|
-
* { name: 'Holographic Sight', quality: 'epic', level: 75 },
|
|
112
|
-
* { name: 'Suppressor', quality: 'rare', level: 72 },
|
|
113
|
-
* { name: 'Vertical Grip', quality: 'common', level: 65 }
|
|
114
|
-
* ]
|
|
115
|
-
* },
|
|
116
|
-
* {
|
|
117
|
-
* name: 'DeathDealer',
|
|
118
|
-
* score: 7300,
|
|
119
|
-
* equipments: [
|
|
120
|
-
* { name: 'SKS', quality: 'epic', level: 76 },
|
|
121
|
-
* { name: 'Holographic Sight', quality: 'rare', level: 68 },
|
|
122
|
-
* { name: 'Extended Mag', quality: 'common', level: 65 }
|
|
123
|
-
* ]
|
|
124
|
-
* },
|
|
125
|
-
* {
|
|
126
|
-
* name: 'StormRider',
|
|
127
|
-
* score: 8900,
|
|
128
|
-
* equipments: [
|
|
129
|
-
* { name: 'MK14', quality: 'legendary', level: 92 },
|
|
130
|
-
* { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
|
|
131
|
-
* { name: 'Scope 8x', quality: 'epic', level: 80 },
|
|
132
|
-
* { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
133
|
-
* { name: 'Tactical Stock', quality: 'rare', level: 75 }
|
|
134
|
-
* ]
|
|
135
|
-
* },
|
|
136
|
-
* {
|
|
137
|
-
* name: 'CombatLegend',
|
|
138
|
-
* score: 7600,
|
|
139
|
-
* equipments: [
|
|
140
|
-
* { name: 'UMP45', quality: 'rare', level: 74 },
|
|
141
|
-
* { name: 'Level 2 Vest', quality: 'common', level: 67 },
|
|
142
|
-
* { name: 'Red Dot Sight', quality: 'common', level: 62 },
|
|
143
|
-
* { name: 'Extended Mag', quality: 'rare', level: 70 }
|
|
144
|
-
* ]
|
|
145
|
-
* }
|
|
146
|
-
* ];
|
|
147
|
-
*
|
|
148
|
-
* // Create a TreeMultiMap for player rankings
|
|
149
|
-
* const playerRankings = new TreeMultiMap<number, Equipment, Player>(players, {
|
|
150
|
-
* toEntryFn: ({ score, equipments }) => [score, equipments],
|
|
151
|
-
* isMapMode: false
|
|
152
|
-
* });
|
|
153
|
-
*
|
|
154
|
-
* const topPlayersEquipments = playerRankings.rangeSearch([8900, 10000], node => playerRankings.get(node.key));
|
|
155
|
-
* console.log(topPlayersEquipments); // [
|
|
156
|
-
* // [
|
|
157
|
-
* // {
|
|
158
|
-
* // name: 'MK14',
|
|
159
|
-
* // quality: 'legendary',
|
|
160
|
-
* // level: 92
|
|
161
|
-
* // },
|
|
162
|
-
* // { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
|
|
163
|
-
* // {
|
|
164
|
-
* // name: 'Scope 8x',
|
|
165
|
-
* // quality: 'epic',
|
|
166
|
-
* // level: 80
|
|
167
|
-
* // },
|
|
168
|
-
* // { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
169
|
-
* // {
|
|
170
|
-
* // name: 'Tactical Stock',
|
|
171
|
-
* // quality: 'rare',
|
|
172
|
-
* // level: 75
|
|
173
|
-
* // }
|
|
174
|
-
* // ],
|
|
175
|
-
* // [
|
|
176
|
-
* // { name: 'KAR98K', quality: 'legendary', level: 90 },
|
|
177
|
-
* // {
|
|
178
|
-
* // name: 'Level 3 Vest',
|
|
179
|
-
* // quality: 'legendary',
|
|
180
|
-
* // level: 85
|
|
181
|
-
* // },
|
|
182
|
-
* // { name: 'Holographic Sight', quality: 'epic', level: 82 },
|
|
183
|
-
* // {
|
|
184
|
-
* // name: 'Suppressor',
|
|
185
|
-
* // quality: 'legendary',
|
|
186
|
-
* // level: 88
|
|
187
|
-
* // },
|
|
188
|
-
* // { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
|
|
189
|
-
* // ]
|
|
190
|
-
* // ];
|
|
20
|
+
* // Morris traversal (O(1) space)
|
|
21
|
+
* const tmm = new TreeMultiMap<number>([5, 3, 7]);
|
|
22
|
+
* const result = tmm.morris(n => n.key, 'IN');
|
|
23
|
+
* console.log(result.length); // > 0;
|
|
191
24
|
*/
|
|
192
25
|
export declare class TreeMultiMap<K = any, V = any, R = any> implements Iterable<[K, V[]]> {
|
|
193
26
|
#private;
|
|
@@ -218,62 +51,461 @@ export declare class TreeMultiMap<K = any, V = any, R = any> implements Iterable
|
|
|
218
51
|
/**
|
|
219
52
|
* Whether the map is empty.
|
|
220
53
|
* @remarks Time O(1), Space O(1)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
* @example
|
|
93
|
+
* // Check if empty
|
|
94
|
+
* console.log(new TreeMultiMap().isEmpty()); // true;
|
|
221
95
|
*/
|
|
222
96
|
isEmpty(): boolean;
|
|
223
97
|
/**
|
|
224
98
|
* Removes all entries from the map.
|
|
225
99
|
* @remarks Time O(1), Space O(1)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
* @example
|
|
139
|
+
* // Remove all entries
|
|
140
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
141
|
+
* mm.add(1, 'a');
|
|
142
|
+
* mm.clear();
|
|
143
|
+
* console.log(mm.isEmpty()); // true;
|
|
226
144
|
*/
|
|
227
145
|
clear(): void;
|
|
228
146
|
/**
|
|
229
147
|
* Bucket length for a key (missing => 0).
|
|
230
148
|
* @remarks Time O(log n), Space O(1)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
* @example
|
|
152
|
+
* // Count values for key
|
|
153
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
154
|
+
* mm.add(1, 'a');
|
|
155
|
+
* mm.add(1, 'b');
|
|
156
|
+
* console.log(mm.count(1)); // 2;
|
|
231
157
|
*/
|
|
232
158
|
count(key: K): number;
|
|
233
159
|
/**
|
|
234
160
|
* Total number of values across all buckets (Σ bucket.length).
|
|
235
161
|
* @remarks Time O(n), Space O(1)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
* @example
|
|
165
|
+
* // Total number of values
|
|
166
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
167
|
+
* mm.add(1, 'a');
|
|
168
|
+
* mm.add(1, 'b');
|
|
169
|
+
* mm.add(2, 'c');
|
|
170
|
+
* console.log(mm.totalSize); // 3;
|
|
236
171
|
*/
|
|
237
172
|
get totalSize(): number;
|
|
238
173
|
/**
|
|
239
174
|
* Whether the map contains the given key.
|
|
240
175
|
* @remarks Time O(log n), Space O(1)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
* @example
|
|
229
|
+
* // Check key existence
|
|
230
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
231
|
+
* mm.add(1, 'a');
|
|
232
|
+
* console.log(mm.has(1)); // true;
|
|
233
|
+
* console.log(mm.has(2)); // false;
|
|
241
234
|
*/
|
|
242
235
|
has(key: K): boolean;
|
|
243
236
|
/**
|
|
244
237
|
* Live bucket reference (do not auto-delete key if bucket becomes empty via mutation).
|
|
245
238
|
* @remarks Time O(log n), Space O(1)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
* @example
|
|
292
|
+
* // Get values for key
|
|
293
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
294
|
+
* mm.add(1, 'a');
|
|
295
|
+
* mm.add(1, 'b');
|
|
296
|
+
* console.log(mm.get(1)); // ['a', 'b'];
|
|
246
297
|
*/
|
|
247
298
|
get(key: K): V[] | undefined;
|
|
248
299
|
/**
|
|
249
300
|
* Append a single value.
|
|
250
301
|
* @remarks Time O(log n), Space O(1)
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
* @example
|
|
335
|
+
* // Add key-value pair
|
|
336
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
337
|
+
* mm.add(1, 'a');
|
|
338
|
+
* mm.add(1, 'b');
|
|
339
|
+
* mm.add(2, 'c');
|
|
340
|
+
* console.log(mm.get(1)); // ['a', 'b'];
|
|
251
341
|
*/
|
|
252
342
|
add(key: K, value: V): boolean;
|
|
253
343
|
/**
|
|
254
344
|
* Alias for compatibility with existing TreeMultiMap semantics.
|
|
255
345
|
* @remarks Time O(log n), Space O(1) for single value; O(log n + m) for bucket append
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
* @example
|
|
397
|
+
* // Set values for key
|
|
398
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
399
|
+
* mm.set(1, 'a');
|
|
400
|
+
* mm.set(1, 'b');
|
|
401
|
+
* console.log(mm.get(1)); // ['a', 'b'];
|
|
256
402
|
*/
|
|
257
403
|
set(entry: [K | null | undefined, V[] | undefined] | K | null | undefined, value?: V): boolean;
|
|
258
404
|
set(key: K, value: V): boolean;
|
|
259
405
|
/**
|
|
260
406
|
* Deletes a key and its entire bucket.
|
|
261
407
|
* @remarks Time O(log n), Space O(1)
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
* @example
|
|
461
|
+
* // Remove key
|
|
462
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
463
|
+
* mm.add(1, 'a');
|
|
464
|
+
* mm.add(2, 'b');
|
|
465
|
+
* mm.delete(1);
|
|
466
|
+
* console.log(mm.has(1)); // false;
|
|
262
467
|
*/
|
|
263
468
|
delete(key: K): boolean;
|
|
264
469
|
/**
|
|
265
470
|
* Check if a specific value exists in a key's bucket.
|
|
266
471
|
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
* @example
|
|
475
|
+
* // Check specific key-value
|
|
476
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
477
|
+
* mm.add(1, 'a');
|
|
478
|
+
* console.log(mm.hasEntry(1, 'a')); // true;
|
|
479
|
+
* console.log(mm.hasEntry(1, 'z')); // false;
|
|
267
480
|
*/
|
|
268
481
|
hasEntry(key: K, value: V, eq?: (a: V, b: V) => boolean): boolean;
|
|
269
482
|
/**
|
|
270
483
|
* Delete a single occurrence of a value from a key's bucket.
|
|
271
484
|
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
* @example
|
|
488
|
+
* // Delete specific value
|
|
489
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
490
|
+
* mm.add(1, 'a');
|
|
491
|
+
* mm.add(1, 'b');
|
|
492
|
+
* mm.deleteValue(1, 'a');
|
|
493
|
+
* console.log(mm.get(1)); // ['b'];
|
|
272
494
|
*/
|
|
273
495
|
deleteValue(key: K, value: V, eq?: (a: V, b: V) => boolean): boolean;
|
|
274
496
|
/**
|
|
275
497
|
* Delete all occurrences of a value from a key's bucket.
|
|
276
498
|
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
* @example
|
|
502
|
+
* // Delete all matching values
|
|
503
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
504
|
+
* mm.add(1, 'a');
|
|
505
|
+
* mm.add(1, 'a');
|
|
506
|
+
* mm.add(1, 'b');
|
|
507
|
+
* const count = mm.deleteValues(1, 'a');
|
|
508
|
+
* console.log(count); // 2;
|
|
277
509
|
*/
|
|
278
510
|
deleteValues(key: K, value: V, eq?: (a: V, b: V) => boolean): number;
|
|
279
511
|
/**
|
|
@@ -284,136 +516,790 @@ export declare class TreeMultiMap<K = any, V = any, R = any> implements Iterable
|
|
|
284
516
|
/**
|
|
285
517
|
* Iterates over all keys.
|
|
286
518
|
* @remarks Time O(n), Space O(1)
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
* @example
|
|
558
|
+
* // Iterate keys
|
|
559
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
560
|
+
* mm.add(3, 'c');
|
|
561
|
+
* mm.add(1, 'a');
|
|
562
|
+
* console.log([...mm.keys()]); // [1, 3];
|
|
287
563
|
*/
|
|
288
564
|
keys(): IterableIterator<K>;
|
|
289
565
|
/**
|
|
290
566
|
* Iterates over all buckets.
|
|
291
567
|
* @remarks Time O(n), Space O(1)
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
* @example
|
|
607
|
+
* // Iterate value arrays
|
|
608
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
609
|
+
* mm.add(1, 'a');
|
|
610
|
+
* mm.add(1, 'b');
|
|
611
|
+
* console.log([...mm.values()]); // [['a', 'b']];
|
|
292
612
|
*/
|
|
293
613
|
values(): IterableIterator<V[]>;
|
|
294
614
|
/**
|
|
295
615
|
* Iterates over all entries for a specific key.
|
|
296
616
|
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
* @example
|
|
620
|
+
* // Get entries for key
|
|
621
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
622
|
+
* mm.add(1, 'a');
|
|
623
|
+
* mm.add(1, 'b');
|
|
624
|
+
* console.log([...mm.entriesOf(1)]); // [[1, 'a'], [1, 'b']];
|
|
297
625
|
*/
|
|
298
626
|
entriesOf(key: K): IterableIterator<[K, V]>;
|
|
299
627
|
/**
|
|
300
628
|
* Iterates over all values for a specific key.
|
|
301
629
|
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
* @example
|
|
633
|
+
* // Get flat values for key
|
|
634
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
635
|
+
* mm.add(1, 'a');
|
|
636
|
+
* mm.add(1, 'b');
|
|
637
|
+
* console.log([...mm.valuesOf(1)]); // ['a', 'b'];
|
|
302
638
|
*/
|
|
303
639
|
valuesOf(key: K): IterableIterator<V>;
|
|
304
640
|
/**
|
|
305
641
|
* Iterates over all [key, value] pairs (flattened from buckets).
|
|
306
642
|
* @remarks Time O(T), Space O(1) where T is totalSize
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
* @example
|
|
646
|
+
* // All key-value pairs flattened
|
|
647
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
648
|
+
* mm.add(1, 'a');
|
|
649
|
+
* mm.add(1, 'b');
|
|
650
|
+
* mm.add(2, 'c');
|
|
651
|
+
* console.log([...mm.flatEntries()]); // [[1, 'a'], [1, 'b'], [2, 'c']];
|
|
307
652
|
*/
|
|
308
653
|
flatEntries(): IterableIterator<[K, V]>;
|
|
309
654
|
/**
|
|
310
655
|
* Returns the entry with the smallest key.
|
|
311
656
|
* @remarks Time O(log n), Space O(1)
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
* @example
|
|
672
|
+
* // First entry
|
|
673
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
674
|
+
* mm.add(3, 'c');
|
|
675
|
+
* mm.add(1, 'a');
|
|
676
|
+
* console.log(mm.first()?.[0]); // 1;
|
|
315
677
|
*/
|
|
316
678
|
first(): [K, V[]] | undefined;
|
|
317
679
|
/**
|
|
318
680
|
* Returns the entry with the largest key.
|
|
319
681
|
* @remarks Time O(log n), Space O(1)
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
* @example
|
|
697
|
+
* // Last entry
|
|
698
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
699
|
+
* mm.add(1, 'a');
|
|
700
|
+
* mm.add(3, 'c');
|
|
701
|
+
* console.log(mm.last()?.[0]); // 3;
|
|
323
702
|
*/
|
|
324
703
|
last(): [K, V[]] | undefined;
|
|
325
704
|
/**
|
|
326
705
|
* Removes and returns the entry with the smallest key.
|
|
327
706
|
* @remarks Time O(log n), Space O(1)
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
* @example
|
|
711
|
+
* // Remove and return first
|
|
712
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
713
|
+
* mm.add(2, 'b');
|
|
714
|
+
* mm.add(1, 'a');
|
|
715
|
+
* const first = mm.pollFirst();
|
|
716
|
+
* console.log(first?.[0]); // 1;
|
|
717
|
+
* console.log(mm.has(1)); // false;
|
|
332
718
|
*/
|
|
333
719
|
pollFirst(): [K, V[]] | undefined;
|
|
334
720
|
/**
|
|
335
721
|
* Removes and returns the entry with the largest key.
|
|
336
722
|
* @remarks Time O(log n), Space O(1)
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
* @example
|
|
727
|
+
* // Remove and return last
|
|
728
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
729
|
+
* mm.add(1, 'a');
|
|
730
|
+
* mm.add(3, 'c');
|
|
731
|
+
* const last = mm.pollLast();
|
|
732
|
+
* console.log(last?.[0]); // 3;
|
|
341
733
|
*/
|
|
342
734
|
pollLast(): [K, V[]] | undefined;
|
|
343
735
|
/**
|
|
344
736
|
* Returns the entry with the smallest key >= given key.
|
|
345
737
|
* @remarks Time O(log n), Space O(1)
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
* @example
|
|
780
|
+
* // Least key ≥ target
|
|
781
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
782
|
+
* mm.add(10, 'a');
|
|
783
|
+
* mm.add(20, 'b');
|
|
784
|
+
* mm.add(30, 'c');
|
|
785
|
+
* console.log(mm.ceiling(15)?.[0]); // 20;
|
|
350
786
|
*/
|
|
351
787
|
ceiling(key: K): [K, V[]] | undefined;
|
|
352
788
|
/**
|
|
353
789
|
* Returns the entry with the largest key <= given key.
|
|
354
790
|
* @remarks Time O(log n), Space O(1)
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
* @example
|
|
833
|
+
* // Greatest key ≤ target
|
|
834
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
835
|
+
* mm.add(10, 'a');
|
|
836
|
+
* mm.add(20, 'b');
|
|
837
|
+
* mm.add(30, 'c');
|
|
838
|
+
* console.log(mm.floor(25)?.[0]); // 20;
|
|
359
839
|
*/
|
|
360
840
|
floor(key: K): [K, V[]] | undefined;
|
|
361
841
|
/**
|
|
362
842
|
* Returns the entry with the smallest key > given key.
|
|
363
843
|
* @remarks Time O(log n), Space O(1)
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
* @example
|
|
875
|
+
* // Least key > target
|
|
876
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
877
|
+
* mm.add(10, 'a');
|
|
878
|
+
* mm.add(20, 'b');
|
|
879
|
+
* console.log(mm.higher(10)?.[0]); // 20;
|
|
368
880
|
*/
|
|
369
881
|
higher(key: K): [K, V[]] | undefined;
|
|
370
882
|
/**
|
|
371
883
|
* Returns the entry with the largest key < given key.
|
|
372
884
|
* @remarks Time O(log n), Space O(1)
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
* @example
|
|
916
|
+
* // Greatest key < target
|
|
917
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
918
|
+
* mm.add(10, 'a');
|
|
919
|
+
* mm.add(20, 'b');
|
|
920
|
+
* console.log(mm.lower(20)?.[0]); // 10;
|
|
377
921
|
*/
|
|
378
922
|
lower(key: K): [K, V[]] | undefined;
|
|
379
923
|
/**
|
|
380
924
|
* Prints the internal tree structure (for debugging).
|
|
381
925
|
* @remarks Time O(n), Space O(n)
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
* @example
|
|
965
|
+
* // Display tree
|
|
966
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
967
|
+
* mm.add(1, 'a');
|
|
968
|
+
* expect(() => mm.print()).not.toThrow();
|
|
382
969
|
*/
|
|
383
970
|
print(): void;
|
|
384
971
|
/**
|
|
385
972
|
* Executes a callback for each entry.
|
|
386
973
|
* @remarks Time O(n), Space O(1)
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
* @example
|
|
1013
|
+
* // Iterate entries
|
|
1014
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
1015
|
+
* mm.add(1, 'a');
|
|
1016
|
+
* mm.add(2, 'b');
|
|
1017
|
+
* const keys: number[] = [];
|
|
1018
|
+
* mm.forEach((v, k) => keys.push(k));
|
|
1019
|
+
* console.log(keys); // [1, 2];
|
|
387
1020
|
*/
|
|
388
1021
|
forEach(callback: (value: V[], key: K, map: this) => void): void;
|
|
389
1022
|
/**
|
|
390
1023
|
* Creates a new map with entries that pass the predicate.
|
|
391
1024
|
* @remarks Time O(n), Space O(n)
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
* @example
|
|
1064
|
+
* // Filter entries
|
|
1065
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
1066
|
+
* mm.add(1, 'a');
|
|
1067
|
+
* mm.add(2, 'b');
|
|
1068
|
+
* mm.add(3, 'c');
|
|
1069
|
+
* const filtered = mm.filter((v, k) => k > 1);
|
|
1070
|
+
* console.log([...filtered.keys()]); // [2, 3];
|
|
392
1071
|
*/
|
|
393
1072
|
filter(predicate: (value: V[], key: K, map: this) => boolean): TreeMultiMap<K, V, R>;
|
|
394
1073
|
/**
|
|
395
1074
|
* Creates a new map by transforming each entry.
|
|
396
1075
|
* @remarks Time O(n log n), Space O(n)
|
|
1076
|
+
|
|
1077
|
+
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
* @example
|
|
1115
|
+
* // Transform values
|
|
1116
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
1117
|
+
* mm.add(1, 'a');
|
|
1118
|
+
* const mapped = mm.map((v, k) => [k, v.map(s => s.toUpperCase())] as [number, string[]]);
|
|
1119
|
+
* console.log(mapped.get(1)); // ['A'];
|
|
397
1120
|
*/
|
|
398
1121
|
map<V2>(mapper: (value: V[], key: K, map: this) => [K, V2[]]): TreeMultiMap<K, V2, R>;
|
|
399
1122
|
/**
|
|
400
1123
|
* Reduces all entries to a single value.
|
|
401
1124
|
* @remarks Time O(n), Space O(1)
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
|
|
1150
|
+
|
|
1151
|
+
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
|
|
1163
|
+
* @example
|
|
1164
|
+
* // Aggregate
|
|
1165
|
+
* const mm = new TreeMultiMap<number, number>();
|
|
1166
|
+
* mm.add(1, 10);
|
|
1167
|
+
* mm.add(2, 20);
|
|
1168
|
+
* const sum = mm.reduce((acc, v) => acc + v.reduce((a, b) => a + b, 0), 0);
|
|
1169
|
+
* console.log(sum); // 30;
|
|
402
1170
|
*/
|
|
403
1171
|
reduce<U>(callback: (accumulator: U, value: V[], key: K, map: this) => U, initialValue: U): U;
|
|
404
1172
|
/**
|
|
405
1173
|
* Sets multiple entries at once.
|
|
406
1174
|
* @remarks Time O(m log n), Space O(m) where m is input size
|
|
1175
|
+
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
* @example
|
|
1206
|
+
* // Set multiple entries
|
|
1207
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
1208
|
+
* mm.setMany([[1, ['a']], [2, ['b']]]);
|
|
1209
|
+
* console.log(mm.size); // 2;
|
|
407
1210
|
*/
|
|
408
1211
|
setMany(keysNodesEntriesOrRaws: Iterable<K | [K | null | undefined, V[] | undefined]>): boolean[];
|
|
409
1212
|
/**
|
|
410
1213
|
* Searches for entries within a key range.
|
|
411
1214
|
* @remarks Time O(log n + k), Space O(k) where k is result size
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
* @example
|
|
1246
|
+
* // Find keys in range
|
|
1247
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
1248
|
+
* mm.add(10, 'a');
|
|
1249
|
+
* mm.add(20, 'b');
|
|
1250
|
+
* mm.add(30, 'c');
|
|
1251
|
+
* const result = mm.rangeSearch([15, 25]);
|
|
1252
|
+
* console.log(result.length); // 1;
|
|
412
1253
|
*/
|
|
413
1254
|
rangeSearch<C extends (node: RedBlackTreeNode<K, V[]>) => unknown>(range: Range<K> | [K, K], callback?: C): ReturnType<C>[];
|
|
414
1255
|
/**
|
|
415
1256
|
* Creates a shallow clone of this map.
|
|
416
1257
|
* @remarks Time O(n log n), Space O(n)
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
|
|
1272
|
+
|
|
1273
|
+
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
|
|
1285
|
+
|
|
1286
|
+
|
|
1287
|
+
|
|
1288
|
+
|
|
1289
|
+
|
|
1290
|
+
|
|
1291
|
+
|
|
1292
|
+
|
|
1293
|
+
|
|
1294
|
+
|
|
1295
|
+
|
|
1296
|
+
* @example
|
|
1297
|
+
* // Deep clone
|
|
1298
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
1299
|
+
* mm.add(1, 'a');
|
|
1300
|
+
* const copy = mm.clone();
|
|
1301
|
+
* copy.delete(1);
|
|
1302
|
+
* console.log(mm.has(1)); // true;
|
|
417
1303
|
*/
|
|
418
1304
|
clone(): TreeMultiMap<K, V, R>;
|
|
419
1305
|
/**
|