typescript-dsa-stl 2.0.0 → 2.0.2
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 +41 -42
- package/dist/collections/Graph.d.ts +61 -0
- package/dist/collections/Graph.d.ts.map +1 -0
- package/dist/collections/Graph.js +52 -0
- package/dist/collections/Graph.js.map +1 -0
- package/dist/collections/index.d.ts +2 -0
- package/dist/collections/index.d.ts.map +1 -1
- package/dist/collections/index.js +1 -0
- package/dist/collections/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +0 -50
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -30
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -144,9 +144,9 @@ cube.push(layer0);
|
|
|
144
144
|
cube.at(0).at(1).at(0); // 3 (layer 0, row 1, col 0)
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
### Graph adjacency
|
|
147
|
+
### Graph adjacency list (like C++ `vector<vector<type>> graph(n)`)
|
|
148
148
|
|
|
149
|
-
You can model C++-style adjacency lists using the graph
|
|
149
|
+
You can model C++-style adjacency lists using the graph types and helpers exported from `typescript-dsa-stl/collections` (or the main package).
|
|
150
150
|
|
|
151
151
|
#### Unweighted adjacency list
|
|
152
152
|
|
|
@@ -154,39 +154,36 @@ C++:
|
|
|
154
154
|
|
|
155
155
|
```cpp
|
|
156
156
|
int n = 5;
|
|
157
|
-
vector<vector<int>>
|
|
158
|
-
|
|
157
|
+
vector<vector<int>> graph(n);
|
|
158
|
+
graph[u].push_back(v); // or graph[u].pb(v);
|
|
159
159
|
```
|
|
160
160
|
|
|
161
|
-
TypeScript (
|
|
161
|
+
TypeScript (easy declaration with `createAdjacencyList`):
|
|
162
162
|
|
|
163
163
|
```ts
|
|
164
|
-
import
|
|
164
|
+
import { createAdjacencyList } from 'typescript-dsa-stl/collections';
|
|
165
165
|
|
|
166
166
|
const n = 5;
|
|
167
|
-
|
|
168
|
-
const adj: AdjacencyList<number> = Array.from({ length: n }, () => []);
|
|
167
|
+
const graph = createAdjacencyList(n); // empty graph with n vertices
|
|
169
168
|
|
|
170
|
-
// C++:
|
|
171
|
-
|
|
169
|
+
// C++: graph[u].push_back(v);
|
|
170
|
+
graph[u].push(v);
|
|
172
171
|
|
|
173
172
|
// Iteration is the same idea as in C++
|
|
174
|
-
for (const v of
|
|
173
|
+
for (const v of graph[u]) {
|
|
175
174
|
// neighbor v
|
|
176
175
|
}
|
|
177
176
|
```
|
|
178
177
|
|
|
179
|
-
|
|
178
|
+
Or with helpers `addEdge` / `deleteEdge`:
|
|
180
179
|
|
|
181
180
|
```ts
|
|
182
|
-
import
|
|
183
|
-
import { addEdge, deleteEdge } from 'typescript-dsa-stl/types';
|
|
181
|
+
import { createAdjacencyList, addEdge, deleteEdge } from 'typescript-dsa-stl/collections';
|
|
184
182
|
|
|
185
|
-
const
|
|
186
|
-
const adj: AdjacencyList<number> = Array.from({ length: n }, () => []);
|
|
183
|
+
const graph = createAdjacencyList(5);
|
|
187
184
|
|
|
188
|
-
addEdge(
|
|
189
|
-
deleteEdge(
|
|
185
|
+
addEdge(graph, u, v); // add u -> v
|
|
186
|
+
deleteEdge(graph, u, v); // remove all edges u -> v
|
|
190
187
|
```
|
|
191
188
|
|
|
192
189
|
#### Weighted adjacency list
|
|
@@ -195,58 +192,60 @@ In C++ you might write:
|
|
|
195
192
|
|
|
196
193
|
```cpp
|
|
197
194
|
int n = 5;
|
|
198
|
-
vector<vector<pair<int,int>>>
|
|
199
|
-
|
|
195
|
+
vector<vector<pair<int,int>>> graph(n);
|
|
196
|
+
graph[u].push_back({v, w}); // edge u -> v with weight w
|
|
200
197
|
```
|
|
201
198
|
|
|
202
|
-
In TypeScript, use `
|
|
199
|
+
In TypeScript, use `createWeightedAdjacencyList` for easy declaration:
|
|
203
200
|
|
|
204
201
|
```ts
|
|
205
|
-
import
|
|
206
|
-
WeightedEdge,
|
|
207
|
-
WeightedAdjacencyList,
|
|
208
|
-
} from 'typescript-dsa-stl/types';
|
|
202
|
+
import { createWeightedAdjacencyList } from 'typescript-dsa-stl/collections';
|
|
209
203
|
|
|
210
204
|
const n = 5;
|
|
211
|
-
const
|
|
212
|
-
Array.from({ length: n }, () => []);
|
|
205
|
+
const graph = createWeightedAdjacencyList(n); // empty weighted graph with n vertices
|
|
213
206
|
|
|
214
|
-
// C++:
|
|
215
|
-
|
|
207
|
+
// C++: graph[u].push_back({v, w});
|
|
208
|
+
graph[u].push({ to: v, weight: w });
|
|
216
209
|
|
|
217
210
|
// When iterating, you get both neighbor and weight
|
|
218
|
-
for (const { to, weight } of
|
|
211
|
+
for (const { to, weight } of graph[u]) {
|
|
219
212
|
// edge u -> to with cost = weight
|
|
220
213
|
}
|
|
221
|
-
|
|
222
|
-
// If you prefer a different vertex or weight type, just change the generics:
|
|
223
|
-
// const adj: WeightedAdjacencyList<string, bigint> = ...
|
|
224
214
|
```
|
|
225
215
|
|
|
226
216
|
Or with the helper functions `addEdge` / `deleteEdge`:
|
|
227
217
|
|
|
228
218
|
```ts
|
|
229
|
-
import
|
|
230
|
-
import { addEdge, deleteEdge } from 'typescript-dsa-stl/types';
|
|
219
|
+
import { createWeightedAdjacencyList, addEdge, deleteEdge } from 'typescript-dsa-stl/collections';
|
|
231
220
|
|
|
232
|
-
const
|
|
233
|
-
const adj: WeightedAdjacencyList<number, number> =
|
|
234
|
-
Array.from({ length: n }, () => []);
|
|
221
|
+
const graph = createWeightedAdjacencyList(5);
|
|
235
222
|
|
|
236
|
-
addEdge(
|
|
237
|
-
deleteEdge(
|
|
223
|
+
addEdge(graph, u, v, w); // add u -> v with weight w
|
|
224
|
+
deleteEdge(graph, u, v, w); // delete all edges u -> v with weight w
|
|
238
225
|
```
|
|
239
226
|
|
|
227
|
+
#### Graph adjacency list — use cases
|
|
228
|
+
|
|
229
|
+
Use an **unweighted** graph (adjacency list) when you only care about connectivity; use a **weighted** graph when edges have costs (distance, time, capacity).
|
|
230
|
+
|
|
231
|
+
| Use case | When to use |
|
|
232
|
+
|----------|-------------|
|
|
233
|
+
| **BFS / DFS, connectivity** | Unweighted: shortest path in terms of hop count, connected components, cycle detection. |
|
|
234
|
+
| **Shortest path (Dijkstra), MST** | Weighted: edge weights as distances or costs; run Dijkstra, Prim, or Kruskal on the list. |
|
|
235
|
+
| **Social / dependency graphs** | Unweighted or weighted: followers, dependencies (e.g. build order), recommendation graphs. |
|
|
236
|
+
| **Grid / game graphs** | Unweighted: 4- or 8-neighbor grids; weighted if movement costs differ per cell. |
|
|
237
|
+
| **Network / flow** | Weighted: capacities or latencies on edges for max-flow or routing. |
|
|
238
|
+
|
|
240
239
|
---
|
|
241
240
|
|
|
242
241
|
## API overview
|
|
243
242
|
|
|
244
243
|
| Module | Exports |
|
|
245
244
|
|--------|--------|
|
|
246
|
-
| **Collections** | `Vector`, `Stack`, `Queue`, `List`, `ListNode`, `PriorityQueue`, `OrderedMap`, `UnorderedMap`, `OrderedSet`, `UnorderedSet`, `OrderedMultiMap`, `OrderedMultiSet` |
|
|
245
|
+
| **Collections** | `Vector`, `Stack`, `Queue`, `List`, `ListNode`, `PriorityQueue`, `OrderedMap`, `UnorderedMap`, `OrderedSet`, `UnorderedSet`, `OrderedMultiMap`, `OrderedMultiSet`, `WeightedEdge`, `AdjacencyList`, `WeightedAdjacencyList`, `createAdjacencyList`, `createWeightedAdjacencyList`, `addEdge`, `deleteEdge` |
|
|
247
246
|
| **Algorithms** | `sort`, `find`, `findIndex`, `transform`, `filter`, `reduce`, `reverse`, `unique`, `binarySearch`, `lowerBound`, `upperBound`, `min`, `max`, `partition` |
|
|
248
247
|
| **Utils** | `clamp`, `range`, `noop`, `identity`, `swap` |
|
|
249
|
-
| **Types** | `Comparator`, `Predicate`, `UnaryFn`, `Reducer`, `IterableLike`, `toArray
|
|
248
|
+
| **Types** | `Comparator`, `Predicate`, `UnaryFn`, `Reducer`, `IterableLike`, `toArray` |
|
|
250
249
|
|
|
251
250
|
### Subpath imports (tree-shaking)
|
|
252
251
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph adjacency list helpers (C++-style).
|
|
3
|
+
*
|
|
4
|
+
* These are designed so you can mirror common C++ patterns like:
|
|
5
|
+
* vector<vector<int>> adj(n);
|
|
6
|
+
* vector<vector<pair<int,int>>> adj(n);
|
|
7
|
+
*/
|
|
8
|
+
/** Single weighted edge: `to` vertex with a `weight`. */
|
|
9
|
+
export interface WeightedEdge<Vertex = number, Weight = number> {
|
|
10
|
+
to: Vertex;
|
|
11
|
+
weight: Weight;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Unweighted adjacency list.
|
|
15
|
+
*
|
|
16
|
+
* C++: `vector<vector<int>> adj(n);`
|
|
17
|
+
* TS: `AdjacencyList<number>` (backed by `number[][]`).
|
|
18
|
+
*/
|
|
19
|
+
export type AdjacencyList<Vertex = number> = Vertex[][];
|
|
20
|
+
/**
|
|
21
|
+
* Weighted adjacency list.
|
|
22
|
+
*
|
|
23
|
+
* C++: `vector<vector<pair<int,int>>> adj(n);`
|
|
24
|
+
* TS: `WeightedAdjacencyList<number, number>`
|
|
25
|
+
* (backed by `WeightedEdge<number, number>[][]`).
|
|
26
|
+
*
|
|
27
|
+
* Typical use:
|
|
28
|
+
* const adj: WeightedAdjacencyList<number, number> =
|
|
29
|
+
* Array.from({ length: n }, () => []);
|
|
30
|
+
* adj[u].push({ to: v, weight: w });
|
|
31
|
+
*/
|
|
32
|
+
export type WeightedAdjacencyList<Vertex = number, Weight = number> = WeightedEdge<Vertex, Weight>[][];
|
|
33
|
+
/**
|
|
34
|
+
* Create an empty unweighted graph with `n` vertices (0..n-1).
|
|
35
|
+
* Equivalent to C++: `vector<vector<int>> graph(n);`
|
|
36
|
+
*/
|
|
37
|
+
export declare function createAdjacencyList(n: number): AdjacencyList<number>;
|
|
38
|
+
/**
|
|
39
|
+
* Create an empty weighted graph with `n` vertices (0..n-1).
|
|
40
|
+
* Equivalent to C++: `vector<vector<pair<int,int>>> graph(n);`
|
|
41
|
+
*/
|
|
42
|
+
export declare function createWeightedAdjacencyList(n: number): WeightedAdjacencyList<number, number>;
|
|
43
|
+
/**
|
|
44
|
+
* Add an edge to a graph adjacency list.
|
|
45
|
+
*
|
|
46
|
+
* Overloads:
|
|
47
|
+
* - Unweighted: addEdge(adj, u, v)
|
|
48
|
+
* - Weighted: addEdge(adj, u, v, w)
|
|
49
|
+
*/
|
|
50
|
+
export declare function addEdge(adj: AdjacencyList<number>, u: number, v: number): void;
|
|
51
|
+
export declare function addEdge(adj: WeightedAdjacencyList<number, number>, u: number, v: number, w: number): void;
|
|
52
|
+
/**
|
|
53
|
+
* Delete all edges u -> v from a graph adjacency list.
|
|
54
|
+
*
|
|
55
|
+
* Overloads:
|
|
56
|
+
* - Unweighted: deleteEdge(adj, u, v)
|
|
57
|
+
* - Weighted: deleteEdge(adj, u, v, w)
|
|
58
|
+
*/
|
|
59
|
+
export declare function deleteEdge(adj: AdjacencyList<number>, u: number, v: number): void;
|
|
60
|
+
export declare function deleteEdge(adj: WeightedAdjacencyList<number, number>, u: number, v: number, w: number): void;
|
|
61
|
+
//# sourceMappingURL=Graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Graph.d.ts","sourceRoot":"","sources":["../../src/collections/Graph.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,yDAAyD;AACzD,MAAM,WAAW,YAAY,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,GAAG,MAAM;IAC5D,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,GAAG,MAAM,IAAI,MAAM,EAAE,EAAE,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,qBAAqB,CAC/B,MAAM,GAAG,MAAM,EACf,MAAM,GAAG,MAAM,IACb,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;AAErC;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAEpE;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,CAAC,EAAE,MAAM,GACR,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,CAEvC;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CACrB,GAAG,EAAE,aAAa,CAAC,MAAM,CAAC,EAC1B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,IAAI,CAAC;AACR,wBAAgB,OAAO,CACrB,GAAG,EAAE,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1C,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,IAAI,CAAC;AAgBR;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,aAAa,CAAC,MAAM,CAAC,EAC1B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,IAAI,CAAC;AACR,wBAAgB,UAAU,CACxB,GAAG,EAAE,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1C,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,IAAI,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph adjacency list helpers (C++-style).
|
|
3
|
+
*
|
|
4
|
+
* These are designed so you can mirror common C++ patterns like:
|
|
5
|
+
* vector<vector<int>> adj(n);
|
|
6
|
+
* vector<vector<pair<int,int>>> adj(n);
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Create an empty unweighted graph with `n` vertices (0..n-1).
|
|
10
|
+
* Equivalent to C++: `vector<vector<int>> graph(n);`
|
|
11
|
+
*/
|
|
12
|
+
export function createAdjacencyList(n) {
|
|
13
|
+
return Array.from({ length: n }, () => []);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create an empty weighted graph with `n` vertices (0..n-1).
|
|
17
|
+
* Equivalent to C++: `vector<vector<pair<int,int>>> graph(n);`
|
|
18
|
+
*/
|
|
19
|
+
export function createWeightedAdjacencyList(n) {
|
|
20
|
+
return Array.from({ length: n }, () => []);
|
|
21
|
+
}
|
|
22
|
+
export function addEdge(adj, u, v, w) {
|
|
23
|
+
if (w === undefined) {
|
|
24
|
+
adj[u].push(v);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
adj[u].push({ to: v, weight: w });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function deleteEdge(adj, u, v, w) {
|
|
31
|
+
const row = adj[u];
|
|
32
|
+
if (!row)
|
|
33
|
+
return;
|
|
34
|
+
if (w === undefined) {
|
|
35
|
+
// Unweighted: remove all neighbors equal to v.
|
|
36
|
+
for (let i = row.length - 1; i >= 0; i--) {
|
|
37
|
+
if (row[i] === v) {
|
|
38
|
+
row.splice(i, 1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// Weighted: remove all edges with { to: v, weight: w }.
|
|
44
|
+
for (let i = row.length - 1; i >= 0; i--) {
|
|
45
|
+
const edge = row[i];
|
|
46
|
+
if (edge.to === v && edge.weight === w) {
|
|
47
|
+
row.splice(i, 1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=Graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Graph.js","sourceRoot":"","sources":["../../src/collections/Graph.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiCH;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,CAAS;IAC3C,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CACzC,CAAS;IAET,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;AAC7C,CAAC;AAoBD,MAAM,UAAU,OAAO,CACrB,GAEyC,EACzC,CAAS,EACT,CAAS,EACT,CAAU;IAEV,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACnB,GAA6B,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;SAAM,CAAC;QACL,GAA6C,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;IAC/E,CAAC;AACH,CAAC;AAoBD,MAAM,UAAU,UAAU,CACxB,GAEyC,EACzC,CAAS,EACT,CAAS,EACT,CAAU;IAEV,MAAM,GAAG,GAAI,GAAqE,CAAC,CAAC,CAAC,CAAC;IAEtF,IAAI,CAAC,GAAG;QAAE,OAAO;IAEjB,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACpB,+CAA+C;QAC/C,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YACzC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjB,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;SAAM,CAAC;QACN,wDAAwD;QACxD,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YACzC,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAiC,CAAC;YACpD,IAAI,IAAI,CAAC,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -10,4 +10,6 @@ export { UnorderedSet } from './UnorderedSet.js';
|
|
|
10
10
|
export { OrderedMultiSet } from './OrderedMultiSet.js';
|
|
11
11
|
export { OrderedMultiMap } from './OrderedMultiMap.js';
|
|
12
12
|
export { RedBlackTree, RBNode } from './RedBlackTree.js';
|
|
13
|
+
export type { WeightedEdge, AdjacencyList, WeightedAdjacencyList } from './Graph.js';
|
|
14
|
+
export { createAdjacencyList, createWeightedAdjacencyList, addEdge, deleteEdge } from './Graph.js';
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collections/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collections/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACzD,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -10,4 +10,5 @@ export { UnorderedSet } from './UnorderedSet.js';
|
|
|
10
10
|
export { OrderedMultiSet } from './OrderedMultiSet.js';
|
|
11
11
|
export { OrderedMultiMap } from './OrderedMultiMap.js';
|
|
12
12
|
export { RedBlackTree, RBNode } from './RedBlackTree.js';
|
|
13
|
+
export { createAdjacencyList, createWeightedAdjacencyList, addEdge, deleteEdge } from './Graph.js';
|
|
13
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/collections/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/collections/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* @example
|
|
6
6
|
* import { Vector, Stack, Queue, List, sort, binarySearch, clamp } from 'typescript-dsa-stl';
|
|
7
7
|
*/
|
|
8
|
-
export { Vector, Stack, Queue, List, ListNode, PriorityQueue, OrderedMap, UnorderedMap, OrderedSet, UnorderedSet, OrderedMultiSet, OrderedMultiMap, } from './collections/index.js';
|
|
8
|
+
export { Vector, Stack, Queue, List, ListNode, PriorityQueue, OrderedMap, UnorderedMap, OrderedSet, UnorderedSet, OrderedMultiSet, OrderedMultiMap, addEdge, deleteEdge, createAdjacencyList, createWeightedAdjacencyList, } from './collections/index.js';
|
|
9
|
+
export type { WeightedEdge, AdjacencyList, WeightedAdjacencyList } from './collections/index.js';
|
|
9
10
|
export { sort, find, findIndex, transform, filter, reduce, reverse, unique, binarySearch, lowerBound, upperBound, min, max, partition, } from './algorithms/index.js';
|
|
10
11
|
export { clamp, range, noop, identity, swap } from './utils/index.js';
|
|
11
12
|
export type { Comparator, Predicate, UnaryFn, Reducer, IterableLike } from './types/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,
|
|
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,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,GAC5B,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACjG,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,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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @example
|
|
6
6
|
* import { Vector, Stack, Queue, List, sort, binarySearch, clamp } from 'typescript-dsa-stl';
|
|
7
7
|
*/
|
|
8
|
-
export { Vector, Stack, Queue, List, ListNode, PriorityQueue, OrderedMap, UnorderedMap, OrderedSet, UnorderedSet, OrderedMultiSet, OrderedMultiMap, } from './collections/index.js';
|
|
8
|
+
export { Vector, Stack, Queue, List, ListNode, PriorityQueue, OrderedMap, UnorderedMap, OrderedSet, UnorderedSet, OrderedMultiSet, OrderedMultiMap, addEdge, deleteEdge, createAdjacencyList, createWeightedAdjacencyList, } from './collections/index.js';
|
|
9
9
|
export { sort, find, findIndex, transform, filter, reduce, reverse, unique, binarySearch, lowerBound, upperBound, min, max, partition, } from './algorithms/index.js';
|
|
10
10
|
export { clamp, range, noop, identity, swap } from './utils/index.js';
|
|
11
11
|
export { toArray } from './types/index.js';
|
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,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,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,GAC5B,MAAM,wBAAwB,CAAC;AAEhC,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,uBAAuB,CAAC;AAC/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/dist/types/index.d.ts
CHANGED
|
@@ -13,54 +13,4 @@ export type Reducer<T, U> = (acc: U, x: T) => U;
|
|
|
13
13
|
export type IterableLike<T> = Iterable<T> | ArrayLike<T>;
|
|
14
14
|
/** Convert IterableLike to array (single copy). Used internally by algorithms. */
|
|
15
15
|
export declare function toArray<T>(source: IterableLike<T>): T[];
|
|
16
|
-
/**
|
|
17
|
-
* Graph adjacency list helpers (C++-style).
|
|
18
|
-
*
|
|
19
|
-
* These are designed so you can mirror common C++ patterns like:
|
|
20
|
-
* vector<vector<int>> adj(n);
|
|
21
|
-
* vector<vector<pair<int,int>>> adj(n);
|
|
22
|
-
*/
|
|
23
|
-
/** Single weighted edge: `to` vertex with a `weight`. */
|
|
24
|
-
export interface WeightedEdge<Vertex = number, Weight = number> {
|
|
25
|
-
to: Vertex;
|
|
26
|
-
weight: Weight;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Unweighted adjacency list.
|
|
30
|
-
*
|
|
31
|
-
* C++: `vector<vector<int>> adj(n);`
|
|
32
|
-
* TS: `AdjacencyList<number>` (backed by `number[][]`).
|
|
33
|
-
*/
|
|
34
|
-
export type AdjacencyList<Vertex = number> = Vertex[][];
|
|
35
|
-
/**
|
|
36
|
-
* Weighted adjacency list.
|
|
37
|
-
*
|
|
38
|
-
* C++: `vector<vector<pair<int,int>>> adj(n);`
|
|
39
|
-
* TS: `WeightedAdjacencyList<number, number>`
|
|
40
|
-
* (backed by `WeightedEdge<number, number>[][]`).
|
|
41
|
-
*
|
|
42
|
-
* Typical use:
|
|
43
|
-
* const adj: WeightedAdjacencyList<number, number> =
|
|
44
|
-
* Array.from({ length: n }, () => []);
|
|
45
|
-
* adj[u].push({ to: v, weight: w });
|
|
46
|
-
*/
|
|
47
|
-
export type WeightedAdjacencyList<Vertex = number, Weight = number> = WeightedEdge<Vertex, Weight>[][];
|
|
48
|
-
/**
|
|
49
|
-
* Add an edge to a graph adjacency list.
|
|
50
|
-
*
|
|
51
|
-
* Overloads:
|
|
52
|
-
* - Unweighted: addEdge(adj, u, v)
|
|
53
|
-
* - Weighted: addEdge(adj, u, v, w)
|
|
54
|
-
*/
|
|
55
|
-
export declare function addEdge(adj: AdjacencyList<number>, u: number, v: number): void;
|
|
56
|
-
export declare function addEdge(adj: WeightedAdjacencyList<number, number>, u: number, v: number, w: number): void;
|
|
57
|
-
/**
|
|
58
|
-
* Delete all edges u -> v from a graph adjacency list.
|
|
59
|
-
*
|
|
60
|
-
* Overloads:
|
|
61
|
-
* - Unweighted: deleteEdge(adj, u, v)
|
|
62
|
-
* - Weighted: deleteEdge(adj, u, v, w)
|
|
63
|
-
*/
|
|
64
|
-
export declare function deleteEdge(adj: AdjacencyList<number>, u: number, v: number): void;
|
|
65
|
-
export declare function deleteEdge(adj: WeightedAdjacencyList<number, number>, u: number, v: number, w: number): void;
|
|
66
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,iFAAiF;AACjF,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC;AAEnD,kDAAkD;AAClD,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;AAE7C,6BAA6B;AAC7B,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AAExC,uDAAuD;AACvD,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AAEhD,2EAA2E;AAC3E,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAEzD,kFAAkF;AAClF,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAMvD
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,iFAAiF;AACjF,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC;AAEnD,kDAAkD;AAClD,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;AAE7C,6BAA6B;AAC7B,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AAExC,uDAAuD;AACvD,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AAEhD,2EAA2E;AAC3E,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAEzD,kFAAkF;AAClF,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAMvD"}
|
package/dist/types/index.js
CHANGED
|
@@ -10,34 +10,4 @@ export function toArray(source) {
|
|
|
10
10
|
}
|
|
11
11
|
return Array.from(source);
|
|
12
12
|
}
|
|
13
|
-
export function addEdge(adj, u, v, w) {
|
|
14
|
-
if (w === undefined) {
|
|
15
|
-
adj[u].push(v);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
adj[u].push({ to: v, weight: w });
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export function deleteEdge(adj, u, v, w) {
|
|
22
|
-
const row = adj[u];
|
|
23
|
-
if (!row)
|
|
24
|
-
return;
|
|
25
|
-
if (w === undefined) {
|
|
26
|
-
// Unweighted: remove all neighbors equal to v.
|
|
27
|
-
for (let i = row.length - 1; i >= 0; i--) {
|
|
28
|
-
if (row[i] === v) {
|
|
29
|
-
row.splice(i, 1);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
// Weighted: remove all edges with { to: v, weight: w }.
|
|
35
|
-
for (let i = row.length - 1; i >= 0; i--) {
|
|
36
|
-
const edge = row[i];
|
|
37
|
-
if (edge.to === v && edge.weight === w) {
|
|
38
|
-
row.splice(i, 1);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
13
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiBH,kFAAkF;AAClF,MAAM,UAAU,OAAO,CAAI,MAAuB;IAChD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IACzC,IAAI,OAAQ,MAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,UAAU,EAAE,CAAC;QACnE,OAAO,CAAC,GAAI,MAAsB,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAsB,CAAC,CAAC;AAC5C,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiBH,kFAAkF;AAClF,MAAM,UAAU,OAAO,CAAI,MAAuB;IAChD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IACzC,IAAI,OAAQ,MAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,UAAU,EAAE,CAAC;QACnE,OAAO,CAAC,GAAI,MAAsB,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAsB,CAAC,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-dsa-stl",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "STL-style data structures and algorithms for TypeScript: Vector, Stack, Queue, List, PriorityQueue, Map, Set, sort, binarySearch. Use like C++ STL.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|