Skip to content

v6: SortCore step-generator engine, 4 new algorithms, complexity profiler - #2

Open
Sebby1770 wants to merge 1 commit into
mainfrom
feat/deep-upgrade-2026-08
Open

v6: SortCore step-generator engine, 4 new algorithms, complexity profiler#2
Sebby1770 wants to merge 1 commit into
mainfrom
feat/deep-upgrade-2026-08

Conversation

@Sebby1770

Copy link
Copy Markdown
Owner

What this does

Rebuilds the Sort Lab's engine around a single testable core and adds an empirical complexity lab on top of it.

sorting-core.js — one implementation, three consumers

All sorting logic now lives in a dependency-free module of pure step generators (SortCore in the browser, CJS in Node — same pattern as pathfinding-core.js). Each algorithm yields a stream of ops (compare / swap / write / touch / counts / mark / narrate / gap / digitExp), and:

  • the page's SortRunner animates the stream (metrics, sound, heatmap, narration, step mode all preserved — ~450 lines of duplicated per-algorithm animation code deleted),
  • the tests run it headlessly,
  • the profiler counts it.

Four new algorithms (10 → 14)

Why it's interesting
Comb Sort bubble sort with a ÷1.3 shrinking gap — kills turtles
Gnome Sort the simplest stable sort — one loop, no nested indices
Cycle Sort provably minimal writes (≤ n) — the writes metric finally gets a star
TimSort (simplified) insertion-sorted minruns + merges with the already-ordered shortcut

All four are wired into the select, race mode, tournament, quiz, learning cards, and profiles.

📈 Complexity Profiler

One click benchmarks all 14 algorithms at n = 16…512 on the current dataset shape, draws a log-log chart, and least-squares-fits each line's slope — the measured exponent k in O(nᵏ) — next to the theoretical class. Verified in-browser: radix/counting measure n^1.00, merge/heap/tim land at n^1.2–1.3, bubble at ~n^2.

Tests — 47 new (66 total, still zero dependencies)

node --test tests/sorting.test.js covers: correctness for every algorithm on 8 dataset shapes + edge cases, input non-mutation, stability proofs for the 8 stable sorts (tagged-key trick), cycle sort's ≤ n write bound and 0-writes-on-sorted property, exact bubble counts on reversed input, and exponent-estimator checks that separate quadratic from linearithmic growth.

Also

  • Service worker cache → v6, precaches sorting-core.js
  • README (14-algorithm table, architecture note, profiler docs) + CHANGELOG v6 entry

Verification

  • ✅ 66/66 node tests pass
  • ✅ Live page: tournament runs all 14 through the new driver; profiler renders chart + table; no console errors

🤖 Generated with Claude Code

… profiler (v6)

- sorting-core.js: all 14 sorting algorithms as pure step generators
  (browser global SortCore + Node CJS), one implementation shared by
  the page, the tests, and the profiler
- New algorithms: Comb, Gnome, Cycle (minimal writes), simplified TimSort
- Complexity Profiler: benchmarks every algorithm at n=16..512, log-log
  chart + fitted empirical growth exponent vs theoretical class
- SortRunner now animates the op stream instead of hardcoding algorithms
- 47 sorting unit tests incl. stability proofs and cycle write bound
- SW cache v6, README/CHANGELOG updates

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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