Skip to content

Repository files navigation

petgraph-wasm

NPM Version

A work in progress, selective WASM wrapper around the fantastic petgraph library in Rust.

This project aims to provide a direct port of the petgraph library to an NPM packages which preserves as much of the original API structure and design as possible. For more details please check out the thoroughly documented petgraph API.

Example

// Typescript exampleimport{DiGraph,toposort}from'petgraph-wasm'// Create new directional graphconstg=newDiGraph()// Add nodes to directional graphconstkno_index=g.addNode("Knoxville")constvil_index=g.addNode("Vilnius")consttai_index=g.addNode("Taipei")// Connect them with edgesg.addEdge(kno_index,vil_index)g.addEdge(kno_index,tai_index)g.addEdge(vil_index,tai_index)// Sort themconstsorted_g=toposort(g)// Detect cyclesg.addEdge(tai_index,kno_index)// Will throw error!toposort(g)

Performance

You should always measure you're exact needs to know how this library will work for you. But here's a few order of magnitude examples as run on a GCP VM with a 2.25GHz AMD EPYC CPU. There are probably overly "optomistic" in design as compared to real world needs.

ActionNodesEdgesTime
toposort10,0009,000~2ms
toposort10,00090,000~5ms
toposort10,000900,000~20ms
toposort100,00099,000~20ms
toposort100,000990,000~70ms
toposort100,000900,000~600ms
toposort1,000,000999,000~350ms
toposort1,000,0009,990,000~750ms
toposort1,000,00099,900,000out-of-memory

Development

To work on this you will need to install rust-up and wasm-pack.

# Build the npm package
wasm-pack build --target nodejs
# Test on node
wasm-pack test --node
# Create release build
./bin/ci.sh
# Try out benchmark of 100,000 nodes each with 15 edgestime ./example_js/benchmark.js 100000 15

About

A work in progress, selective WASM wrapper around the fantastic petgraph library in Rust.

Topics

Resources

Stars

11 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages