elseware-nodejs 1.0.10 → 1.2.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 +103 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1713 -1
- package/dist/index.d.ts +1713 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +7 -2
package/dist/index.d.cts
CHANGED
|
@@ -57,6 +57,26 @@ declare class APIResponse {
|
|
|
57
57
|
|
|
58
58
|
declare const asyncHandler: (fn: (req: Request, res: Response, next: NextFunction) => Promise<void>) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
59
59
|
|
|
60
|
+
interface AzureBlobConfig {
|
|
61
|
+
connectionString: string;
|
|
62
|
+
accountName: string;
|
|
63
|
+
accountKey: string;
|
|
64
|
+
containerName: string;
|
|
65
|
+
}
|
|
66
|
+
type ProgressCallback = (percentage: string) => void;
|
|
67
|
+
declare class AzureBlobService {
|
|
68
|
+
private containerName;
|
|
69
|
+
private blobServiceClient;
|
|
70
|
+
private containerClient;
|
|
71
|
+
private sharedKeyCredential;
|
|
72
|
+
constructor(config: AzureBlobConfig);
|
|
73
|
+
uploadFile(localPath: string, blobName: string, onProgress?: ProgressCallback): Promise<string>;
|
|
74
|
+
downloadFile(blobName: string, downloadPath: string, onProgress?: ProgressCallback): Promise<void>;
|
|
75
|
+
deleteFile(blobName: string): Promise<boolean>;
|
|
76
|
+
listFiles(prefix?: string): Promise<string[]>;
|
|
77
|
+
blobExists(blobName: string): Promise<boolean>;
|
|
78
|
+
}
|
|
79
|
+
|
|
60
80
|
interface DatabaseConfig {
|
|
61
81
|
uri: string;
|
|
62
82
|
}
|
|
@@ -94,6 +114,1698 @@ declare function createAllowedOrigins(options?: AllowedOriginsOptions): string[]
|
|
|
94
114
|
|
|
95
115
|
declare function createCorsOptions(allowedOrigins: string[]): CorsOptions;
|
|
96
116
|
|
|
117
|
+
/**
|
|
118
|
+
* CircularArray (Ring Buffer)
|
|
119
|
+
* ---------------------------
|
|
120
|
+
* A fixed-capacity circular array implementation.
|
|
121
|
+
*
|
|
122
|
+
* Characteristics:
|
|
123
|
+
* - Fixed capacity
|
|
124
|
+
* - O(1) enqueue / dequeue
|
|
125
|
+
* - Wrap-around indexing
|
|
126
|
+
* - Bounds-safe
|
|
127
|
+
* - Generic
|
|
128
|
+
* - Iterable (logical order)
|
|
129
|
+
*
|
|
130
|
+
* Use cases:
|
|
131
|
+
* - Queues
|
|
132
|
+
* - Circular buffers
|
|
133
|
+
* - Sliding windows
|
|
134
|
+
* - Game event buffers
|
|
135
|
+
*/
|
|
136
|
+
declare class CircularArray<T> implements Iterable<T> {
|
|
137
|
+
private readonly capacity;
|
|
138
|
+
private data;
|
|
139
|
+
private head;
|
|
140
|
+
private tail;
|
|
141
|
+
private length;
|
|
142
|
+
constructor(capacity: number);
|
|
143
|
+
size(): number;
|
|
144
|
+
getCapacity(): number;
|
|
145
|
+
isEmpty(): boolean;
|
|
146
|
+
isFull(): boolean;
|
|
147
|
+
enqueue(value: T): void;
|
|
148
|
+
dequeue(): T | undefined;
|
|
149
|
+
peek(): T | undefined;
|
|
150
|
+
clear(): void;
|
|
151
|
+
toArray(): T[];
|
|
152
|
+
[Symbol.iterator](): Iterator<T>;
|
|
153
|
+
toString(): string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* DynamicArray
|
|
158
|
+
* ------------
|
|
159
|
+
* A resizable array implementation similar to ArrayList / Vector.
|
|
160
|
+
*
|
|
161
|
+
* Characteristics:
|
|
162
|
+
* - Automatically resizes when capacity is exceeded
|
|
163
|
+
* - O(1) amortized append
|
|
164
|
+
* - O(1) access by index
|
|
165
|
+
* - Bounds-safe
|
|
166
|
+
* - Generic
|
|
167
|
+
* - Iterable
|
|
168
|
+
*
|
|
169
|
+
* Use cases:
|
|
170
|
+
* - General-purpose collections
|
|
171
|
+
* - Algorithm implementations
|
|
172
|
+
* - Game entity lists
|
|
173
|
+
* - Backend buffers
|
|
174
|
+
*/
|
|
175
|
+
declare class DynamicArray<T> implements Iterable<T> {
|
|
176
|
+
private data;
|
|
177
|
+
private capacity;
|
|
178
|
+
private length;
|
|
179
|
+
constructor(initialCapacity?: number);
|
|
180
|
+
size(): number;
|
|
181
|
+
getCapacity(): number;
|
|
182
|
+
private checkBounds;
|
|
183
|
+
private resize;
|
|
184
|
+
get(index: number): T | undefined;
|
|
185
|
+
set(index: number, value: T): void;
|
|
186
|
+
push(value: T): void;
|
|
187
|
+
pop(): T | undefined;
|
|
188
|
+
insert(index: number, value: T): void;
|
|
189
|
+
removeAt(index: number): T | undefined;
|
|
190
|
+
contains(value: T): boolean;
|
|
191
|
+
toArray(): T[];
|
|
192
|
+
clear(): void;
|
|
193
|
+
[Symbol.iterator](): Iterator<T>;
|
|
194
|
+
toString(): string;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* StaticArray
|
|
199
|
+
* -----------
|
|
200
|
+
* A fixed-size array implementation.
|
|
201
|
+
*
|
|
202
|
+
* Characteristics:
|
|
203
|
+
* - Size is defined at creation time and cannot be changed
|
|
204
|
+
* - O(1) access by index
|
|
205
|
+
* - Bounds-safe
|
|
206
|
+
* - Generic
|
|
207
|
+
* - Iterable
|
|
208
|
+
*
|
|
209
|
+
* Use cases:
|
|
210
|
+
* - Fixed buffers
|
|
211
|
+
* - Memory-sensitive systems
|
|
212
|
+
* - Game grids / tiles
|
|
213
|
+
* - Algorithm demonstrations
|
|
214
|
+
*/
|
|
215
|
+
declare class StaticArray<T> implements Iterable<T> {
|
|
216
|
+
private readonly capacity;
|
|
217
|
+
private readonly data;
|
|
218
|
+
/**
|
|
219
|
+
* Creates a static array with a fixed size.
|
|
220
|
+
* @param size Total capacity of the array
|
|
221
|
+
* @param initialValue Optional default value for all indices
|
|
222
|
+
*/
|
|
223
|
+
constructor(size: number, initialValue?: T);
|
|
224
|
+
size(): number;
|
|
225
|
+
private checkBounds;
|
|
226
|
+
get(index: number): T | undefined;
|
|
227
|
+
set(index: number, value: T): void;
|
|
228
|
+
fill(value: T): void;
|
|
229
|
+
clear(): void;
|
|
230
|
+
contains(value: T): boolean;
|
|
231
|
+
indexOf(value: T): number;
|
|
232
|
+
toArray(): (T | undefined)[];
|
|
233
|
+
[Symbol.iterator](): Iterator<T>;
|
|
234
|
+
forEach(callback: (value: T | undefined, index: number) => void): void;
|
|
235
|
+
clone(): StaticArray<T>;
|
|
236
|
+
toString(): string;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* AdjacencyList
|
|
241
|
+
* -------------
|
|
242
|
+
* A generic adjacency list data structure.
|
|
243
|
+
*
|
|
244
|
+
* Characteristics:
|
|
245
|
+
* - Stores neighbors for each vertex
|
|
246
|
+
* - Supports weighted or unweighted edges
|
|
247
|
+
* - No traversal or algorithms included
|
|
248
|
+
*
|
|
249
|
+
* Intended to be used as a building block
|
|
250
|
+
* for Graph / DirectedGraph implementations.
|
|
251
|
+
*/
|
|
252
|
+
interface AdjacentEdge<T = string> {
|
|
253
|
+
to: T;
|
|
254
|
+
weight?: number;
|
|
255
|
+
}
|
|
256
|
+
declare class AdjacencyList<T = string> {
|
|
257
|
+
private list;
|
|
258
|
+
addVertex(vertex: T): void;
|
|
259
|
+
removeVertex(vertex: T): void;
|
|
260
|
+
hasVertex(vertex: T): boolean;
|
|
261
|
+
getVertices(): T[];
|
|
262
|
+
addEdge(from: T, to: T, weight?: number): void;
|
|
263
|
+
removeEdge(from: T, to: T): void;
|
|
264
|
+
hasEdge(from: T, to: T): boolean;
|
|
265
|
+
getEdges(vertex: T): AdjacentEdge<T>[];
|
|
266
|
+
clear(): void;
|
|
267
|
+
size(): number;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* AdjacencyMatrix
|
|
272
|
+
* ---------------
|
|
273
|
+
* Matrix-based graph representation.
|
|
274
|
+
*
|
|
275
|
+
* Characteristics:
|
|
276
|
+
* - Directed or Undirected
|
|
277
|
+
* - Weighted or Unweighted
|
|
278
|
+
* - Dense graph friendly
|
|
279
|
+
* - No traversal or algorithms included
|
|
280
|
+
*
|
|
281
|
+
* Internally maps vertices to indices.
|
|
282
|
+
*/
|
|
283
|
+
declare class AdjacencyMatrix<T = string> {
|
|
284
|
+
private readonly directed;
|
|
285
|
+
private matrix;
|
|
286
|
+
private vertices;
|
|
287
|
+
private indexMap;
|
|
288
|
+
constructor(directed?: boolean);
|
|
289
|
+
addVertex(vertex: T): void;
|
|
290
|
+
removeVertex(vertex: T): void;
|
|
291
|
+
hasVertex(vertex: T): boolean;
|
|
292
|
+
getVertices(): T[];
|
|
293
|
+
addEdge(from: T, to: T, weight?: number): void;
|
|
294
|
+
removeEdge(from: T, to: T): void;
|
|
295
|
+
hasEdge(from: T, to: T): boolean;
|
|
296
|
+
getWeight(from: T, to: T): number | undefined;
|
|
297
|
+
size(): number;
|
|
298
|
+
clear(): void;
|
|
299
|
+
isDirected(): boolean;
|
|
300
|
+
/**
|
|
301
|
+
* Returns a copy of the adjacency matrix
|
|
302
|
+
*/
|
|
303
|
+
toMatrix(): number[][];
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* DirectedGraph
|
|
308
|
+
* -------------
|
|
309
|
+
* Adjacency-list based directed graph data structure.
|
|
310
|
+
*
|
|
311
|
+
* Characteristics:
|
|
312
|
+
* - Directed edges only
|
|
313
|
+
* - Weighted or unweighted edges (stored, not processed)
|
|
314
|
+
* - Includes general traversals: BFS & DFS
|
|
315
|
+
*
|
|
316
|
+
* Advanced algorithms should live separately.
|
|
317
|
+
*/
|
|
318
|
+
interface DirectedEdge<T = string> {
|
|
319
|
+
to: T;
|
|
320
|
+
weight?: number;
|
|
321
|
+
}
|
|
322
|
+
declare class DirectedGraph<T = string> {
|
|
323
|
+
private adjList;
|
|
324
|
+
addVertex(vertex: T): void;
|
|
325
|
+
removeVertex(vertex: T): void;
|
|
326
|
+
hasVertex(vertex: T): boolean;
|
|
327
|
+
getVertices(): T[];
|
|
328
|
+
addEdge(from: T, to: T, weight?: number): void;
|
|
329
|
+
removeEdge(from: T, to: T): void;
|
|
330
|
+
hasEdge(from: T, to: T): boolean;
|
|
331
|
+
getEdges(vertex: T): DirectedEdge<T>[];
|
|
332
|
+
/**
|
|
333
|
+
* Breadth-First Search (BFS)
|
|
334
|
+
*/
|
|
335
|
+
bfs(start: T): T[];
|
|
336
|
+
/**
|
|
337
|
+
* Depth-First Search (DFS)
|
|
338
|
+
*/
|
|
339
|
+
dfs(start: T): T[];
|
|
340
|
+
clear(): void;
|
|
341
|
+
size(): number;
|
|
342
|
+
isDirected(): true;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Graph
|
|
347
|
+
* -----
|
|
348
|
+
* General-purpose adjacency list graph data structure.
|
|
349
|
+
*
|
|
350
|
+
* Includes:
|
|
351
|
+
* - Directed / Undirected graph support
|
|
352
|
+
* - Weighted or unweighted edges (stored, not processed)
|
|
353
|
+
* - General traversal algorithms: BFS & DFS
|
|
354
|
+
*
|
|
355
|
+
* Advanced algorithms (Dijkstra, MST, etc.) should live separately.
|
|
356
|
+
*/
|
|
357
|
+
interface Edge<T = string> {
|
|
358
|
+
to: T;
|
|
359
|
+
weight?: number;
|
|
360
|
+
}
|
|
361
|
+
declare class Graph<T = string> {
|
|
362
|
+
private readonly directed;
|
|
363
|
+
private adjList;
|
|
364
|
+
constructor(directed?: boolean);
|
|
365
|
+
addVertex(vertex: T): void;
|
|
366
|
+
removeVertex(vertex: T): void;
|
|
367
|
+
hasVertex(vertex: T): boolean;
|
|
368
|
+
getVertices(): T[];
|
|
369
|
+
addEdge(from: T, to: T, weight?: number): void;
|
|
370
|
+
removeEdge(from: T, to: T): void;
|
|
371
|
+
hasEdge(from: T, to: T): boolean;
|
|
372
|
+
getEdges(vertex: T): Edge<T>[];
|
|
373
|
+
/**
|
|
374
|
+
* Breadth-First Search (BFS)
|
|
375
|
+
*/
|
|
376
|
+
bfs(start: T): T[];
|
|
377
|
+
/**
|
|
378
|
+
* Depth-First Search (DFS)
|
|
379
|
+
*/
|
|
380
|
+
dfs(start: T): T[];
|
|
381
|
+
clear(): void;
|
|
382
|
+
size(): number;
|
|
383
|
+
isDirected(): boolean;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* ConsistentHash
|
|
388
|
+
* --------------
|
|
389
|
+
* Consistent hashing implementation with virtual nodes.
|
|
390
|
+
*
|
|
391
|
+
* Use cases:
|
|
392
|
+
* - Load balancers
|
|
393
|
+
* - Distributed caches
|
|
394
|
+
* - Database sharding
|
|
395
|
+
*
|
|
396
|
+
* Characteristics:
|
|
397
|
+
* - Minimal key remapping on node add/remove
|
|
398
|
+
* - Supports virtual nodes (replicas)
|
|
399
|
+
* - Deterministic hashing
|
|
400
|
+
*/
|
|
401
|
+
declare class ConsistentHash<T extends string | number> {
|
|
402
|
+
private ring;
|
|
403
|
+
private sortedKeys;
|
|
404
|
+
private replicas;
|
|
405
|
+
constructor(replicas?: number);
|
|
406
|
+
addNode(node: T): void;
|
|
407
|
+
removeNode(node: T): void;
|
|
408
|
+
getNode(key: string | number): T | undefined;
|
|
409
|
+
getNodes(): T[];
|
|
410
|
+
size(): number;
|
|
411
|
+
clear(): void;
|
|
412
|
+
private hash;
|
|
413
|
+
private sortRing;
|
|
414
|
+
private findClosestIndex;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* HashMap
|
|
419
|
+
* -------
|
|
420
|
+
* A generic hash map implementation using separate chaining.
|
|
421
|
+
*
|
|
422
|
+
* Characteristics:
|
|
423
|
+
* - Generic key-value support
|
|
424
|
+
* - Handles collisions via linked lists (arrays)
|
|
425
|
+
* - Automatically resizes when load factor exceeds threshold
|
|
426
|
+
*
|
|
427
|
+
* Time Complexity:
|
|
428
|
+
* - Average: O(1)
|
|
429
|
+
* - Worst: O(n)
|
|
430
|
+
*/
|
|
431
|
+
declare class HashMap<K extends string | number, V> {
|
|
432
|
+
private buckets;
|
|
433
|
+
private capacity;
|
|
434
|
+
private size;
|
|
435
|
+
private readonly LOAD_FACTOR;
|
|
436
|
+
constructor(initialCapacity?: number);
|
|
437
|
+
set(key: K, value: V): void;
|
|
438
|
+
get(key: K): V | undefined;
|
|
439
|
+
has(key: K): boolean;
|
|
440
|
+
delete(key: K): boolean;
|
|
441
|
+
clear(): void;
|
|
442
|
+
keys(): K[];
|
|
443
|
+
values(): V[];
|
|
444
|
+
entries(): Array<[K, V]>;
|
|
445
|
+
getSize(): number;
|
|
446
|
+
getCapacity(): number;
|
|
447
|
+
private hash;
|
|
448
|
+
private resize;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* HashSet
|
|
453
|
+
* -------
|
|
454
|
+
* A generic hash set implementation built on top of HashMap.
|
|
455
|
+
*
|
|
456
|
+
* Characteristics:
|
|
457
|
+
* - Stores unique values only
|
|
458
|
+
* - Backed by HashMap for O(1) average operations
|
|
459
|
+
*
|
|
460
|
+
* Time Complexity:
|
|
461
|
+
* - Average: O(1)
|
|
462
|
+
* - Worst: O(n)
|
|
463
|
+
*/
|
|
464
|
+
declare class HashSet<T extends string | number> {
|
|
465
|
+
private map;
|
|
466
|
+
constructor(initialCapacity?: number);
|
|
467
|
+
add(value: T): void;
|
|
468
|
+
has(value: T): boolean;
|
|
469
|
+
delete(value: T): boolean;
|
|
470
|
+
clear(): void;
|
|
471
|
+
size(): number;
|
|
472
|
+
values(): T[];
|
|
473
|
+
isEmpty(): boolean;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* LFUCache
|
|
478
|
+
* --------
|
|
479
|
+
* Least Frequently Used cache implementation.
|
|
480
|
+
*
|
|
481
|
+
* Eviction rules:
|
|
482
|
+
* 1. Evict the lowest frequency
|
|
483
|
+
* 2. If tie, evict least recently used (LRU)
|
|
484
|
+
*
|
|
485
|
+
* Uses:
|
|
486
|
+
* - HashMap for O(1) lookup
|
|
487
|
+
* - Frequency Map → DoublyLinkedList for LRU ordering
|
|
488
|
+
*/
|
|
489
|
+
declare class LFUCache<K extends string | number, V> {
|
|
490
|
+
private capacity;
|
|
491
|
+
private size;
|
|
492
|
+
private minFreq;
|
|
493
|
+
private cache;
|
|
494
|
+
private freqMap;
|
|
495
|
+
constructor(capacity: number);
|
|
496
|
+
get(key: K): V | undefined;
|
|
497
|
+
put(key: K, value: V): void;
|
|
498
|
+
has(key: K): boolean;
|
|
499
|
+
sizeOf(): number;
|
|
500
|
+
clear(): void;
|
|
501
|
+
private updateFrequency;
|
|
502
|
+
private evictLFU;
|
|
503
|
+
private getFreqList;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* LRUCache
|
|
508
|
+
* --------
|
|
509
|
+
* Least Recently Used (LRU) Cache implementation.
|
|
510
|
+
*
|
|
511
|
+
* Characteristics:
|
|
512
|
+
* - O(1) get and put operations
|
|
513
|
+
* - Evicts least recently used item when capacity is exceeded
|
|
514
|
+
*
|
|
515
|
+
* Data Structures Used:
|
|
516
|
+
* - HashMap for fast lookup
|
|
517
|
+
* - Doubly Linked List for usage order
|
|
518
|
+
*/
|
|
519
|
+
declare class LRUCache<K extends string | number, V> {
|
|
520
|
+
private capacity;
|
|
521
|
+
private cache;
|
|
522
|
+
private head;
|
|
523
|
+
private tail;
|
|
524
|
+
constructor(capacity: number);
|
|
525
|
+
get(key: K): V | undefined;
|
|
526
|
+
put(key: K, value: V): void;
|
|
527
|
+
has(key: K): boolean;
|
|
528
|
+
size(): number;
|
|
529
|
+
clear(): void;
|
|
530
|
+
private addToFront;
|
|
531
|
+
private removeNode;
|
|
532
|
+
private moveToFront;
|
|
533
|
+
private evictLeastRecentlyUsed;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* BinaryHeap
|
|
538
|
+
* ----------
|
|
539
|
+
* A generic binary heap implementation.
|
|
540
|
+
*
|
|
541
|
+
* By default this is a min-heap.
|
|
542
|
+
* You can create a max-heap by providing a custom comparator.
|
|
543
|
+
*
|
|
544
|
+
* Time Complexity:
|
|
545
|
+
* - Insert: O(log n)
|
|
546
|
+
* - Extract: O(log n)
|
|
547
|
+
* - Peek: O(1)
|
|
548
|
+
*/
|
|
549
|
+
declare class BinaryHeap<T> {
|
|
550
|
+
private heap;
|
|
551
|
+
private readonly compare;
|
|
552
|
+
constructor(comparator?: (a: T, b: T) => number, initial?: T[]);
|
|
553
|
+
insert(value: T): void;
|
|
554
|
+
extract(): T | undefined;
|
|
555
|
+
peek(): T | undefined;
|
|
556
|
+
size(): number;
|
|
557
|
+
isEmpty(): boolean;
|
|
558
|
+
clear(): void;
|
|
559
|
+
toArray(): T[];
|
|
560
|
+
private heapify;
|
|
561
|
+
private siftUp;
|
|
562
|
+
private siftDown;
|
|
563
|
+
private swap;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* FibonacciHeap
|
|
568
|
+
* -------------
|
|
569
|
+
* Amortized-optimal heap supporting:
|
|
570
|
+
* - insert: O(1)
|
|
571
|
+
* - findMin: O(1)
|
|
572
|
+
* - merge: O(1)
|
|
573
|
+
* - decreaseKey: O(1) amortized
|
|
574
|
+
* - extractMin: O(log n) amortized
|
|
575
|
+
*/
|
|
576
|
+
declare class FibNode<T> {
|
|
577
|
+
key: T;
|
|
578
|
+
parent: FibNode<T> | null;
|
|
579
|
+
children: FibNode<T>[];
|
|
580
|
+
mark: boolean;
|
|
581
|
+
constructor(key: T);
|
|
582
|
+
}
|
|
583
|
+
declare class FibonacciHeap<T> {
|
|
584
|
+
private roots;
|
|
585
|
+
private minNode;
|
|
586
|
+
private _size;
|
|
587
|
+
private readonly compare;
|
|
588
|
+
constructor(compareFn?: (a: T, b: T) => number);
|
|
589
|
+
insert(key: T): FibNode<T>;
|
|
590
|
+
findMin(): T | undefined;
|
|
591
|
+
size(): number;
|
|
592
|
+
isEmpty(): boolean;
|
|
593
|
+
merge(other: FibonacciHeap<T>): void;
|
|
594
|
+
extractMin(): T | undefined;
|
|
595
|
+
decreaseKey(node: FibNode<T>, newKey: T): void;
|
|
596
|
+
clear(): void;
|
|
597
|
+
private consolidate;
|
|
598
|
+
private link;
|
|
599
|
+
private cut;
|
|
600
|
+
private cascadingCut;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* MaxHeap
|
|
605
|
+
* -------
|
|
606
|
+
* A specialized MaxHeap implementation built on top of BinaryHeap.
|
|
607
|
+
*
|
|
608
|
+
* Characteristics:
|
|
609
|
+
* - Always extracts the maximum element
|
|
610
|
+
* - O(log n) insert & extract
|
|
611
|
+
* - O(1) peek
|
|
612
|
+
*/
|
|
613
|
+
|
|
614
|
+
declare class MaxHeap<T> extends BinaryHeap<T> {
|
|
615
|
+
constructor(initial?: T[]);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* MinHeap
|
|
620
|
+
* -------
|
|
621
|
+
* A specialized MinHeap implementation built on top of BinaryHeap.
|
|
622
|
+
*
|
|
623
|
+
* Characteristics:
|
|
624
|
+
* - Always extracts the minimum element
|
|
625
|
+
* - O(log n) insert & extract
|
|
626
|
+
* - O(1) peek
|
|
627
|
+
*/
|
|
628
|
+
|
|
629
|
+
declare class MinHeap<T> extends BinaryHeap<T> {
|
|
630
|
+
constructor(initial?: T[]);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* PairingHeap
|
|
635
|
+
* -----------
|
|
636
|
+
* A self-adjusting heap with excellent practical performance.
|
|
637
|
+
*
|
|
638
|
+
* Time Complexity (amortized):
|
|
639
|
+
* - insert: O(1)
|
|
640
|
+
* - merge: O(1)
|
|
641
|
+
* - findMin: O(1)
|
|
642
|
+
* - extractMin: O(log n)
|
|
643
|
+
* - decreaseKey: O(log n)
|
|
644
|
+
*
|
|
645
|
+
* Simpler and safer than Fibonacci Heap.
|
|
646
|
+
*/
|
|
647
|
+
declare class PairingNode<T> {
|
|
648
|
+
key: T;
|
|
649
|
+
child: PairingNode<T> | null;
|
|
650
|
+
sibling: PairingNode<T> | null;
|
|
651
|
+
parent: PairingNode<T> | null;
|
|
652
|
+
constructor(key: T);
|
|
653
|
+
}
|
|
654
|
+
declare class PairingHeap<T> {
|
|
655
|
+
private root;
|
|
656
|
+
private _size;
|
|
657
|
+
private readonly compare;
|
|
658
|
+
constructor(compareFn?: (a: T, b: T) => number);
|
|
659
|
+
insert(key: T): PairingNode<T>;
|
|
660
|
+
findMin(): T | undefined;
|
|
661
|
+
size(): number;
|
|
662
|
+
isEmpty(): boolean;
|
|
663
|
+
merge(other: PairingHeap<T>): void;
|
|
664
|
+
extractMin(): T | undefined;
|
|
665
|
+
decreaseKey(node: PairingNode<T>, newKey: T): void;
|
|
666
|
+
clear(): void;
|
|
667
|
+
private mergeNodes;
|
|
668
|
+
/**
|
|
669
|
+
* Two-pass pairing: first pair siblings, then merge back
|
|
670
|
+
*/
|
|
671
|
+
private combineSiblings;
|
|
672
|
+
private cut;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
declare class CircularLinkedList<T> implements Iterable<T> {
|
|
676
|
+
private tail;
|
|
677
|
+
private length;
|
|
678
|
+
size(): number;
|
|
679
|
+
add(value: T): void;
|
|
680
|
+
remove(value: T): boolean;
|
|
681
|
+
toArray(): T[];
|
|
682
|
+
[Symbol.iterator](): Iterator<T>;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
declare class DoublyLinkedList<T> implements Iterable<T> {
|
|
686
|
+
private head;
|
|
687
|
+
private tail;
|
|
688
|
+
private length;
|
|
689
|
+
size(): number;
|
|
690
|
+
add(value: T): void;
|
|
691
|
+
remove(value: T): boolean;
|
|
692
|
+
toArray(): T[];
|
|
693
|
+
[Symbol.iterator](): Iterator<T>;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
declare class Node<T> {
|
|
697
|
+
value: T;
|
|
698
|
+
next: Node<T> | null;
|
|
699
|
+
prev: Node<T> | null;
|
|
700
|
+
constructor(value: T);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
declare class SinglyLinkedList<T> implements Iterable<T> {
|
|
704
|
+
private head;
|
|
705
|
+
private tail;
|
|
706
|
+
private length;
|
|
707
|
+
size(): number;
|
|
708
|
+
isEmpty(): boolean;
|
|
709
|
+
add(value: T): void;
|
|
710
|
+
remove(value: T): boolean;
|
|
711
|
+
contains(value: T): boolean;
|
|
712
|
+
toArray(): T[];
|
|
713
|
+
[Symbol.iterator](): Iterator<T>;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* BloomFilter
|
|
718
|
+
* -----------
|
|
719
|
+
* A probabilistic data structure for fast membership testing.
|
|
720
|
+
*
|
|
721
|
+
* Characteristics:
|
|
722
|
+
* - No false negatives
|
|
723
|
+
* - Possible false positives
|
|
724
|
+
* - Space efficient
|
|
725
|
+
* - Insert & lookup only
|
|
726
|
+
*
|
|
727
|
+
* Time Complexity:
|
|
728
|
+
* - add: O(k)
|
|
729
|
+
* - contains: O(k)
|
|
730
|
+
*/
|
|
731
|
+
declare class BloomFilter {
|
|
732
|
+
private readonly size;
|
|
733
|
+
private readonly hashCount;
|
|
734
|
+
private readonly bits;
|
|
735
|
+
constructor(size: number, hashCount: number);
|
|
736
|
+
add(value: string): void;
|
|
737
|
+
contains(value: string): boolean;
|
|
738
|
+
clear(): void;
|
|
739
|
+
private getHashes;
|
|
740
|
+
private hash;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* CountMinSketch
|
|
745
|
+
* --------------
|
|
746
|
+
* A probabilistic data structure for frequency estimation.
|
|
747
|
+
*
|
|
748
|
+
* Guarantees:
|
|
749
|
+
* - Estimated count >= true count
|
|
750
|
+
* - No false negatives
|
|
751
|
+
*
|
|
752
|
+
* Time Complexity:
|
|
753
|
+
* - update: O(d)
|
|
754
|
+
* - estimate: O(d)
|
|
755
|
+
*/
|
|
756
|
+
declare class CountMinSketch {
|
|
757
|
+
private readonly width;
|
|
758
|
+
private readonly depth;
|
|
759
|
+
private readonly table;
|
|
760
|
+
private readonly seeds;
|
|
761
|
+
constructor(width: number, depth: number);
|
|
762
|
+
/**
|
|
763
|
+
* Increments the count of an item
|
|
764
|
+
*/
|
|
765
|
+
update(value: string, count?: number): void;
|
|
766
|
+
/**
|
|
767
|
+
* Returns the estimated frequency of an item
|
|
768
|
+
*/
|
|
769
|
+
estimate(value: string): number;
|
|
770
|
+
clear(): void;
|
|
771
|
+
private hash;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* HyperLogLog
|
|
776
|
+
* -----------
|
|
777
|
+
* Probabilistic data structure for cardinality estimation.
|
|
778
|
+
*
|
|
779
|
+
* Guarantees:
|
|
780
|
+
* - Approximates number of distinct elements
|
|
781
|
+
* - Small memory footprint
|
|
782
|
+
*
|
|
783
|
+
* Error rate ≈ 1.04 / sqrt(m)
|
|
784
|
+
* where m = number of registers
|
|
785
|
+
*/
|
|
786
|
+
declare class HyperLogLog {
|
|
787
|
+
private readonly p;
|
|
788
|
+
private readonly m;
|
|
789
|
+
private readonly registers;
|
|
790
|
+
private readonly alpha;
|
|
791
|
+
constructor(p?: number);
|
|
792
|
+
add(value: string): void;
|
|
793
|
+
count(): number;
|
|
794
|
+
clear(): void;
|
|
795
|
+
private hash;
|
|
796
|
+
private countLeadingZeros;
|
|
797
|
+
private getAlpha;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* CircularQueue
|
|
802
|
+
* -------------
|
|
803
|
+
* Fixed-size circular FIFO queue.
|
|
804
|
+
*
|
|
805
|
+
* Characteristics:
|
|
806
|
+
* - O(1) enqueue / dequeue
|
|
807
|
+
* - Fixed capacity
|
|
808
|
+
*
|
|
809
|
+
* Use cases:
|
|
810
|
+
* - Ring buffers
|
|
811
|
+
* - Real-time systems
|
|
812
|
+
*/
|
|
813
|
+
declare class CircularQueue<T> {
|
|
814
|
+
private readonly capacity;
|
|
815
|
+
private data;
|
|
816
|
+
private head;
|
|
817
|
+
private tail;
|
|
818
|
+
private length;
|
|
819
|
+
constructor(capacity: number);
|
|
820
|
+
size(): number;
|
|
821
|
+
isEmpty(): boolean;
|
|
822
|
+
isFull(): boolean;
|
|
823
|
+
enqueue(value: T): void;
|
|
824
|
+
dequeue(): T | undefined;
|
|
825
|
+
peek(): T | undefined;
|
|
826
|
+
clear(): void;
|
|
827
|
+
toArray(): T[];
|
|
828
|
+
toString(): string;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* Deque
|
|
833
|
+
* -----
|
|
834
|
+
* Double-ended queue.
|
|
835
|
+
*
|
|
836
|
+
* Characteristics:
|
|
837
|
+
* - O(1) add/remove from both ends
|
|
838
|
+
*
|
|
839
|
+
* Use cases:
|
|
840
|
+
* - Sliding window problems
|
|
841
|
+
* - Palindrome checking
|
|
842
|
+
*/
|
|
843
|
+
declare class Deque<T> {
|
|
844
|
+
private items;
|
|
845
|
+
size(): number;
|
|
846
|
+
isEmpty(): boolean;
|
|
847
|
+
pushFront(value: T): void;
|
|
848
|
+
pushBack(value: T): void;
|
|
849
|
+
popFront(): T | undefined;
|
|
850
|
+
popBack(): T | undefined;
|
|
851
|
+
peekFront(): T | undefined;
|
|
852
|
+
peekBack(): T | undefined;
|
|
853
|
+
clear(): void;
|
|
854
|
+
toArray(): T[];
|
|
855
|
+
toString(): string;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
/**
|
|
859
|
+
* PriorityQueue (Min-Heap)
|
|
860
|
+
* ------------------------
|
|
861
|
+
* Elements with lower priority value are dequeued first.
|
|
862
|
+
*
|
|
863
|
+
* Characteristics:
|
|
864
|
+
* - O(log n) enqueue / dequeue
|
|
865
|
+
*
|
|
866
|
+
* Use cases:
|
|
867
|
+
* - Dijkstra / A*
|
|
868
|
+
* - Task scheduling
|
|
869
|
+
*/
|
|
870
|
+
declare class PriorityQueue<T> {
|
|
871
|
+
private heap;
|
|
872
|
+
size(): number;
|
|
873
|
+
isEmpty(): boolean;
|
|
874
|
+
enqueue(value: T, priority: number): void;
|
|
875
|
+
dequeue(): T | undefined;
|
|
876
|
+
peek(): T | undefined;
|
|
877
|
+
private bubbleUp;
|
|
878
|
+
private bubbleDown;
|
|
879
|
+
toString(): string;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Queue
|
|
884
|
+
* -----
|
|
885
|
+
* FIFO (First In First Out) queue.
|
|
886
|
+
*
|
|
887
|
+
* Characteristics:
|
|
888
|
+
* - O(1) enqueue / dequeue (amortized)
|
|
889
|
+
* - Generic
|
|
890
|
+
*
|
|
891
|
+
* Use cases:
|
|
892
|
+
* - Task scheduling
|
|
893
|
+
* - Event processing
|
|
894
|
+
* - BFS traversal
|
|
895
|
+
*/
|
|
896
|
+
declare class Queue<T> {
|
|
897
|
+
private items;
|
|
898
|
+
private head;
|
|
899
|
+
size(): number;
|
|
900
|
+
isEmpty(): boolean;
|
|
901
|
+
enqueue(value: T): void;
|
|
902
|
+
dequeue(): T | undefined;
|
|
903
|
+
peek(): T | undefined;
|
|
904
|
+
clear(): void;
|
|
905
|
+
toArray(): T[];
|
|
906
|
+
toString(): string;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Disjoint Set Union (Union-Find)
|
|
911
|
+
* ------------------------------
|
|
912
|
+
* Data structure that keeps track of a partition of a set into
|
|
913
|
+
* disjoint (non-overlapping) subsets.
|
|
914
|
+
*
|
|
915
|
+
* Optimizations:
|
|
916
|
+
* - Path compression
|
|
917
|
+
* - Union by rank
|
|
918
|
+
*
|
|
919
|
+
* Time Complexity (amortized):
|
|
920
|
+
* - find: O(α(n))
|
|
921
|
+
* - union: O(α(n))
|
|
922
|
+
* - connected: O(α(n))
|
|
923
|
+
*/
|
|
924
|
+
declare class DisjointSetUnion<T = number> {
|
|
925
|
+
private parent;
|
|
926
|
+
private rank;
|
|
927
|
+
/**
|
|
928
|
+
* Creates a new set containing `x` if it doesn't exist.
|
|
929
|
+
*/
|
|
930
|
+
makeSet(x: T): void;
|
|
931
|
+
/**
|
|
932
|
+
* Finds the representative (root) of the set containing `x`.
|
|
933
|
+
* Applies path compression.
|
|
934
|
+
*/
|
|
935
|
+
find(x: T): T;
|
|
936
|
+
/**
|
|
937
|
+
* Unions the sets containing `x` and `y`.
|
|
938
|
+
*/
|
|
939
|
+
union(x: T, y: T): void;
|
|
940
|
+
/**
|
|
941
|
+
* Checks whether `x` and `y` belong to the same set.
|
|
942
|
+
*/
|
|
943
|
+
connected(x: T, y: T): boolean;
|
|
944
|
+
/**
|
|
945
|
+
* Returns the number of disjoint sets.
|
|
946
|
+
*/
|
|
947
|
+
countSets(): number;
|
|
948
|
+
/**
|
|
949
|
+
* Returns all elements.
|
|
950
|
+
*/
|
|
951
|
+
elements(): T[];
|
|
952
|
+
/**
|
|
953
|
+
* Clears all sets.
|
|
954
|
+
*/
|
|
955
|
+
clear(): void;
|
|
956
|
+
/**
|
|
957
|
+
* Returns total number of elements.
|
|
958
|
+
*/
|
|
959
|
+
size(): number;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* MultiSet (Bag)
|
|
964
|
+
* --------------
|
|
965
|
+
* A set-like data structure that allows duplicate elements
|
|
966
|
+
* and tracks the count of each element.
|
|
967
|
+
*
|
|
968
|
+
* Characteristics:
|
|
969
|
+
* - Elements can appear multiple times
|
|
970
|
+
* - Count-based operations
|
|
971
|
+
* - No ordering guarantees
|
|
972
|
+
*/
|
|
973
|
+
declare class MultiSet<T> implements Iterable<[T, number]> {
|
|
974
|
+
private store;
|
|
975
|
+
constructor(iterable?: Iterable<T>);
|
|
976
|
+
add(value: T, count?: number): void;
|
|
977
|
+
remove(value: T, count?: number): boolean;
|
|
978
|
+
clear(): void;
|
|
979
|
+
has(value: T): boolean;
|
|
980
|
+
count(value: T): number;
|
|
981
|
+
size(): number;
|
|
982
|
+
distinctSize(): number;
|
|
983
|
+
isEmpty(): boolean;
|
|
984
|
+
values(): T[];
|
|
985
|
+
entries(): Array<[T, number]>;
|
|
986
|
+
/**
|
|
987
|
+
* Union: max(countA, countB)
|
|
988
|
+
*/
|
|
989
|
+
union(other: MultiSet<T>): MultiSet<T>;
|
|
990
|
+
/**
|
|
991
|
+
* Intersection: min(countA, countB)
|
|
992
|
+
*/
|
|
993
|
+
intersection(other: MultiSet<T>): MultiSet<T>;
|
|
994
|
+
/**
|
|
995
|
+
* Difference: countA - countB (floor at 0)
|
|
996
|
+
*/
|
|
997
|
+
difference(other: MultiSet<T>): MultiSet<T>;
|
|
998
|
+
[Symbol.iterator](): Iterator<[T, number]>;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* OrderedSet
|
|
1003
|
+
* ----------
|
|
1004
|
+
* A set data structure that preserves insertion order.
|
|
1005
|
+
*
|
|
1006
|
+
* Characteristics:
|
|
1007
|
+
* - Unique elements
|
|
1008
|
+
* - Deterministic iteration order
|
|
1009
|
+
* - Supports standard set operations
|
|
1010
|
+
*
|
|
1011
|
+
* Backed by Map to guarantee order.
|
|
1012
|
+
*/
|
|
1013
|
+
declare class OrderedSet<T> implements Iterable<T> {
|
|
1014
|
+
private store;
|
|
1015
|
+
constructor(iterable?: Iterable<T>);
|
|
1016
|
+
add(value: T): void;
|
|
1017
|
+
delete(value: T): boolean;
|
|
1018
|
+
has(value: T): boolean;
|
|
1019
|
+
clear(): void;
|
|
1020
|
+
size(): number;
|
|
1021
|
+
isEmpty(): boolean;
|
|
1022
|
+
values(): T[];
|
|
1023
|
+
first(): T | undefined;
|
|
1024
|
+
last(): T | undefined;
|
|
1025
|
+
union(other: OrderedSet<T>): OrderedSet<T>;
|
|
1026
|
+
intersection(other: OrderedSet<T>): OrderedSet<T>;
|
|
1027
|
+
difference(other: OrderedSet<T>): OrderedSet<T>;
|
|
1028
|
+
isSubsetOf(other: OrderedSet<T>): boolean;
|
|
1029
|
+
isSupersetOf(other: OrderedSet<T>): boolean;
|
|
1030
|
+
[Symbol.iterator](): Iterator<T>;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* Set
|
|
1035
|
+
* ---
|
|
1036
|
+
* A generic Set data structure abstraction.
|
|
1037
|
+
*
|
|
1038
|
+
* Characteristics:
|
|
1039
|
+
* - Stores unique elements
|
|
1040
|
+
* - No ordering guarantees
|
|
1041
|
+
* - Supports standard set operations
|
|
1042
|
+
*
|
|
1043
|
+
* Internally backed by JavaScript's Set,
|
|
1044
|
+
* but exposes a clean, controlled API.
|
|
1045
|
+
*/
|
|
1046
|
+
declare class Set<T> implements Iterable<T> {
|
|
1047
|
+
private store;
|
|
1048
|
+
constructor(iterable?: Iterable<T>);
|
|
1049
|
+
add(value: T): void;
|
|
1050
|
+
delete(value: T): boolean;
|
|
1051
|
+
has(value: T): boolean;
|
|
1052
|
+
clear(): void;
|
|
1053
|
+
size(): number;
|
|
1054
|
+
isEmpty(): boolean;
|
|
1055
|
+
values(): T[];
|
|
1056
|
+
union(other: Set<T>): Set<T>;
|
|
1057
|
+
intersection(other: Set<T>): Set<T>;
|
|
1058
|
+
difference(other: Set<T>): Set<T>;
|
|
1059
|
+
isSubsetOf(other: Set<T>): boolean;
|
|
1060
|
+
isSupersetOf(other: Set<T>): boolean;
|
|
1061
|
+
[Symbol.iterator](): Iterator<T>;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* KDTree (k-dimensional tree)
|
|
1066
|
+
* ---------------------------
|
|
1067
|
+
* A space-partitioning data structure for organizing points
|
|
1068
|
+
* in a k-dimensional space.
|
|
1069
|
+
*
|
|
1070
|
+
* Use cases:
|
|
1071
|
+
* - Nearest neighbor search
|
|
1072
|
+
* - Range queries
|
|
1073
|
+
* - Spatial indexing
|
|
1074
|
+
*
|
|
1075
|
+
* Characteristics:
|
|
1076
|
+
* - Binary tree
|
|
1077
|
+
* - Splits space by alternating dimensions
|
|
1078
|
+
*
|
|
1079
|
+
* Time Complexity (average):
|
|
1080
|
+
* - Build: O(n log n)
|
|
1081
|
+
* - Insert: O(log n)
|
|
1082
|
+
* - Search: O(log n)
|
|
1083
|
+
*/
|
|
1084
|
+
type Point = number[];
|
|
1085
|
+
declare class KDTree<T = any> {
|
|
1086
|
+
private root;
|
|
1087
|
+
private readonly k;
|
|
1088
|
+
constructor(points?: Array<{
|
|
1089
|
+
point: Point;
|
|
1090
|
+
value?: T;
|
|
1091
|
+
}>, dimensions?: number);
|
|
1092
|
+
insert(point: Point, value?: T): void;
|
|
1093
|
+
contains(point: Point): boolean;
|
|
1094
|
+
nearest(target: Point): {
|
|
1095
|
+
point: Point;
|
|
1096
|
+
value?: T;
|
|
1097
|
+
} | null;
|
|
1098
|
+
rangeSearch(min: Point, max: Point): Array<{
|
|
1099
|
+
point: Point;
|
|
1100
|
+
value?: T;
|
|
1101
|
+
}>;
|
|
1102
|
+
isEmpty(): boolean;
|
|
1103
|
+
private build;
|
|
1104
|
+
private insertNode;
|
|
1105
|
+
private findNode;
|
|
1106
|
+
private distanceSquared;
|
|
1107
|
+
private inRange;
|
|
1108
|
+
private pointsEqual;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* QuadTree
|
|
1113
|
+
* --------
|
|
1114
|
+
* A 2D spatial partitioning data structure that recursively subdivides
|
|
1115
|
+
* space into four quadrants.
|
|
1116
|
+
*/
|
|
1117
|
+
type Point2D = {
|
|
1118
|
+
x: number;
|
|
1119
|
+
y: number;
|
|
1120
|
+
};
|
|
1121
|
+
type Rect = {
|
|
1122
|
+
x: number;
|
|
1123
|
+
y: number;
|
|
1124
|
+
w: number;
|
|
1125
|
+
h: number;
|
|
1126
|
+
};
|
|
1127
|
+
declare class QuadTree<T = any> {
|
|
1128
|
+
private root;
|
|
1129
|
+
constructor(boundary: Rect, capacity?: number);
|
|
1130
|
+
insert(point: Point2D, value?: T): boolean;
|
|
1131
|
+
contains(point: Point2D): boolean;
|
|
1132
|
+
query(range: Rect): Array<{
|
|
1133
|
+
point: Point2D;
|
|
1134
|
+
value?: T;
|
|
1135
|
+
}>;
|
|
1136
|
+
clear(): void;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
/**
|
|
1140
|
+
* MaxStack
|
|
1141
|
+
* --------
|
|
1142
|
+
* Stack with constant-time maximum lookup.
|
|
1143
|
+
*
|
|
1144
|
+
* Characteristics:
|
|
1145
|
+
* - O(1) push / pop / getMax
|
|
1146
|
+
* - Uses auxiliary stack
|
|
1147
|
+
*
|
|
1148
|
+
* Use cases:
|
|
1149
|
+
* - Sliding window problems
|
|
1150
|
+
* - Game stat tracking
|
|
1151
|
+
*/
|
|
1152
|
+
declare class MaxStack<T> {
|
|
1153
|
+
private stack;
|
|
1154
|
+
private maxStack;
|
|
1155
|
+
size(): number;
|
|
1156
|
+
isEmpty(): boolean;
|
|
1157
|
+
push(value: T): void;
|
|
1158
|
+
pop(): T | undefined;
|
|
1159
|
+
peek(): T | undefined;
|
|
1160
|
+
getMax(): T | undefined;
|
|
1161
|
+
clear(): void;
|
|
1162
|
+
toArray(): T[];
|
|
1163
|
+
toString(): string;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* MinStack
|
|
1168
|
+
* --------
|
|
1169
|
+
* Stack with constant-time minimum lookup.
|
|
1170
|
+
*
|
|
1171
|
+
* Characteristics:
|
|
1172
|
+
* - O(1) push / pop / getMin
|
|
1173
|
+
* - Uses auxiliary stack
|
|
1174
|
+
*
|
|
1175
|
+
* Use cases:
|
|
1176
|
+
* - Range queries
|
|
1177
|
+
* - Algorithm optimization
|
|
1178
|
+
*/
|
|
1179
|
+
declare class MinStack<T> {
|
|
1180
|
+
private stack;
|
|
1181
|
+
private minStack;
|
|
1182
|
+
size(): number;
|
|
1183
|
+
isEmpty(): boolean;
|
|
1184
|
+
push(value: T): void;
|
|
1185
|
+
pop(): T | undefined;
|
|
1186
|
+
peek(): T | undefined;
|
|
1187
|
+
getMin(): T | undefined;
|
|
1188
|
+
clear(): void;
|
|
1189
|
+
toArray(): T[];
|
|
1190
|
+
toString(): string;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* Stack
|
|
1195
|
+
* -----
|
|
1196
|
+
* LIFO (Last In First Out) stack implementation.
|
|
1197
|
+
*
|
|
1198
|
+
* Characteristics:
|
|
1199
|
+
* - O(1) push / pop / peek
|
|
1200
|
+
* - Generic
|
|
1201
|
+
* - Iterable (top → bottom)
|
|
1202
|
+
*
|
|
1203
|
+
* Use cases:
|
|
1204
|
+
* - Function calls
|
|
1205
|
+
* - Undo/redo systems
|
|
1206
|
+
* - Expression evaluation
|
|
1207
|
+
*/
|
|
1208
|
+
declare class Stack<T> implements Iterable<T> {
|
|
1209
|
+
protected items: T[];
|
|
1210
|
+
size(): number;
|
|
1211
|
+
isEmpty(): boolean;
|
|
1212
|
+
push(value: T): void;
|
|
1213
|
+
pop(): T | undefined;
|
|
1214
|
+
peek(): T | undefined;
|
|
1215
|
+
clear(): void;
|
|
1216
|
+
toArray(): T[];
|
|
1217
|
+
[Symbol.iterator](): Iterator<T>;
|
|
1218
|
+
toString(): string;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* SuffixArray
|
|
1223
|
+
* -----------
|
|
1224
|
+
* Data structure that stores the sorted order of all suffixes of a string.
|
|
1225
|
+
*
|
|
1226
|
+
* Use cases:
|
|
1227
|
+
* - Fast substring search
|
|
1228
|
+
* - Pattern matching
|
|
1229
|
+
* - Longest repeated substring
|
|
1230
|
+
* - Longest common prefix (with LCP)
|
|
1231
|
+
*
|
|
1232
|
+
* Construction:
|
|
1233
|
+
* - O(n log n) using prefix-doubling
|
|
1234
|
+
*/
|
|
1235
|
+
declare class SuffixArray {
|
|
1236
|
+
private readonly text;
|
|
1237
|
+
private readonly suffixArray;
|
|
1238
|
+
constructor(text: string);
|
|
1239
|
+
/**
|
|
1240
|
+
* Returns the suffix array (indices of sorted suffixes)
|
|
1241
|
+
*/
|
|
1242
|
+
getArray(): number[];
|
|
1243
|
+
/**
|
|
1244
|
+
* Returns the original string
|
|
1245
|
+
*/
|
|
1246
|
+
getText(): string;
|
|
1247
|
+
/**
|
|
1248
|
+
* Returns the suffix at a given position in the suffix array
|
|
1249
|
+
*/
|
|
1250
|
+
getSuffix(i: number): string;
|
|
1251
|
+
/**
|
|
1252
|
+
* Number of suffixes
|
|
1253
|
+
*/
|
|
1254
|
+
size(): number;
|
|
1255
|
+
private buildSuffixArray;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* SuffixTree
|
|
1260
|
+
* ----------
|
|
1261
|
+
* A compressed trie of all suffixes of a string.
|
|
1262
|
+
*
|
|
1263
|
+
* Implementation:
|
|
1264
|
+
* - Ukkonen's algorithm (online, O(n))
|
|
1265
|
+
* - Uses implicit end index for leaf edges
|
|
1266
|
+
*
|
|
1267
|
+
* Use cases:
|
|
1268
|
+
* - Fast substring queries
|
|
1269
|
+
* - Longest repeated substring
|
|
1270
|
+
* - Pattern matching
|
|
1271
|
+
*/
|
|
1272
|
+
declare class SuffixTree {
|
|
1273
|
+
private readonly text;
|
|
1274
|
+
private readonly root;
|
|
1275
|
+
private activeNode;
|
|
1276
|
+
private activeEdge;
|
|
1277
|
+
private activeLength;
|
|
1278
|
+
private remainingSuffixCount;
|
|
1279
|
+
private readonly leafEnd;
|
|
1280
|
+
constructor(text: string);
|
|
1281
|
+
/**
|
|
1282
|
+
* Checks if a pattern exists in the text.
|
|
1283
|
+
* (Traversal only; no extra algorithms.)
|
|
1284
|
+
*/
|
|
1285
|
+
contains(pattern: string): boolean;
|
|
1286
|
+
/**
|
|
1287
|
+
* Returns the original text
|
|
1288
|
+
*/
|
|
1289
|
+
getText(): string;
|
|
1290
|
+
private build;
|
|
1291
|
+
private extend;
|
|
1292
|
+
private walkDown;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
/**
|
|
1296
|
+
* SparseTable
|
|
1297
|
+
* -----------
|
|
1298
|
+
* Data structure for answering range queries on static arrays.
|
|
1299
|
+
*
|
|
1300
|
+
* Supports:
|
|
1301
|
+
* - Range Min Query (RMQ)
|
|
1302
|
+
* - Range Max Query
|
|
1303
|
+
* - Any idempotent operation
|
|
1304
|
+
*
|
|
1305
|
+
* Constraints:
|
|
1306
|
+
* - Array is immutable
|
|
1307
|
+
* - Operation must be associative
|
|
1308
|
+
* - Operation should be idempotent for O(1) queries
|
|
1309
|
+
*
|
|
1310
|
+
* Time Complexity:
|
|
1311
|
+
* - Build: O(n log n)
|
|
1312
|
+
* - Query: O(1)
|
|
1313
|
+
*/
|
|
1314
|
+
declare class SparseTable<T> {
|
|
1315
|
+
private readonly n;
|
|
1316
|
+
private readonly log;
|
|
1317
|
+
private readonly table;
|
|
1318
|
+
private readonly combine;
|
|
1319
|
+
constructor(arr: T[], combine: (a: T, b: T) => T);
|
|
1320
|
+
/**
|
|
1321
|
+
* Queries range [l, r] inclusive
|
|
1322
|
+
*/
|
|
1323
|
+
query(l: number, r: number): T;
|
|
1324
|
+
size(): number;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
/**
|
|
1328
|
+
* AVLTree
|
|
1329
|
+
* -------
|
|
1330
|
+
* Self-balancing Binary Search Tree (AVL).
|
|
1331
|
+
*
|
|
1332
|
+
* Properties:
|
|
1333
|
+
* - Balance factor = height(left) - height(right)
|
|
1334
|
+
* - Balance factor ∈ {-1, 0, 1}
|
|
1335
|
+
*
|
|
1336
|
+
* Guarantees:
|
|
1337
|
+
* - O(log n) insert, delete, search
|
|
1338
|
+
*/
|
|
1339
|
+
declare class AVLTree<T> {
|
|
1340
|
+
private root;
|
|
1341
|
+
private compare;
|
|
1342
|
+
constructor(compareFn?: (a: T, b: T) => number);
|
|
1343
|
+
insert(value: T): void;
|
|
1344
|
+
remove(value: T): void;
|
|
1345
|
+
contains(value: T): boolean;
|
|
1346
|
+
inorder(): T[];
|
|
1347
|
+
preorder(): T[];
|
|
1348
|
+
postorder(): T[];
|
|
1349
|
+
height(): number;
|
|
1350
|
+
isEmpty(): boolean;
|
|
1351
|
+
clear(): void;
|
|
1352
|
+
private insertNode;
|
|
1353
|
+
private removeNode;
|
|
1354
|
+
private search;
|
|
1355
|
+
private rotateRight;
|
|
1356
|
+
private rotateLeft;
|
|
1357
|
+
private rebalance;
|
|
1358
|
+
private nodeHeight;
|
|
1359
|
+
private updateHeight;
|
|
1360
|
+
private getBalance;
|
|
1361
|
+
private findMin;
|
|
1362
|
+
private inorderTraverse;
|
|
1363
|
+
private preorderTraverse;
|
|
1364
|
+
private postorderTraverse;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
/**
|
|
1368
|
+
* RedBlackTree
|
|
1369
|
+
* ------------
|
|
1370
|
+
* Self-balancing Binary Search Tree using red-black properties.
|
|
1371
|
+
*
|
|
1372
|
+
* Properties:
|
|
1373
|
+
* 1. Every node is either red or black
|
|
1374
|
+
* 2. Root is always black
|
|
1375
|
+
* 3. Red nodes cannot have red children
|
|
1376
|
+
* 4. Every path from a node to its null leaves
|
|
1377
|
+
* has the same number of black nodes
|
|
1378
|
+
*
|
|
1379
|
+
* Guarantees:
|
|
1380
|
+
* - O(log n) insert, delete, search
|
|
1381
|
+
*/
|
|
1382
|
+
declare class RedBlackTree<T> {
|
|
1383
|
+
private root;
|
|
1384
|
+
private compare;
|
|
1385
|
+
constructor(compareFn?: (a: T, b: T) => number);
|
|
1386
|
+
insert(value: T): void;
|
|
1387
|
+
remove(value: T): void;
|
|
1388
|
+
contains(value: T): boolean;
|
|
1389
|
+
inorder(): T[];
|
|
1390
|
+
height(): number;
|
|
1391
|
+
isEmpty(): boolean;
|
|
1392
|
+
clear(): void;
|
|
1393
|
+
private bstInsert;
|
|
1394
|
+
private fixInsert;
|
|
1395
|
+
private deleteNode;
|
|
1396
|
+
private fixDelete;
|
|
1397
|
+
private rotateLeft;
|
|
1398
|
+
private rotateRight;
|
|
1399
|
+
private transplant;
|
|
1400
|
+
private minimum;
|
|
1401
|
+
private findNode;
|
|
1402
|
+
private inorderTraverse;
|
|
1403
|
+
private calculateHeight;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
/**
|
|
1407
|
+
* SplayTree
|
|
1408
|
+
* ---------
|
|
1409
|
+
* Self-adjusting Binary Search Tree.
|
|
1410
|
+
*
|
|
1411
|
+
* Properties:
|
|
1412
|
+
* - Recently accessed elements are moved to the root
|
|
1413
|
+
* - Amortized O(log n) for insert, search, delete
|
|
1414
|
+
*
|
|
1415
|
+
* Splaying operations:
|
|
1416
|
+
* - Zig
|
|
1417
|
+
* - Zig-Zig
|
|
1418
|
+
* - Zig-Zag
|
|
1419
|
+
*/
|
|
1420
|
+
declare class SplayTree<T> {
|
|
1421
|
+
private root;
|
|
1422
|
+
private compare;
|
|
1423
|
+
constructor(compareFn?: (a: T, b: T) => number);
|
|
1424
|
+
insert(value: T): void;
|
|
1425
|
+
contains(value: T): boolean;
|
|
1426
|
+
remove(value: T): void;
|
|
1427
|
+
inorder(): T[];
|
|
1428
|
+
height(): number;
|
|
1429
|
+
isEmpty(): boolean;
|
|
1430
|
+
clear(): void;
|
|
1431
|
+
private splay;
|
|
1432
|
+
private rotateLeft;
|
|
1433
|
+
private rotateRight;
|
|
1434
|
+
private findNode;
|
|
1435
|
+
private replaceRoot;
|
|
1436
|
+
private subtreeMax;
|
|
1437
|
+
private inorderTraverse;
|
|
1438
|
+
private calculateHeight;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* BinarySearchTree
|
|
1443
|
+
* ----------------
|
|
1444
|
+
* A classic Binary Search Tree (BST) implementation.
|
|
1445
|
+
*
|
|
1446
|
+
* Properties:
|
|
1447
|
+
* - Left subtree values < node value
|
|
1448
|
+
* - Right subtree values > node value
|
|
1449
|
+
* - No duplicate values (by default)
|
|
1450
|
+
*
|
|
1451
|
+
* Time Complexity:
|
|
1452
|
+
* - Average: O(log n)
|
|
1453
|
+
* - Worst: O(n) (skewed tree)
|
|
1454
|
+
*/
|
|
1455
|
+
declare class BinarySearchTree<T> {
|
|
1456
|
+
private root;
|
|
1457
|
+
private compare;
|
|
1458
|
+
constructor(compareFn?: (a: T, b: T) => number);
|
|
1459
|
+
insert(value: T): void;
|
|
1460
|
+
contains(value: T): boolean;
|
|
1461
|
+
remove(value: T): void;
|
|
1462
|
+
inorder(): T[];
|
|
1463
|
+
preorder(): T[];
|
|
1464
|
+
postorder(): T[];
|
|
1465
|
+
min(): T | undefined;
|
|
1466
|
+
max(): T | undefined;
|
|
1467
|
+
height(): number;
|
|
1468
|
+
isEmpty(): boolean;
|
|
1469
|
+
clear(): void;
|
|
1470
|
+
private insertNode;
|
|
1471
|
+
private search;
|
|
1472
|
+
private removeNode;
|
|
1473
|
+
private inorderTraverse;
|
|
1474
|
+
private preorderTraverse;
|
|
1475
|
+
private postorderTraverse;
|
|
1476
|
+
private findMin;
|
|
1477
|
+
private findMax;
|
|
1478
|
+
private calculateHeight;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
/**
|
|
1482
|
+
* BinaryTree
|
|
1483
|
+
* ----------
|
|
1484
|
+
* A generic binary tree implementation.
|
|
1485
|
+
*
|
|
1486
|
+
* Characteristics:
|
|
1487
|
+
* - Each node has at most two children
|
|
1488
|
+
* - No ordering constraints (not a BST)
|
|
1489
|
+
* - Supports DFS & BFS traversals
|
|
1490
|
+
*/
|
|
1491
|
+
declare class TreeNode<T> {
|
|
1492
|
+
value: T;
|
|
1493
|
+
left: TreeNode<T> | null;
|
|
1494
|
+
right: TreeNode<T> | null;
|
|
1495
|
+
constructor(value: T);
|
|
1496
|
+
}
|
|
1497
|
+
declare class BinaryTree<T> {
|
|
1498
|
+
root: TreeNode<T> | null;
|
|
1499
|
+
constructor(rootValue?: T);
|
|
1500
|
+
/**
|
|
1501
|
+
* Inserts a value using level-order traversal
|
|
1502
|
+
* (keeps tree as balanced as possible)
|
|
1503
|
+
*/
|
|
1504
|
+
insert(value: T): void;
|
|
1505
|
+
inorder(): T[];
|
|
1506
|
+
preorder(): T[];
|
|
1507
|
+
postorder(): T[];
|
|
1508
|
+
levelOrder(): T[];
|
|
1509
|
+
height(): number;
|
|
1510
|
+
isEmpty(): boolean;
|
|
1511
|
+
clear(): void;
|
|
1512
|
+
private inorderTraverse;
|
|
1513
|
+
private preorderTraverse;
|
|
1514
|
+
private postorderTraverse;
|
|
1515
|
+
private calculateHeight;
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
/**
|
|
1519
|
+
* BPlusTree
|
|
1520
|
+
* ---------
|
|
1521
|
+
* B+ Tree implementation where:
|
|
1522
|
+
* - All values are stored in leaf nodes
|
|
1523
|
+
* - Internal nodes contain only keys for routing
|
|
1524
|
+
* - Leaf nodes are linked for fast range queries
|
|
1525
|
+
*
|
|
1526
|
+
* Order (t):
|
|
1527
|
+
* - Max keys per node = 2t - 1
|
|
1528
|
+
* - Min keys per non-root node = t - 1
|
|
1529
|
+
*
|
|
1530
|
+
* Time Complexity:
|
|
1531
|
+
* - Search: O(log n)
|
|
1532
|
+
* - Insert: O(log n)
|
|
1533
|
+
* - Delete: O(log n)
|
|
1534
|
+
* - Range Scan: O(log n + k)
|
|
1535
|
+
*/
|
|
1536
|
+
declare class BPlusTree<T> {
|
|
1537
|
+
private root;
|
|
1538
|
+
private readonly t;
|
|
1539
|
+
private compare;
|
|
1540
|
+
constructor(minDegree: number, compareFn?: (a: T, b: T) => number);
|
|
1541
|
+
search(key: T): boolean;
|
|
1542
|
+
insert(key: T): void;
|
|
1543
|
+
delete(key: T): void;
|
|
1544
|
+
traverse(): T[];
|
|
1545
|
+
range(from: T, to: T): T[];
|
|
1546
|
+
clear(): void;
|
|
1547
|
+
isEmpty(): boolean;
|
|
1548
|
+
private findLeaf;
|
|
1549
|
+
private insertNonFull;
|
|
1550
|
+
private splitChild;
|
|
1551
|
+
private deleteFromNode;
|
|
1552
|
+
private rebalance;
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* BTree
|
|
1557
|
+
* -----
|
|
1558
|
+
* A classic B-Tree implementation.
|
|
1559
|
+
*
|
|
1560
|
+
* Properties (minimum degree = t):
|
|
1561
|
+
* - Every node has at most 2t - 1 keys
|
|
1562
|
+
* - Every non-root node has at least t - 1 keys
|
|
1563
|
+
* - All leaves appear at the same level
|
|
1564
|
+
*
|
|
1565
|
+
* Time Complexity:
|
|
1566
|
+
* - Search: O(log n)
|
|
1567
|
+
* - Insert: O(log n)
|
|
1568
|
+
* - Delete: O(log n)
|
|
1569
|
+
*/
|
|
1570
|
+
declare class BTree<T> {
|
|
1571
|
+
private root;
|
|
1572
|
+
private readonly t;
|
|
1573
|
+
private compare;
|
|
1574
|
+
constructor(minDegree: number, compareFn?: (a: T, b: T) => number);
|
|
1575
|
+
search(key: T): boolean;
|
|
1576
|
+
insert(key: T): void;
|
|
1577
|
+
delete(key: T): void;
|
|
1578
|
+
traverse(): T[];
|
|
1579
|
+
clear(): void;
|
|
1580
|
+
isEmpty(): boolean;
|
|
1581
|
+
private searchNode;
|
|
1582
|
+
private insertNonFull;
|
|
1583
|
+
private splitChild;
|
|
1584
|
+
private deleteFromNode;
|
|
1585
|
+
private deleteInternalNode;
|
|
1586
|
+
private fill;
|
|
1587
|
+
private borrowFromPrev;
|
|
1588
|
+
private borrowFromNext;
|
|
1589
|
+
private merge;
|
|
1590
|
+
private findKey;
|
|
1591
|
+
private getPredecessor;
|
|
1592
|
+
private getSuccessor;
|
|
1593
|
+
private traverseNode;
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
/**
|
|
1597
|
+
* RadixTree (Compressed Trie / Patricia Trie)
|
|
1598
|
+
* -------------------------------------------
|
|
1599
|
+
* Optimized trie where chains of single-child nodes
|
|
1600
|
+
* are compressed into single edges.
|
|
1601
|
+
*
|
|
1602
|
+
* Use cases:
|
|
1603
|
+
* - Autocomplete
|
|
1604
|
+
* - Routing tables
|
|
1605
|
+
* - Prefix matching
|
|
1606
|
+
*
|
|
1607
|
+
* Time Complexity:
|
|
1608
|
+
* - Insert: O(n)
|
|
1609
|
+
* - Search: O(n)
|
|
1610
|
+
* - Delete: O(n)
|
|
1611
|
+
* - Prefix lookup: O(n)
|
|
1612
|
+
*/
|
|
1613
|
+
declare class RadixTree {
|
|
1614
|
+
private root;
|
|
1615
|
+
insert(word: string): void;
|
|
1616
|
+
search(word: string): boolean;
|
|
1617
|
+
startsWith(prefix: string): boolean;
|
|
1618
|
+
delete(word: string): void;
|
|
1619
|
+
clear(): void;
|
|
1620
|
+
isEmpty(): boolean;
|
|
1621
|
+
private findNode;
|
|
1622
|
+
private deleteHelper;
|
|
1623
|
+
private commonPrefix;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
/**
|
|
1627
|
+
* TernarySearchTree (TST)
|
|
1628
|
+
* ----------------------
|
|
1629
|
+
* A space-efficient string tree where each node stores
|
|
1630
|
+
* a single character and has three children:
|
|
1631
|
+
*
|
|
1632
|
+
* - left → characters less than current
|
|
1633
|
+
* - equal → next character in word
|
|
1634
|
+
* - right → characters greater than current
|
|
1635
|
+
*
|
|
1636
|
+
* Time Complexity:
|
|
1637
|
+
* - Insert: O(n)
|
|
1638
|
+
* - Search: O(n)
|
|
1639
|
+
* - Delete: O(n)
|
|
1640
|
+
* - Prefix lookup: O(n)
|
|
1641
|
+
*/
|
|
1642
|
+
declare class TernarySearchTree {
|
|
1643
|
+
private root;
|
|
1644
|
+
insert(word: string): void;
|
|
1645
|
+
search(word: string): boolean;
|
|
1646
|
+
startsWith(prefix: string): boolean;
|
|
1647
|
+
delete(word: string): void;
|
|
1648
|
+
clear(): void;
|
|
1649
|
+
isEmpty(): boolean;
|
|
1650
|
+
private insertNode;
|
|
1651
|
+
private searchNode;
|
|
1652
|
+
private deleteNode;
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
/**
|
|
1656
|
+
* Trie (Prefix Tree)
|
|
1657
|
+
* ------------------
|
|
1658
|
+
* Efficient tree-based data structure for storing strings.
|
|
1659
|
+
*
|
|
1660
|
+
* Use cases:
|
|
1661
|
+
* - Autocomplete
|
|
1662
|
+
* - Spell checking
|
|
1663
|
+
* - Prefix search
|
|
1664
|
+
*
|
|
1665
|
+
* Time Complexity:
|
|
1666
|
+
* - Insert: O(n)
|
|
1667
|
+
* - Search: O(n)
|
|
1668
|
+
* - Delete: O(n)
|
|
1669
|
+
* - Prefix lookup: O(n)
|
|
1670
|
+
*/
|
|
1671
|
+
declare class Trie {
|
|
1672
|
+
private root;
|
|
1673
|
+
insert(word: string): void;
|
|
1674
|
+
search(word: string): boolean;
|
|
1675
|
+
startsWith(prefix: string): boolean;
|
|
1676
|
+
delete(word: string): void;
|
|
1677
|
+
clear(): void;
|
|
1678
|
+
isEmpty(): boolean;
|
|
1679
|
+
private findNode;
|
|
1680
|
+
private deleteHelper;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
/**
|
|
1684
|
+
* FenwickTree (Binary Indexed Tree)
|
|
1685
|
+
* --------------------------------
|
|
1686
|
+
* Efficient data structure for prefix sums.
|
|
1687
|
+
*
|
|
1688
|
+
* Supports:
|
|
1689
|
+
* - Point update: O(log n)
|
|
1690
|
+
* - Prefix sum query: O(log n)
|
|
1691
|
+
* - Range sum query: O(log n)
|
|
1692
|
+
*
|
|
1693
|
+
* Internally uses 1-based indexing.
|
|
1694
|
+
*/
|
|
1695
|
+
declare class FenwickTree {
|
|
1696
|
+
private readonly n;
|
|
1697
|
+
private tree;
|
|
1698
|
+
constructor(sizeOrArray: number | number[]);
|
|
1699
|
+
/**
|
|
1700
|
+
* Add value to index (0-based)
|
|
1701
|
+
*/
|
|
1702
|
+
add(index: number, value: number): void;
|
|
1703
|
+
/**
|
|
1704
|
+
* Prefix sum from 0 to index (inclusive)
|
|
1705
|
+
*/
|
|
1706
|
+
sum(index: number): number;
|
|
1707
|
+
/**
|
|
1708
|
+
* Range sum [left, right]
|
|
1709
|
+
*/
|
|
1710
|
+
rangeSum(left: number, right: number): number;
|
|
1711
|
+
/**
|
|
1712
|
+
* Get size of tree
|
|
1713
|
+
*/
|
|
1714
|
+
size(): number;
|
|
1715
|
+
/**
|
|
1716
|
+
* Reset all values
|
|
1717
|
+
*/
|
|
1718
|
+
clear(): void;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
/**
|
|
1722
|
+
* IntervalTree
|
|
1723
|
+
* ------------
|
|
1724
|
+
* Augmented Binary Search Tree for interval overlap queries.
|
|
1725
|
+
*
|
|
1726
|
+
* Each node stores:
|
|
1727
|
+
* - interval [low, high]
|
|
1728
|
+
* - max: maximum high endpoint in its subtree
|
|
1729
|
+
*
|
|
1730
|
+
* Time Complexity (average):
|
|
1731
|
+
* - Insert: O(log n)
|
|
1732
|
+
* - Delete: O(log n)
|
|
1733
|
+
* - Search overlap: O(log n)
|
|
1734
|
+
* - Search all overlaps: O(k + log n)
|
|
1735
|
+
*/
|
|
1736
|
+
interface Interval {
|
|
1737
|
+
low: number;
|
|
1738
|
+
high: number;
|
|
1739
|
+
}
|
|
1740
|
+
declare class IntervalTree {
|
|
1741
|
+
private root;
|
|
1742
|
+
insert(interval: Interval): void;
|
|
1743
|
+
delete(interval: Interval): void;
|
|
1744
|
+
/**
|
|
1745
|
+
* Returns true if any interval overlaps with the query interval
|
|
1746
|
+
*/
|
|
1747
|
+
search(query: Interval): boolean;
|
|
1748
|
+
/**
|
|
1749
|
+
* Returns all intervals that overlap with the query interval
|
|
1750
|
+
*/
|
|
1751
|
+
searchAll(query: Interval): Interval[];
|
|
1752
|
+
/**
|
|
1753
|
+
* In-order traversal (sorted by low)
|
|
1754
|
+
*/
|
|
1755
|
+
traverse(): Interval[];
|
|
1756
|
+
clear(): void;
|
|
1757
|
+
isEmpty(): boolean;
|
|
1758
|
+
private insertNode;
|
|
1759
|
+
private deleteNode;
|
|
1760
|
+
private searchAny;
|
|
1761
|
+
private searchAllFrom;
|
|
1762
|
+
private overlaps;
|
|
1763
|
+
private minNode;
|
|
1764
|
+
private inOrder;
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
/**
|
|
1768
|
+
* SegmentTree
|
|
1769
|
+
* -----------
|
|
1770
|
+
* A generic segment tree implementation for range queries.
|
|
1771
|
+
*
|
|
1772
|
+
* Supports:
|
|
1773
|
+
* - Range query: O(log n)
|
|
1774
|
+
* - Point update: O(log n)
|
|
1775
|
+
*
|
|
1776
|
+
* Requirements:
|
|
1777
|
+
* - Merge function must be associative
|
|
1778
|
+
*
|
|
1779
|
+
* Examples:
|
|
1780
|
+
* - Sum: (a, b) => a + b
|
|
1781
|
+
* - Min: Math.min
|
|
1782
|
+
* - Max: Math.max
|
|
1783
|
+
*/
|
|
1784
|
+
declare class SegmentTree<T> {
|
|
1785
|
+
private tree;
|
|
1786
|
+
private data;
|
|
1787
|
+
private readonly n;
|
|
1788
|
+
private readonly merge;
|
|
1789
|
+
private readonly identity;
|
|
1790
|
+
constructor(arr: T[], mergeFn: (a: T, b: T) => T, identity: T);
|
|
1791
|
+
/**
|
|
1792
|
+
* Query range [l, r]
|
|
1793
|
+
*/
|
|
1794
|
+
query(l: number, r: number): T;
|
|
1795
|
+
/**
|
|
1796
|
+
* Update value at index
|
|
1797
|
+
*/
|
|
1798
|
+
update(index: number, value: T): void;
|
|
1799
|
+
/**
|
|
1800
|
+
* Get original array
|
|
1801
|
+
*/
|
|
1802
|
+
toArray(): T[];
|
|
1803
|
+
size(): number;
|
|
1804
|
+
private build;
|
|
1805
|
+
private queryRange;
|
|
1806
|
+
private updatePoint;
|
|
1807
|
+
}
|
|
1808
|
+
|
|
97
1809
|
declare class AppError extends Error {
|
|
98
1810
|
statusCode: number;
|
|
99
1811
|
status: string;
|
|
@@ -147,4 +1859,4 @@ declare function toMinutes(ms: number): number;
|
|
|
147
1859
|
declare function toHours(ms: number): number;
|
|
148
1860
|
declare function sleep(ms: number): Promise<void>;
|
|
149
1861
|
|
|
150
|
-
export { APIFactory, APIFeatures, APIResponse, type AllowedOriginsOptions, AppError, BaseService, type CrudService, type DatabaseConfig, GlobalErrorHandler, type LoggerOptions, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, seconds, sleep, toHours, toMinutes, toSeconds, validate };
|
|
1862
|
+
export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobConfig, AzureBlobService, BPlusTree, BTree, BaseService, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, ConsistentHash, CountMinSketch, type CrudService, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type Interval, IntervalTree, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SegmentTree, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TernarySearchTree, TreeNode, Trie, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, seconds, sleep, toHours, toMinutes, toSeconds, validate };
|