Skip to content

RUST WASM implementation of a graph to be used in Typescript

License

Notifications You must be signed in to change notification settings

Apokalip/IOTA_DAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Directed Acyclical Graph implementation in Rust and exported with WASM to be used with Typescript

The Whys.

Why and how I modified task

How : Changed the task to a full fledged Directed Acyclic Graph, any amount of edges still no weights as I don't think they are needed in this context.

Statistics I went for:

  • Node Count: 10
  • Edge Count: 9
  • Count of source Nodes
  • Count of leaf Nodes
  • Average Depth from Node 0
  • Avarage Depth from all Source Nodes
  • Avarage In-references per Node
  • Average Nodes per depth
  • DAG density
  • Average Path length/distance between nodes

"database" format is more complex for this as I felt it was lackluster from a developers perspective.

First line is still node count after that lines are related to the nodes themself, while the numbers are edge targets. Example:

5
1 2
2 3
4 5

So we have 5 nodes, first one is Node(0) with edges 0->1 and 0->2 and so on. For nodes that dont have outgoing edges the lines and empty or non existing as the Graph is constructed based on the edges and will create nodes if there is no node which was targeted. You may have empty lines start, middle,end. It does not matter.

Why : I felt like a full fledged DAG will be more interesting as there may be more issues in porting to WASM, and those are chances to show off.

How to setup and run

Firstly you will need Rust https://doc.rust-lang.org/cargo/getting-started/installation.html Then lets get the source after you have setup Rust and Cargo

git clone https://github.com/Apokalip/IOTA_DAG.git

We have 2 folders: dag_generator : generates DAG-s for testing with a number of nodes and targeted density(tries to get close to it) dag_wasm : the package and demo itself

How to create a DAG file for testing

Move to the dag_generator folder

cd dag_generator

Generate a dag file

cargo run -- -n 30 -d 0.3

Where -n / --nodes are the number of wanted nodes -d / --density is the targeted density After running you should have a DAG_30nodes_0.3density.txt file. The name will always be related to the inputs.

Setup and run the package in Rust

Lets use the previously generated DAG file in (How to create a DAG file for testing)

cd dag_wasm
cargo update
cargo run -- DAG_30nodes_0.3density.txt

image

You should get an output with some statistics about the DAG

Setup and run in WASM Typescript Env

Run these in order. Install npm if you dont have it.

wasm-pack should be ran with --target web --features wasm for WASM to be available

After the first build, npm run build and npm start should rebuild the Rust Wasm package automatically

cd dag_wasm
cargo install wasm-pack
wasm-pack --target web --features wasm
npm install
npm build
npm start

After running you should see a page on localhost and someport. Either your IDE will auto open it or look at the terminal for something like

<i> [webpack-dev-server] Loopback: http://localhost:8089/

image This is the page you will see. Paste your DAG "database" context in the field and click load. The context will be converted to a WASM graph and you will get statistics on the right.

About

RUST WASM implementation of a graph to be used in Typescript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published