typescript-dsa-stl 2.7.0 → 2.8.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Repository** for the npm package **[typescript-dsa-stl](https://www.npmjs.com/package/typescript-dsa-stl)** · [GitHub](https://github.com/SajidAbdullah729/TypeScript_DSA)
4
4
 
5
- STL-style data structures and algorithms for TypeScript: **Vector**, **Stack**, **Queue**, **Deque**, **List**, **PriorityQueue**, ordered/unordered **Map** and **Set**, **OrderedMultiMap** / **OrderedMultiSet**, **segment trees**, **graph** helpers (BFS, DFS, Dijkstra, Kruskal, DSU), and **string** algorithms (KMP, Rabin–Karp, rolling hash). Install from npm for your app; this repo is the source.
5
+ STL-style data structures and algorithms for TypeScript: **Vector**, **Stack**, **Queue**, **Deque**, **List**, **PriorityQueue**, ordered/unordered **Map** and **Set**, **OrderedMultiMap** / **OrderedMultiSet**, **segment trees**, **graph** helpers (BFS, DFS, topological sort, Dijkstra, Kruskal, DSU), and **string** algorithms (KMP, Rabin–Karp, rolling hash). Install from npm for your app; this repo is the source.
6
6
 
7
7
  ---
8
8
 
@@ -14,10 +14,10 @@ STL-style data structures and algorithms for TypeScript: **Vector**, **Stack**,
14
14
  | [Package layout & imports](#package-layout--imports) | Barrel vs subpaths (tree-shaking) |
15
15
  | [Quick start](#quick-start) | One file showing main APIs |
16
16
  | [API reference](#api-reference) | Export tables |
17
- | [Complexity](#complexity) | Big-O for collections and segment trees |
17
+ | [Complexity](#complexity) | Big-O for collections |
18
18
  | [Collections](#collections) | Deque, nested vectors, multi-map / multi-set |
19
- | [Segment trees](#segment-trees) | Sum/min/max, generic, lazy |
20
- | [Graph algorithms](#graph-algorithms) | Adjacency lists, BFS/DFS, components, MST, shortest paths |
19
+ | [Segment trees](#segment-trees) | Overview, variants, and examples (one section) |
20
+ | [Graph algorithms](#graph-algorithms) | Adjacency lists, BFS/DFS, topological sort, components, MST, shortest paths |
21
21
  | [String algorithms](#string-algorithms) | KMP, Rabin–Karp, rolling hash |
22
22
  | [For maintainers](#for-maintainers) | Build and publish |
23
23
  | [License](#license) | MIT |
@@ -45,6 +45,8 @@ import {
45
45
  binarySearch,
46
46
  breadthFirstSearch,
47
47
  depthFirstSearch,
48
+ topologicalSortStack,
49
+ topologicalSortIndegree,
48
50
  KnuthMorrisPratt,
49
51
  RabinKarp,
50
52
  StringRollingHash,
@@ -164,15 +166,15 @@ range(0, 5); // [0, 1, 2, 3, 4]
164
166
  | Area | Exports |
165
167
  |------|---------|
166
168
  | **Collections** | `Vector`, `Stack`, `Queue`, `Deque`, `List`, `ListNode`, `PriorityQueue`, `OrderedMap`, `UnorderedMap`, `OrderedSet`, `UnorderedSet`, `OrderedMultiMap`, `OrderedMultiSet`, `GeneralSegmentTree`, `SegmentTree`, `SegmentTreeSum`, `SegmentTreeMin`, `SegmentTreeMax`, `LazySegmentTreeSum`, `WeightedEdge`, `AdjacencyList`, `WeightedAdjacencyList`, `createAdjacencyList`, `createWeightedAdjacencyList`, `addEdge`, `deleteEdge` |
167
- | **Algorithms** | `sort`, `find`, `findIndex`, `transform`, `filter`, `reduce`, `reverse`, `unique`, `binarySearch`, `lowerBound`, `upperBound`, `min`, `max`, `partition`, `DisjointSetUnion`, `KnuthMorrisPratt`, `RabinKarp`, `RABIN_KARP_DEFAULT_MODS`, `StringRollingHash`, `breadthFirstSearch`, `depthFirstSearch`, `connectedComponents`, `kruskalMST`, `dijkstra`, `reconstructPath` |
169
+ | **Algorithms** | `sort`, `find`, `findIndex`, `transform`, `filter`, `reduce`, `reverse`, `unique`, `binarySearch`, `lowerBound`, `upperBound`, `min`, `max`, `partition`, `DisjointSetUnion`, `KnuthMorrisPratt`, `RabinKarp`, `RABIN_KARP_DEFAULT_MODS`, `StringRollingHash`, `breadthFirstSearch`, `depthFirstSearch`, `topologicalSortStack`, `topologicalSortIndegree`, `connectedComponents`, `kruskalMST`, `dijkstra`, `reconstructPath` |
168
170
  | **Utils** | `clamp`, `range`, `noop`, `identity`, `swap` |
169
- | **Types** | `Comparator`, `Predicate`, `UnaryFn`, `Reducer`, `IterableLike`, `toArray`, `RabinKarpTripleMods`, `WeightedUndirectedEdge`, `GeneralSegmentTreeConfig`, `SegmentCombine`, `SegmentMerge`, `SegmentLeafBuild` |
171
+ | **Types** | `Comparator`, `Predicate`, `UnaryFn`, `Reducer`, `IterableLike`, `toArray`, `RabinKarpTripleMods`, `WeightedUndirectedEdge`, `TopologicalSortResult`, `GeneralSegmentTreeConfig`, `SegmentCombine`, `SegmentMerge`, `SegmentLeafBuild` |
170
172
 
171
173
  ### Subpath imports (tree-shaking)
172
174
 
173
175
  ```ts
174
176
  import { Vector, Stack, Queue, Deque } from 'typescript-dsa-stl/collections';
175
- import { sort, binarySearch, breadthFirstSearch, depthFirstSearch, KnuthMorrisPratt, RabinKarp, StringRollingHash } from 'typescript-dsa-stl/algorithms';
177
+ import { sort, binarySearch, breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, KnuthMorrisPratt, RabinKarp, StringRollingHash } from 'typescript-dsa-stl/algorithms';
176
178
  import { clamp, range } from 'typescript-dsa-stl/utils';
177
179
  import type { Comparator } from 'typescript-dsa-stl/types';
178
180
  ```
@@ -201,12 +203,7 @@ import type { Comparator } from 'typescript-dsa-stl/types';
201
203
  \* Amortized (hash).
202
204
  \** At a known node.
203
205
 
204
- ### Segment trees
205
-
206
- | Structure | Build | Point update | Range query | Extra |
207
- |-----------|-------|--------------|-------------|--------|
208
- | **GeneralSegmentTree**, **SegmentTree**, **SegmentTreeSum** / **Min** / **Max** | O(n) | O(log n) | O(log n) | Inclusive `[l, r]`; **GeneralSegmentTree** keeps raw `V` and uses `merge` + `buildLeaf` |
209
- | **LazySegmentTreeSum** | O(n) | `set`: O(log n) | `rangeSum`: O(log n) | `rangeAdd` on a range: O(log n) |
206
+ Segment-tree time and space behaviour is documented in [Segment trees](#segment-trees) (overview and table at the start of that section).
210
207
 
211
208
  ---
212
209
 
@@ -330,9 +327,33 @@ for (const [key, value] of index) {
330
327
 
331
328
  ## Segment trees
332
329
 
330
+ ### Segment tree overview and complexity
331
+
332
+ A segment tree is an indexable array backed by a tree so **range questions** (sum, min, max, or your own combine) and **updates** cost **O(log n)** instead of scanning the whole slice.
333
+
333
334
  Segment trees support **range queries** and **point updates** in **O(log n)**. Range endpoints are **inclusive**: `query(l, r)` covers indices `l` through `r`.
334
335
 
335
- ### Ready-made variants (`SegmentTreeSum`, `SegmentTreeMin`, `SegmentTreeMax`)
336
+ **What each type does:**
337
+
338
+ | Type | Does |
339
+ |------|------|
340
+ | **SegmentTreeSum** / **Min** / **Max** | Fixed numeric range **sum**, **min**, or **max** with **one index updated at a time**. |
341
+ | **SegmentTree** (generic) | Your own **associative** combine over ranges; same type for array entries and node values. |
342
+ | **GeneralSegmentTree** | Array stores raw **V**, nodes hold a summary **T** built with **merge** and **buildLeaf**. |
343
+ | **LazySegmentTreeSum** | **Add the same delta to a whole range**, optional **single-cell set**, and **range sum** (lazy tags). |
344
+
345
+ | Structure | Build | Point update | Range query | Extra |
346
+ |-----------|-------|--------------|-------------|--------|
347
+ | **GeneralSegmentTree**, **SegmentTree**, **SegmentTreeSum** / **Min** / **Max** | O(n) | O(log n) | O(log n) | Inclusive `[l, r]`; **GeneralSegmentTree** keeps raw `V` and uses `merge` + `buildLeaf` |
348
+ | **LazySegmentTreeSum** | O(n) | `set`: O(log n) | `rangeSum`: O(log n) | `rangeAdd` on a range: O(log n) |
349
+
350
+ ### Segment tree: Sum, Min, Max and example
351
+
352
+ - **`SegmentTreeSum`** — answers “what is the **sum** from `l` to `r`?” after you **`update(i, value)`** on one index.
353
+ - **`SegmentTreeMin`** — answers “what is the **minimum** in `[l, r]`?” after single-index updates.
354
+ - **`SegmentTreeMax`** — answers “what is the **maximum** in `[l, r]`?” after single-index updates.
355
+
356
+ Together they are fixed numeric implementations: build from initial values, **`update(i, value)`** for one index, **`query(l, r)`** for an inclusive range.
336
357
 
337
358
  ```ts
338
359
  import {
@@ -353,9 +374,41 @@ const mx = new SegmentTreeMax([5, 2, 8, 1]);
353
374
  console.log(mx.query(0, 3)); // 8
354
375
  ```
355
376
 
356
- ### Generic `SegmentTree<T>` (custom combine + neutral)
377
+ **Example analytics / reporting (fixed buckets, range totals, single-day corrections):** each index is a **fixed bucket** (hour, day, version slot, …). You ask for the **sum** from bucket `a` through `b` and sometimes **fix one bucket** after late data or reconciliation — same API as above, wrapped for clarity.
357
378
 
358
- Use the same type for array elements and aggregates. Pass an **associative** `combine` and a **neutral** value for query ranges that miss a segment (e.g. `0` for sum, `Infinity` for min).
379
+ ```ts
380
+ import { SegmentTreeSum } from 'typescript-dsa-stl';
381
+
382
+ /** Revenue (or events, page views, API calls) per calendar day; index 0 = first day of period. */
383
+ class PeriodMetrics {
384
+ private readonly tree: SegmentTreeSum;
385
+
386
+ constructor(dailyValues: readonly number[]) {
387
+ this.tree = new SegmentTreeSum(dailyValues);
388
+ }
389
+
390
+ /** Total for an inclusive day range — e.g. chart drill-down or export row. */
391
+ totalBetweenDay(firstDayIndex: number, lastDayIndex: number): number {
392
+ return this.tree.query(firstDayIndex, lastDayIndex);
393
+ }
394
+
395
+ /** Backfill or correct one day without rebuilding the whole series. */
396
+ setDay(dayIndex: number, amount: number): void {
397
+ this.tree.update(dayIndex, amount);
398
+ }
399
+ }
400
+
401
+ const january = new PeriodMetrics([1200, 980, 1100, 1050, 1300]);
402
+ console.log(january.totalBetweenDay(0, 4)); // full period
403
+ january.setDay(2, 1150); // corrected day 2
404
+ console.log(january.totalBetweenDay(1, 3)); // sum over days 1..3
405
+ ```
406
+
407
+ In production you would usually **persist** the underlying series in a database and **rebuild** the tree when the period reloads; the tree stays useful in memory for dashboards, simulations, or request handlers that see heavy read/update traffic on the same window.
408
+
409
+ ### Generic SegmentTree
410
+
411
+ **`SegmentTree<T>`** supports range queries for **any associative operation** (gcd, concatenation, bitwise OR, …) on a fixed-length array, with **point updates**, when element type and aggregate type are the same — pass an **associative** `combine` and a **neutral** value for query ranges that miss a segment (e.g. `0` for sum, `Infinity` for min).
359
412
 
360
413
  ```ts
361
414
  import { SegmentTree } from 'typescript-dsa-stl';
@@ -385,9 +438,11 @@ const strTree = new SegmentTree<string>(
385
438
  console.log(strTree.query(0, 2)); // 'abc'
386
439
  ```
387
440
 
388
- ### `GeneralSegmentTree<T, V>` (custom merge + buildLeaf)
441
+ ### GeneralSegmentTree
389
442
 
390
- Use when **raw** values `V` differ from the **aggregate** type `T`:
443
+ **`GeneralSegmentTree<T, V>`** keeps **raw** values of type **V** in the array while each segment stores a **different** summary type **T** (e.g. raw numbers in the array, but nodes keep sums of squares or custom stats).
444
+
445
+ You supply:
391
446
 
392
447
  - **`merge(left, right)`** — combine two child aggregates (internal nodes).
393
448
  - **`neutral`** — identity for `merge` when a query does not overlap a segment.
@@ -407,9 +462,11 @@ st.update(1, 4);
407
462
  console.log(st.rawAt(1)); // 4 — current raw value at index 1
408
463
  ```
409
464
 
410
- ### `LazySegmentTreeSum` (range add + range sum)
465
+ ### LazySegmentTreeSum and example
466
+
467
+ **`LazySegmentTreeSum`** maintains a numeric array where you can **add a constant to every element in a range**, **overwrite one cell**, and query **range sums** — all in **O(log n)** via lazy propagation (unlike the trees above, which only support point updates).
411
468
 
412
- **`rangeAdd(l, r, delta)`** adds `delta` to every element in the inclusive range. **`rangeSum(l, r)`** returns the sum. **`set(i, value)`** assigns one position (lazy tags are applied along the path). All are **O(log n)**.
469
+ **`rangeAdd(l, r, delta)`** adds `delta` to every element in the inclusive range. **`rangeSum(l, r)`** returns the sum. **`set(i, value)`** assigns one position (lazy tags are applied along the path). All are **O(log n)** — see the complexity table in the overview above.
413
470
 
414
471
  ```ts
415
472
  import { LazySegmentTreeSum } from 'typescript-dsa-stl';
@@ -421,47 +478,7 @@ lazy.set(0, 100);
421
478
  console.log(lazy.rangeSum(0, 3)); // 100 + 5 + 5 + 0
422
479
  ```
423
480
 
424
- ### Real-world use cases
425
-
426
- These patterns show up in backends and internal tools when you need **many** range queries and updates on a fixed sequence (length known up front), without scanning the whole array each time.
427
-
428
- #### 1. Analytics or reporting: totals over a time window (with corrections)
429
-
430
- Each index is a **fixed bucket** (hour of day, day of month, version slot, etc.). You repeatedly ask “what is the **sum** from bucket `a` through `b`?” and sometimes **fix one bucket** after late data or a reconciliation.
431
-
432
- ```ts
433
- import { SegmentTreeSum } from 'typescript-dsa-stl';
434
-
435
- /** Revenue (or events, page views, API calls) per calendar day; index 0 = first day of period. */
436
- class PeriodMetrics {
437
- private readonly tree: SegmentTreeSum;
438
-
439
- constructor(dailyValues: readonly number[]) {
440
- this.tree = new SegmentTreeSum(dailyValues);
441
- }
442
-
443
- /** Total for an inclusive day range — e.g. chart drill-down or export row. */
444
- totalBetweenDay(firstDayIndex: number, lastDayIndex: number): number {
445
- return this.tree.query(firstDayIndex, lastDayIndex);
446
- }
447
-
448
- /** Backfill or correct one day without rebuilding the whole series. */
449
- setDay(dayIndex: number, amount: number): void {
450
- this.tree.update(dayIndex, amount);
451
- }
452
- }
453
-
454
- const january = new PeriodMetrics([1200, 980, 1100, 1050, 1300]);
455
- console.log(january.totalBetweenDay(0, 4)); // full period
456
- january.setDay(2, 1150); // corrected day 2
457
- console.log(january.totalBetweenDay(1, 3)); // sum over days 1..3
458
- ```
459
-
460
- In production you would usually **persist** the underlying series in a database and **rebuild** the tree when the period reloads; the tree stays useful in memory for dashboards, simulations, or request handlers that see heavy read/update traffic on the same window.
461
-
462
- #### 2. Operations or finance: bulk adjustment on a slice, then aggregate
463
-
464
- You apply the **same delta** to **every** element in an index range (tiered bonuses, prorated credits, simulation shocks), then need **range sums** for reporting. A lazy sum tree avoids touching each cell one by one.
481
+ **Example bulk adjustment on a slice, then aggregate:** apply the **same delta** to **every** element in an index range (bonuses, prorated credits, simulation shocks), then query **range sums** without updating each cell one by one.
465
482
 
466
483
  ```ts
467
484
  import { LazySegmentTreeSum } from 'typescript-dsa-stl';
@@ -646,6 +663,117 @@ console.log(breadthFirstSearch(5, withIsolated, 0)); // [0, 1] — not [0,1,2,3,
646
663
  - **Disconnected graphs:** run again from another unvisited `start`, or use `connectedComponents` to enumerate components first.
647
664
  - **Weighted graphs:** for traversal ignoring weights, use the same vertex lists as the unweighted graph (weights are ignored by these two functions).
648
665
 
666
+ ### Topological sort
667
+
668
+ `topologicalSortStack` (iterative DFS / finish order) and `topologicalSortIndegree` (Kahn’s algorithm, zero-indegree queue) both take `n` and a **directed** unweighted `AdjacencyList`. They return `{ order, ok }`: a permutation of `0..n-1` when `ok` is true, or failure when a directed cycle exists.
669
+
670
+ **When to use**
671
+
672
+ - **Task / build / dependency ordering:** items must happen only after their prerequisites (package install order, compile steps, course prerequisites).
673
+ - **Scheduling under precedence constraints:** jobs with “A before B” rules and no cycles.
674
+ - **Detecting cycles in a directed model:** if `ok` is false, the graph (on valid vertices `0..n-1`) is not a DAG.
675
+ - **Pick either algorithm:** both answer the same yes/no; choose **stack** if you want DFS-style behavior and an explicit stack; choose **indegree** (Kahn) if you prefer peeling sources level-by-level (often closer to “ready queue” mental models).
676
+
677
+ **When topological order is not possible**
678
+
679
+ - Any **directed cycle** (including a **self-loop**): `ok` is false.
680
+ - **Undirected** graphs modeled with **both** `u → v` and `v → u`: that is a 2-cycle, so **not** a DAG unless you only use directed edges that reflect real precedence.
681
+
682
+ **Example (how to call it and use the result)**
683
+
684
+ Both functions return the same shape: **`TopologicalSortResult`** — `{ order: number[]; ok: boolean }`.
685
+
686
+ - **`ok === true`:** `order` is a **permutation of `0..n-1`**; every edge `u → v` appears with `u` before `v` in `order`.
687
+ - **`ok === false`:** **no** full topological order exists (directed cycle). For `topologicalSortStack`, `order` is `[]`. For `topologicalSortIndegree`, `order` may list only some vertices; **do not** treat it as a complete sort.
688
+
689
+ ```ts
690
+ import {
691
+ createAdjacencyList,
692
+ addEdge,
693
+ topologicalSortStack,
694
+ topologicalSortIndegree,
695
+ type TopologicalSortResult,
696
+ } from 'typescript-dsa-stl';
697
+
698
+ const n = 4;
699
+ const g = createAdjacencyList(n);
700
+ addEdge(g, 0, 1);
701
+ addEdge(g, 0, 2);
702
+ addEdge(g, 1, 3);
703
+ addEdge(g, 2, 3);
704
+
705
+ // Whole result (typed)
706
+ const result: TopologicalSortResult = topologicalSortStack(n, g);
707
+
708
+ // Usually destructure
709
+ const { order, ok } = topologicalSortIndegree(n, g);
710
+
711
+ if (ok) {
712
+ // `order` here is from `topologicalSortIndegree` above → [0, 1, 2, 3] for this graph.
713
+
714
+ // 1) See the whole sequence at once
715
+ console.log(order);
716
+ // → [ 0, 1, 2, 3 ] (Node.js / browser consoles may add line breaks or “Array(4)” styling)
717
+
718
+ // 2) How many steps (same as n when ok is true)
719
+ console.log(order.length);
720
+ // → 4
721
+
722
+ // 3) Pick by position: first task, second task, …
723
+ const first = order[0];
724
+ const second = order[1];
725
+ console.log('do vertex', first, 'before', second);
726
+ // → do vertex 0 before 1
727
+
728
+ // 4) Simple loop with indices
729
+ for (let i = 0; i < order.length; i++) {
730
+ console.log('step', i + 1, '→ vertex', order[i]);
731
+ }
732
+ // → step 1 → vertex 0
733
+ // → step 2 → vertex 1
734
+ // → step 3 → vertex 2
735
+ // → step 4 → vertex 3
736
+
737
+ // 5) Same loop, shorter (when you only need the vertex id)
738
+ for (const vertex of order) {
739
+ console.log('run job for vertex', vertex);
740
+ }
741
+ // → run job for vertex 0
742
+ // → run job for vertex 1
743
+ // → run job for vertex 2
744
+ // → run job for vertex 3
745
+
746
+ // 6) Optional: each number is an index into your own list of names
747
+ const jobNames = ['bootstrap', 'compileA', 'compileB', 'link'];
748
+ const readable = order.map((vertex) => jobNames[vertex]);
749
+ console.log(readable.join(' → '));
750
+ // → bootstrap → compileA → compileB → link
751
+ } else {
752
+ // No valid order exists (cycle). Use a flag, return early, or show an error.
753
+ console.error('Graph has a cycle; cannot topologically sort.');
754
+ // → Graph has a cycle; cannot topologically sort.
755
+ // (often printed on stderr; some runtimes prepend “Error” styling)
756
+ }
757
+
758
+ // Compare algorithms (same `ok` on a given graph; `order` may differ)
759
+ const a = topologicalSortStack(n, g);
760
+ const b = topologicalSortIndegree(n, g);
761
+ console.log(a.ok, b.ok);
762
+ // → true true
763
+ // (here `a.order` is [0, 2, 1, 3] and `b.order` is [0, 1, 2, 3] — both valid)
764
+
765
+ // Cycle: 0 → 1 → 2 → 0
766
+ const cyclic = createAdjacencyList(3);
767
+ addEdge(cyclic, 0, 1);
768
+ addEdge(cyclic, 1, 2);
769
+ addEdge(cyclic, 2, 0);
770
+ const bad = topologicalSortStack(3, cyclic);
771
+ console.log(bad.ok);
772
+ // → false
773
+ console.log(bad.order);
774
+ // → []
775
+ ```
776
+
649
777
  ### Disjoint Set Union (Union-Find)
650
778
 
651
779
  Use Union-Find (DSU) to compute connected components efficiently. It merges endpoints of every edge in the adjacency list, so for directed graphs it returns weak connectivity components.
@@ -21,6 +21,55 @@ export declare function breadthFirstSearch(n: number, adj: AdjacencyList<number>
21
21
  * - Neighbors are explored in the order they appear in `adj[u]` (first neighbor in the list is visited first).
22
22
  */
23
23
  export declare function depthFirstSearch(n: number, adj: AdjacencyList<number>, start: number): number[];
24
+ /**
25
+ * Result of a topological sort attempt on vertices `0..n-1`.
26
+ *
27
+ * **When sorting is impossible:** classical topological order exists only for a **directed acyclic graph (DAG)**.
28
+ * If the graph has any **directed cycle** (including a **self-loop**), both algorithms set `ok` to `false`.
29
+ * Treating an **undirected** edge as two opposite directed arcs creates a 2-cycle, so `ok` will be `false`
30
+ * unless there are no such pairs (e.g. only isolated vertices).
31
+ *
32
+ * **Input:** You must pass **`n` and `adj` together** — `n` is the number of vertices, and `adj[u]` lists **out-neighbors**
33
+ * of `u` for a **directed** graph. Missing `adj[u]` is treated as no outgoing edges. Neighbors outside `0..n-1` are **ignored**,
34
+ * so the result reflects that pruned graph, not raw adjacency data with invalid indices.
35
+ */
36
+ export interface TopologicalSortResult {
37
+ /** A permutation of `0..n-1` with every edge `u → v` having `u` before `v` (only valid when `ok` is true). */
38
+ order: number[];
39
+ /** `true` iff a topological order exists for the directed graph on `0..n-1` after ignoring invalid neighbors. */
40
+ ok: boolean;
41
+ }
42
+ /**
43
+ * Topological ordering of a **directed** graph using an explicit stack (iterative DFS / finish times).
44
+ * Pushes a vertex after all its outgoing edges have been explored, then reverses that list.
45
+ *
46
+ * Complexity: O(n + m) time, O(n) extra space.
47
+ *
48
+ * **Inputs:** Same as other graph helpers: vertex count `n` and unweighted `adj` (outgoing edges only). This pair **is** the
49
+ * graph representation here; there is no separate graph object. Keep `n` consistent with how many vertices you number (`0..n-1`).
50
+ *
51
+ * **Not possible:** Returns `{ order: [], ok: false }` if a directed cycle is found (self-loop, longer cycle, or bidirectional
52
+ * undirected modeling). Returns `{ order, ok: true }` for any DAG, including disconnected ones.
53
+ *
54
+ * - Invalid neighbor indices are skipped (see {@link TopologicalSortResult}).
55
+ * - Parallel edges behave like multiple arcs; self-loops are cycles.
56
+ */
57
+ export declare function topologicalSortStack(n: number, adj: AdjacencyList<number>): TopologicalSortResult;
58
+ /**
59
+ * Topological ordering via **Kahn's algorithm**: repeatedly remove vertices with indegree zero (BFS-style).
60
+ * Uses only indegrees derived from `adj`; outdegree is implicit in the lists.
61
+ *
62
+ * Complexity: O(n + m) time, O(n) extra space.
63
+ *
64
+ * **Inputs:** Requires `n` and `adj` together (directed out-edges per vertex), like {@link topologicalSortStack}.
65
+ *
66
+ * **Not possible:** `ok` is `false` when not all vertices are output — equivalently, when the graph on `0..n-1` (after ignoring
67
+ * invalid neighbors) contains a directed cycle. On failure, `order` lists some vertices in a valid partial order but must not
68
+ * be treated as a full topological sort.
69
+ *
70
+ * - When `ok` is `true`, `order` is one valid topological order; it may differ from the stack/DFS-based order.
71
+ */
72
+ export declare function topologicalSortIndegree(n: number, adj: AdjacencyList<number>): TopologicalSortResult;
24
73
  export interface WeightedUndirectedEdge {
25
74
  u: number;
26
75
  v: number;
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/algorithms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E,aAAa,CAAC,MAAM,CAAC,GACzB,MAAM,EAAE,EAAE,CAQZ;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1C,OAAO,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GACjC;IAAE,KAAK,EAAE,sBAAsB,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAgC1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CACtB,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1C,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAmCpC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,MAAM,EAAE,CAgBV"}
@@ -62,6 +62,101 @@ export function depthFirstSearch(n, adj, start) {
62
62
  }
63
63
  return order;
64
64
  }
65
+ /**
66
+ * Topological ordering of a **directed** graph using an explicit stack (iterative DFS / finish times).
67
+ * Pushes a vertex after all its outgoing edges have been explored, then reverses that list.
68
+ *
69
+ * Complexity: O(n + m) time, O(n) extra space.
70
+ *
71
+ * **Inputs:** Same as other graph helpers: vertex count `n` and unweighted `adj` (outgoing edges only). This pair **is** the
72
+ * graph representation here; there is no separate graph object. Keep `n` consistent with how many vertices you number (`0..n-1`).
73
+ *
74
+ * **Not possible:** Returns `{ order: [], ok: false }` if a directed cycle is found (self-loop, longer cycle, or bidirectional
75
+ * undirected modeling). Returns `{ order, ok: true }` for any DAG, including disconnected ones.
76
+ *
77
+ * - Invalid neighbor indices are skipped (see {@link TopologicalSortResult}).
78
+ * - Parallel edges behave like multiple arcs; self-loops are cycles.
79
+ */
80
+ export function topologicalSortStack(n, adj) {
81
+ const state = new Uint8Array(n); // 0 = unvisited, 1 = on stack (visiting), 2 = done
82
+ const finish = [];
83
+ const stack = [];
84
+ for (let s = 0; s < n; s++) {
85
+ if (state[s] !== 0)
86
+ continue;
87
+ state[s] = 1;
88
+ stack.push({ u: s, i: 0 });
89
+ while (stack.length > 0) {
90
+ const top = stack[stack.length - 1];
91
+ const u = top.u;
92
+ const neighbors = adj[u] ?? [];
93
+ let pushedChild = false;
94
+ while (top.i < neighbors.length) {
95
+ const v = neighbors[top.i];
96
+ top.i++;
97
+ if (v < 0 || v >= n)
98
+ continue;
99
+ if (state[v] === 1)
100
+ return { order: [], ok: false };
101
+ if (state[v] === 0) {
102
+ state[v] = 1;
103
+ stack.push({ u: v, i: 0 });
104
+ pushedChild = true;
105
+ break;
106
+ }
107
+ }
108
+ if (!pushedChild) {
109
+ stack.pop();
110
+ state[u] = 2;
111
+ finish.push(u);
112
+ }
113
+ }
114
+ }
115
+ finish.reverse();
116
+ return { order: finish, ok: true };
117
+ }
118
+ /**
119
+ * Topological ordering via **Kahn's algorithm**: repeatedly remove vertices with indegree zero (BFS-style).
120
+ * Uses only indegrees derived from `adj`; outdegree is implicit in the lists.
121
+ *
122
+ * Complexity: O(n + m) time, O(n) extra space.
123
+ *
124
+ * **Inputs:** Requires `n` and `adj` together (directed out-edges per vertex), like {@link topologicalSortStack}.
125
+ *
126
+ * **Not possible:** `ok` is `false` when not all vertices are output — equivalently, when the graph on `0..n-1` (after ignoring
127
+ * invalid neighbors) contains a directed cycle. On failure, `order` lists some vertices in a valid partial order but must not
128
+ * be treated as a full topological sort.
129
+ *
130
+ * - When `ok` is `true`, `order` is one valid topological order; it may differ from the stack/DFS-based order.
131
+ */
132
+ export function topologicalSortIndegree(n, adj) {
133
+ const indeg = new Uint32Array(n);
134
+ for (let u = 0; u < n; u++) {
135
+ for (const v of adj[u] ?? []) {
136
+ if (v >= 0 && v < n)
137
+ indeg[v]++;
138
+ }
139
+ }
140
+ const q = [];
141
+ for (let i = 0; i < n; i++) {
142
+ if (indeg[i] === 0)
143
+ q.push(i);
144
+ }
145
+ const order = [];
146
+ let qh = 0;
147
+ while (qh < q.length) {
148
+ const u = q[qh++];
149
+ order.push(u);
150
+ for (const v of adj[u] ?? []) {
151
+ if (v < 0 || v >= n)
152
+ continue;
153
+ indeg[v]--;
154
+ if (indeg[v] === 0)
155
+ q.push(v);
156
+ }
157
+ }
158
+ return { order, ok: order.length === n };
159
+ }
65
160
  /**
66
161
  * Connected components in an (unweighted) graph using DSU.
67
162
  * Complexity: O((n + m) * alpha(n)).
@@ -1 +1 @@
1
- {"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/algorithms/graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,CAAS,EACT,GAA0B,EAC1B,KAAa;IAEb,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACvC,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,CAAC,GAAa,EAAE,CAAC;IACvB,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACd,OAAO,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;QACrB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAE,CAAC;QACnB,KAAK,CAAC,IAAI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,GAAG,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACjD,IAAI,MAAM,GAAG,CAAC,IAAI,MAAM,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACnD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAErC,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,IAAI,CAAC,GAAG,MAAM,CAAC;IACf,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACjD,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,KAAK;YAAE,MAAM;QACvB,CAAC,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;QACb,IAAI,CAAC,KAAK,CAAC,CAAC;YAAE,OAAO,EAAE,CAAC;IAC1B,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,KAAK;QAAE,OAAO,EAAE,CAAC;IAC/C,IAAI,CAAC,OAAO,EAAE,CAAC;IACf,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -4,6 +4,6 @@ export { KnuthMorrisPratt } from './kmp.js';
4
4
  export { StringRollingHash } from './stringHashing.js';
5
5
  export { RabinKarp, RABIN_KARP_DEFAULT_MODS } from './rabinKarp.js';
6
6
  export type { RabinKarpTripleMods } from './rabinKarp.js';
7
- export type { WeightedUndirectedEdge } from './graph.js';
8
- export { breadthFirstSearch, depthFirstSearch, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './graph.js';
7
+ export type { WeightedUndirectedEdge, TopologicalSortResult } from './graph.js';
8
+ export { breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './graph.js';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/algorithms/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACpE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/algorithms/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACpE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC"}
@@ -3,5 +3,5 @@ export { DisjointSetUnion } from './disjointSetUnion.js';
3
3
  export { KnuthMorrisPratt } from './kmp.js';
4
4
  export { StringRollingHash } from './stringHashing.js';
5
5
  export { RabinKarp, RABIN_KARP_DEFAULT_MODS } from './rabinKarp.js';
6
- export { breadthFirstSearch, depthFirstSearch, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './graph.js';
6
+ export { breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './graph.js';
7
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/algorithms/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAGpE,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/algorithms/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAGpE,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC"}
package/dist/index.d.ts CHANGED
@@ -7,8 +7,8 @@
7
7
  */
8
8
  export { Vector, Stack, Queue, Deque, List, ListNode, PriorityQueue, OrderedMap, UnorderedMap, OrderedSet, UnorderedSet, OrderedMultiSet, OrderedMultiMap, addEdge, deleteEdge, createAdjacencyList, createWeightedAdjacencyList, GeneralSegmentTree, SegmentTree, SegmentTreeSum, SegmentTreeMin, SegmentTreeMax, LazySegmentTreeSum, } from './collections/index.js';
9
9
  export type { WeightedEdge, AdjacencyList, WeightedAdjacencyList, GeneralSegmentTreeConfig, SegmentCombine, SegmentLeafBuild, SegmentMerge, } from './collections/index.js';
10
- export { sort, find, findIndex, transform, filter, reduce, reverse, unique, binarySearch, lowerBound, upperBound, min, max, partition, DisjointSetUnion, KnuthMorrisPratt, StringRollingHash, RabinKarp, RABIN_KARP_DEFAULT_MODS, breadthFirstSearch, depthFirstSearch, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './algorithms/index.js';
11
- export type { WeightedUndirectedEdge, RabinKarpTripleMods } from './algorithms/index.js';
10
+ export { sort, find, findIndex, transform, filter, reduce, reverse, unique, binarySearch, lowerBound, upperBound, min, max, partition, DisjointSetUnion, KnuthMorrisPratt, StringRollingHash, RabinKarp, RABIN_KARP_DEFAULT_MODS, breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './algorithms/index.js';
11
+ export type { WeightedUndirectedEdge, RabinKarpTripleMods, TopologicalSortResult, } from './algorithms/index.js';
12
12
  export { clamp, range, noop, identity, swap } from './utils/index.js';
13
13
  export type { Comparator, Predicate, UnaryFn, Reducer, IterableLike } from './types/index.js';
14
14
  export { toArray } from './types/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,EACf,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,wBAAwB,EACxB,cAAc,EACd,gBAAgB,EAChB,YAAY,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACtE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,EACf,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,wBAAwB,EACxB,cAAc,EACd,gBAAgB,EAChB,YAAY,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACtE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * import { Vector, Stack, Queue, List, sort, binarySearch, clamp } from 'typescript-dsa-stl';
7
7
  */
8
8
  export { Vector, Stack, Queue, Deque, List, ListNode, PriorityQueue, OrderedMap, UnorderedMap, OrderedSet, UnorderedSet, OrderedMultiSet, OrderedMultiMap, addEdge, deleteEdge, createAdjacencyList, createWeightedAdjacencyList, GeneralSegmentTree, SegmentTree, SegmentTreeSum, SegmentTreeMin, SegmentTreeMax, LazySegmentTreeSum, } from './collections/index.js';
9
- export { sort, find, findIndex, transform, filter, reduce, reverse, unique, binarySearch, lowerBound, upperBound, min, max, partition, DisjointSetUnion, KnuthMorrisPratt, StringRollingHash, RabinKarp, RABIN_KARP_DEFAULT_MODS, breadthFirstSearch, depthFirstSearch, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './algorithms/index.js';
9
+ export { sort, find, findIndex, transform, filter, reduce, reverse, unique, binarySearch, lowerBound, upperBound, min, max, partition, DisjointSetUnion, KnuthMorrisPratt, StringRollingHash, RabinKarp, RABIN_KARP_DEFAULT_MODS, breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './algorithms/index.js';
10
10
  export { clamp, range, noop, identity, swap } from './utils/index.js';
11
11
  export { toArray } from './types/index.js';
12
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,EACf,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAUhC,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,EACf,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAUhC,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-dsa-stl",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "description": "STL-style data structures and algorithms for TypeScript: Vector, Stack, Queue, Deque (double-ended queue), List, PriorityQueue, Map, Set, sort, binarySearch, graph utilities. Use like C++ STL.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -54,6 +54,7 @@
54
54
  "queue",
55
55
  "deque",
56
56
  "double-ended-queue",
57
+ "graph",
57
58
  "list",
58
59
  "priority-queue",
59
60
  "map",