Skip to content

Add a WebAssembly build of the algorithms - #3

Open
ilyaeis wants to merge 1 commit into
mainfrom
web-wasm
Open

ilyaeis wants to merge 1 commit into
mainfrom
web-wasm

Conversation

@ilyaeis

@ilyaeis ilyaeis commented Oct 31, 2026

Copy link
Copy Markdown
Owner

What

A WebAssembly build of the sort and shuffle algorithms. The portfolio page at https://ilyaeis.github.io/apps/sorting/ will use it. The drawing there is a JavaScript port of ArrayDrawer.cpp.

  • Code/AnotherFunc.hpp: the SFML include and all sf:: declarations are left out when __EMSCRIPTEN__ or SORTVIS_NO_SFML is defined. The native build does not change. SortAlgorithms.cpp and ShuffleAlgorithms.cpp do not change.
  • web/shim.cpp: replaces Main.cpp and the menu in the web build.
    • drawing() records the steps, like record mode: a dry run counts the steps, then the real run saves every n-th step.
    • rand() and srand() work like glibc (TYPE_3), so a seed gives the same shuffle as the Linux program.
    • Exports: sv_srand, sv_rand, sv_fill, sv_gen_shuffle, sv_shuffle, sv_sort, sv_log, sv_array, sv_length.
  • build_web.sh: builds web/dist/sortvis.js and web/dist/sortvis.wasm (ES module, createSortVis). About 16 KB gzip for both files.
  • CI: a new web job uploads the artifact sortvis-web. A release also attaches the two files.
  • README: a short "Web build" section. web/dist/ is in .gitignore.

Checks

  • The shim rand() gives the same 16,000 numbers as glibc rand() (8 seeds, 2,000 numbers each).
  • Seed 1, Quick sort: the native record mode (every step saved) gives 8084 frames = 1 + 500 shuffle steps + 1 + 7581 sort steps + 1. The wasm log has the same counts. In 12 frames (shuffle, sort at 0 %, 25 %, 50 %, 75 %, end, and more), all 500 column heights and the two highlight colours match the wasm array state.
  • Seed 1, Radix sort with 600 frames (stride 10): 703 frames, as the wasm counts predict (6000 sort steps). All 9 frames I checked match.
  • The CI build of the web files is byte for byte the same as my local build.

🤖 Generated with Claude Code

https://claude.ai/code/session_012G3kWcaMBo7MSwGBgwXaju

The sort and shuffle code now also builds with Emscripten.
AnotherFunc.hpp leaves out the SFML parts when __EMSCRIPTEN__ or
SORTVIS_NO_SFML is defined. The native build does not change.

web/shim.cpp replaces Main.cpp and the menu. Its drawing() records
the steps into a log, like record mode. It has the glibc rand(), so
a seed gives the same shuffle as the Linux program.

build_web.sh builds web/dist/sortvis.js and sortvis.wasm. The CI has
a new web job, and releases attach the two files.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012G3kWcaMBo7MSwGBgwXaju
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant