@xingwangzhe/bfs-rs 0.2.2 → 0.2.3
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 +18 -14
- package/bfs-rs.darwin-arm64.node +0 -0
- package/bfs-rs.darwin-x64.node +0 -0
- package/bfs-rs.linux-arm64-gnu.node +0 -0
- package/bfs-rs.linux-x64-gnu.node +0 -0
- package/bfs-rs.linux-x64-musl.node +0 -0
- package/bfs-rs.win32-x64-msvc.node +0 -0
- package/package.json +27 -25
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ offsets = [0, 2, 4, 7, 8] // node offset range (length = n + 1)
|
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
| Node | Neighbors |
|
|
27
|
-
|
|
27
|
+
| ---- | --------------------- |
|
|
28
28
|
| 0 | adj[0..2] = [1, 2] |
|
|
29
29
|
| 1 | adj[2..4] = [0, 2] |
|
|
30
30
|
| 2 | adj[4..7] = [0, 1, 3] |
|
|
@@ -39,7 +39,7 @@ offsets = [0, 2, 4, 7, 8] // node offset range (length = n + 1)
|
|
|
39
39
|
Single-source BFS, returns distances array.
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
|
-
import { bfsOne } from
|
|
42
|
+
import { bfsOne } from "@xingwangzhe/bfs-rs";
|
|
43
43
|
const r = bfsOne(adj, offsets, n, 0);
|
|
44
44
|
// r.distances → [0, 1, 1, 2]
|
|
45
45
|
// r.maxDistance → 2
|
|
@@ -51,7 +51,7 @@ const r = bfsOne(adj, offsets, n, 0);
|
|
|
51
51
|
Parallel BFS from multiple sources.
|
|
52
52
|
|
|
53
53
|
```ts
|
|
54
|
-
import { bfsBatch } from
|
|
54
|
+
import { bfsBatch } from "@xingwangzhe/bfs-rs";
|
|
55
55
|
const r = bfsBatch(adj, offsets, n, [0, 3]);
|
|
56
56
|
// r.processed → 2, r.results → [BfsOneResult, BfsOneResult]
|
|
57
57
|
```
|
|
@@ -61,7 +61,7 @@ const r = bfsBatch(adj, offsets, n, [0, 3]);
|
|
|
61
61
|
All-pairs BFS (every node as source).
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
|
-
import { bfsAll } from
|
|
64
|
+
import { bfsAll } from "@xingwangzhe/bfs-rs";
|
|
65
65
|
const r = bfsAll(adj, offsets, n);
|
|
66
66
|
// r.results.length === n
|
|
67
67
|
```
|
|
@@ -71,7 +71,7 @@ const r = bfsAll(adj, offsets, n);
|
|
|
71
71
|
Shortest path between two nodes. Stops early at target.
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
|
-
import { bfsPath } from
|
|
74
|
+
import { bfsPath } from "@xingwangzhe/bfs-rs";
|
|
75
75
|
const r = bfsPath(adj, offsets, n, 0, 3);
|
|
76
76
|
// r.path → [0, 2, 3], r.distance → 2
|
|
77
77
|
```
|
|
@@ -85,7 +85,7 @@ These return **only the distance histogram** per source (no full `distances` arr
|
|
|
85
85
|
Same usage as above, but result type is `BfsHistogramResult`:
|
|
86
86
|
|
|
87
87
|
```ts
|
|
88
|
-
import { bfsAllHistogram } from
|
|
88
|
+
import { bfsAllHistogram } from "@xingwangzhe/bfs-rs";
|
|
89
89
|
const r = bfsAllHistogram(adj, offsets, n);
|
|
90
90
|
// r.results[i].histogram → [count_at_dist_1, count_at_dist_2, ...]
|
|
91
91
|
// r.results[i].maxDistance → number
|
|
@@ -98,7 +98,7 @@ Memory per source: ~(diameter × 4) bytes instead of ~(n × 4) bytes.
|
|
|
98
98
|
For repeated queries on the same graph, build the transpose and reusable traversal buffers once:
|
|
99
99
|
|
|
100
100
|
```ts
|
|
101
|
-
import { createBfsGraph } from
|
|
101
|
+
import { createBfsGraph } from "@xingwangzhe/bfs-rs";
|
|
102
102
|
|
|
103
103
|
const graph = createBfsGraph(new Uint32Array(adj), new Uint32Array(offsets), n);
|
|
104
104
|
const one = graph.one(0);
|
|
@@ -110,22 +110,22 @@ The prepared API keeps every result exact. Existing array-based functions remain
|
|
|
110
110
|
|
|
111
111
|
## Performance
|
|
112
112
|
|
|
113
|
-
| Platform
|
|
114
|
-
|
|
115
|
-
| 16-core
|
|
116
|
-
| 1-core
|
|
113
|
+
| Platform | 57K nodes × 179K edges | Notes |
|
|
114
|
+
| -------- | ---------------------- | ---------------------------------- |
|
|
115
|
+
| 16-core | **~3s** | Rayon `par_iter` across 16 threads |
|
|
116
|
+
| 1-core | ~70s | auto-fallback to `iter` |
|
|
117
117
|
|
|
118
118
|
The traversal switches between top-down push and bottom-up pull when the frontier becomes broad. Visitation stamps avoid clearing an `n`-element distance array for histogram-only calls, and merged histograms use worker-local counters before reduction.
|
|
119
119
|
|
|
120
120
|
## Full Example
|
|
121
121
|
|
|
122
122
|
```ts
|
|
123
|
-
import { bfsOne, bfsBatch, bfsAll, bfsPath, bfsAllHistogram } from
|
|
123
|
+
import { bfsOne, bfsBatch, bfsAll, bfsPath, bfsAllHistogram } from "@xingwangzhe/bfs-rs";
|
|
124
124
|
|
|
125
125
|
// Graph: 0--1--2, 0--3--4--2
|
|
126
|
-
const adj
|
|
126
|
+
const adj = [1, 3, 0, 2, 1, 4, 0, 4, 2, 3];
|
|
127
127
|
const offsets = [0, 2, 4, 6, 8, 10];
|
|
128
|
-
const n
|
|
128
|
+
const n = 5;
|
|
129
129
|
|
|
130
130
|
// Full distances
|
|
131
131
|
const r1 = bfsOne(adj, offsets, n, 0);
|
|
@@ -150,3 +150,7 @@ for (const h of r3.results) {
|
|
|
150
150
|
## License
|
|
151
151
|
|
|
152
152
|
MIT
|
|
153
|
+
|
|
154
|
+
## Runtime-focused release builds
|
|
155
|
+
|
|
156
|
+
Native CI artifacts use full LTO, one code-generation unit, and O3, while preserving the existing CPU instruction baseline. CI trains a profile-guided optimization (PGO) candidate using representative graph workloads and publishes it only when the runtime comparison passes; otherwise it publishes the unprofiled release. `bun run build:pgo` produces the optimized addon; `bun run benchmark:pgo` compares it with an unprofiled release. Install `llvm-tools-preview` with the same Rust toolchain first. Details and measurement limits: [scripts/PERFORMANCE.md](scripts/PERFORMANCE.md).
|
package/bfs-rs.darwin-arm64.node
CHANGED
|
Binary file
|
package/bfs-rs.darwin-x64.node
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,47 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xingwangzhe/bfs-rs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Rust BFS on compressed adjacency list with Rayon parallelism",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"author": "xingwangzhe",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/xingwangzhe/bfs-rs.git"
|
|
12
|
-
},
|
|
13
5
|
"keywords": [
|
|
14
6
|
"bfs",
|
|
15
7
|
"graph",
|
|
16
|
-
"rayon",
|
|
17
8
|
"napi-rs",
|
|
9
|
+
"rayon",
|
|
18
10
|
"rust"
|
|
19
11
|
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "xingwangzhe",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/xingwangzhe/bfs-rs.git"
|
|
17
|
+
},
|
|
20
18
|
"files": [
|
|
21
19
|
"index.d.ts",
|
|
22
20
|
"index.js",
|
|
23
21
|
"bfs-rs.*.node"
|
|
24
22
|
],
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"targets": [
|
|
28
|
-
"x86_64-apple-darwin",
|
|
29
|
-
"aarch64-apple-darwin",
|
|
30
|
-
"x86_64-pc-windows-msvc",
|
|
31
|
-
"x86_64-unknown-linux-gnu",
|
|
32
|
-
"x86_64-unknown-linux-musl",
|
|
33
|
-
"aarch64-unknown-linux-gnu"
|
|
34
|
-
]
|
|
35
|
-
},
|
|
36
|
-
"engines": {
|
|
37
|
-
"node": ">= 18"
|
|
38
|
-
},
|
|
23
|
+
"main": "index.js",
|
|
24
|
+
"types": "index.d.ts",
|
|
39
25
|
"scripts": {
|
|
40
26
|
"build": "napi build --platform --release",
|
|
41
27
|
"test": "node --test bfs.test.mjs",
|
|
42
28
|
"benchmark": "node benchmark.mjs",
|
|
43
29
|
"lint": "oxlint",
|
|
44
|
-
"artifacts": "napi artifacts"
|
|
30
|
+
"artifacts": "napi artifacts",
|
|
31
|
+
"build:pgo": "node scripts/build-pgo.mjs",
|
|
32
|
+
"benchmark:pgo": "node scripts/build-pgo.mjs --compare"
|
|
45
33
|
},
|
|
46
34
|
"devDependencies": {
|
|
47
35
|
"@napi-rs/cli": "^3.10.5",
|
|
@@ -53,5 +41,19 @@
|
|
|
53
41
|
"overrides": {
|
|
54
42
|
"brace-expansion": "^5.0.9",
|
|
55
43
|
"tar": "^7.5.22"
|
|
44
|
+
},
|
|
45
|
+
"napi": {
|
|
46
|
+
"binaryName": "bfs-rs",
|
|
47
|
+
"targets": [
|
|
48
|
+
"x86_64-apple-darwin",
|
|
49
|
+
"aarch64-apple-darwin",
|
|
50
|
+
"x86_64-pc-windows-msvc",
|
|
51
|
+
"x86_64-unknown-linux-gnu",
|
|
52
|
+
"x86_64-unknown-linux-musl",
|
|
53
|
+
"aarch64-unknown-linux-gnu"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">= 18"
|
|
56
58
|
}
|
|
57
59
|
}
|