npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wasm-bellman-ford

v0.2.0

Published

## Welcome the Bellman Ford implementation in Rust+WASM

Downloads

3

Readme

WASM - Bellman Ford

Welcome the Bellman Ford implementation in Rust+WASM

What is Bellman-Ford?

The Bellman–Ford algorithm is an algorithm that computes shortest paths from a single source vertex to all of the other vertices in a weighted digraph. It is slower than Dijkstra's algorithm for the same problem, but more versatile, as it is capable of handling graphs in which some of the edge weights are negative numbers. The algorithm was first proposed by Alfonso Shimbel 1955, but is instead named after Richard Bellman and Lester Ford, Jr., who published it in 1958 and 1956, respectively. Edward F. Moore also published the same algorithm in 1957, and for this reason it is also sometimes called the Bellman–Ford–Moore algorithm.
wikipedia

Since we can use Bellman-Ford as an efficient way to detect negative cycles in a fully connected graph, we can use this to quickly find market inefficencies and arbitrage oppertunities. If a cycle is negative in a graph of currency conversions. eg. USD -> JPY, JPY -> EUR then EUR -> USD. Then we can conclude that the currencies are not in price equilibrium.

Check out RESOURCES.md for a Python example of the code and more resouces about the Bellman-Ford algo.

Clone the repo and navigate to the web dirc, and run the web app. If you need to recompile the wasm then follow the wasm-pack instructions below.

git clone https://github.com/drbh/wasm-bellman-ford.git
cd web
npm install
npm run start

Open your browser and navigate to:

http://localhost:8080/

Javascripy API

In the example file index.html just loads in index.js which is the file that interacts with the wasm library. Here is the full code in index.js and you can see how we pass a JSON payload into the wasm function.

import * as wasm from "wasm-bellman-ford";

var data = JSON.stringify(
{
	"graph": [
	    [1.00, 2.00, 4.00],
	    [0.50, 1.00, 2.00],
	    [0.25, 0.50, 1.00]
	]
})

var bool_response = wasm.bellman_ford_neg_cycle(data);
console.log(bool_response)

rust API

This Bellman Ford algorithim is written in rust and can be used as a component in a larger application or can be editied for other wasm uses.

Here we see an example function that reads in a JSON formatted string, wich bellman_ford_neg_cycle will parse.

fn main() {
    let data = r#"
        {
        	"graph": [
			    [1.00, 2.00, 4.00],
			    [0.50, 1.00, 2.00],
			    [0.25, 0.50, 1.00]
			]
        }"#;


    let result = bellman_ford_neg_cycle(data);
    println!("{:?}", result);
}

Following this template: rustwasm/game-of-life

Build Pack Instructions

A template for kick starting a Rust and WebAssembly project using wasm-pack.

📚 Read this template tutorial! 📚

This template is designed for compiling Rust libraries into WebAssembly and publishing the resulting package to NPM.

Be sure to check out other wasm-pack tutorials online for other templates and usages of wasm-pack.

🚴 Usage

🐑 Use cargo generate to Clone this Template

Learn more about cargo generate here.

cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
cd my-project

🛠️ Build with wasm-pack build

wasm-pack build

🔬 Test in Headless Browsers with wasm-pack test

wasm-pack test --headless --firefox

🎁 Publish to NPM with wasm-pack publish

wasm-pack publish

🔋 Batteries Included