Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Rust implementations of LeetCode Problem #926, compiled to WebAssembly and invoked via Javascript

License

Notifications You must be signed in to change notification settings

HamburgChimps/monotone-crescendo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monotone Crescendo

Rust implementations of LeetCode problem #926, compiled to WebAssembly and invoked via Javascript

See a working demo.

Try It Out Locally

  1. Clone this repository onto your machine.

  2. Install wasm-gc by running cargo install wasm-gc. This is used by build-demo.sh to reduce the size of the compiled wasm binary by removing unneccesary/unused cruft. Even though the wasm-gc project itself says you shouldn't use it in most cases, it still seems to get the wasm file the smallest. I tried using the --gc-sections flag in the compiler options and wasm-gc still got it smaller. I am not making use of wasm-bindgen or wasm-pack in this project, which both attempt to remove cruft when compiling, so I utilized wasm-gc to do it manually.

  3. Run ./build-demo.sh in the repository root. This creates the monotone_crescendo.wasm binary and an index.html file in a directory named demo in the repository root.

  4. cd into demo/ and run an http server. Using python's SimpleHTTPServer, for example:

    cd demo/
    python -m SimpleHTTPServer

    The demo will then be available at http://localhost:8000.

Crate Documentation

Detailed documnetation generated via rustdoc can be found alongside the demo.

Acknowledgements

Huge credit to Dr. Richard Apodaca and his blog, depth-first.com, without which I'm not sure I would have been able to make sense of how to read and write from WebAssembly's linear memory without having to dive straight into something like wasm-bindgen.

These two blog posts from Dr. Apodaca were most helpful:

  1. Compiling Rust to WebAssembly: A Simple Example
  2. Rust and WebAssembly from Scratch: Hello World with Strings

Further credit goes to Radu Matei and his blog post, which helped me build upon the concepts I learned from Dr. Apodaca's posts.

The prefix sum solution is the official solution on LeetCode, I only translated it into Rust.

The cumulative solution was posted to LeetCode by tarunbisht, and was translated into Rust by me.

About

Rust implementations of LeetCode Problem #926, compiled to WebAssembly and invoked via Javascript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published