elseware-nodejs 1.0.9 → 1.1.0

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