Skip to content

refactor: extract shared helpers, fix naming, split god file - #10

Merged
TamimEhsan merged 1 commit into
TamimEhsan:masterfrom
Wolfvin:refactor-structural
Jun 15, 2026
Merged

TamimEhsan merged 1 commit into
TamimEhsan:masterfrom
Wolfvin:refactor-structural

Conversation

@Wolfvin

@Wolfvin Wolfvin commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

What this PR does

Structural refactoring of the algorithm modules, verified safe with Regrets regression testing (15 clusters, 27 outputs, 2 chains — all GREEN).

Decomposition — Split god file

sortingAlgorithms.js contained 4 sorting algorithms in one file. Split into:

  • bubble-sort.js — Bubble sort only
  • selection-sort.js — Selection sort only
  • insertion-sort.js — Insertion sort only
  • sortingAlgorithms.js — Re-exports for backward compatibility

Shared Helpers — Eliminate duplication

  • Created helpers/graph-helpers.js with buildPathActions() function
  • Previously, identical pathActions() was duplicated in both graph.js and shortestPath.js
  • Both files now import from shared helper
  • Fixed ESM import: shortestPath.js changed ./graph → ./graph.js

Naming — Make names honest and descriptive

  • Fixed typo: seive() → sieve() (Sieve of Eratosthenes) with backward-compatible alias
  • Fixed naming convention: convex_hull() → convexHull() (camelCase) with alias
  • Descriptive names: cw() → isClockwiseTurn(), ccw() → isCounterClockwiseTurn() with aliases

Verification Results

All changes verified safe with Regrets output-based regression testing:

Verification Method Result
Clusters All 15 .regret fingerprints still GREEN ✅ PASS
Raw Output All 27 entry function outputs match pre-refactor baseline exactly ✅ PASS
Fingerprint Cross-check All 15 fingerprints from new output match pre-refactor fingerprints ✅ PASS
Chain Validation Both chain hashes match pre-refactor chains ✅ PASS

Fingerprint Summary (before → after)

Cluster Fingerprint Status
sieve-of-eratosthenes 61kfkvs ✅
convex-hull-graham 2ffeigp ✅
bubble-sort dsuh6kq ✅
selection-sort pggv13p ✅
insertion-sort 231p3bq ✅
graph-adjacency 2kqzuc0 ✅
graph-weighted-adjacency 3f1bu8y ✅
connected-components 42ufcfy ✅
scc-tarjan 3cp39pq ✅
kruskal-mst 4cmle1u ✅
prim-mst joly0qh ✅
max-flow-ek 4msj9pa ✅
dijkstra-actions 2vmdh6s ✅
bellman-ford-actions 13l9483 ✅
turing-next-step 101eriz ✅

Chain Hash Summary (before → after)

Chain Hash Status
graph-traversal-flow 2tv6cod ✅
mst-to-sp 24sdllj ✅

No behavior was changed. All refactoring is structurally safe.

Structural refactoring verified safe with Regrets regression testing.

## Changes

### Decomposition — Split god file
- Split `sortingAlgorithms.js` (4 algorithms in one file) into individual files:
  - `bubble-sort.js` — Bubble sort algorithm
  - `selection-sort.js` — Selection sort algorithm
  - `insertion-sort.js` — Insertion sort algorithm
- `sortingAlgorithms.js` now re-exports from split modules for backward compatibility

### Shared Helpers — Eliminate duplication
- Created `helpers/graph-helpers.js` with `buildPathActions()` function
- Previously, identical `pathActions()` was duplicated in both `graph.js` and `shortestPath.js`
- Both files now import from shared helper, export as `pathActions` for backward compat
- Fixed ESM import: `shortestPath.js` changed `'./graph'` → `'./graph.js'`

### Naming — Make names honest and descriptive
- Fixed typo: `seive()` → `sieve()` (Sieve of Eratosthenes) with backward-compatible alias
- Fixed naming convention: `convex_hull()` → `convexHull()` (camelCase in JS) with alias
- Descriptive names: `cw()` → `isClockwiseTurn()`, `ccw()` → `isCounterClockwiseTurn()` with aliases

## Verification

All changes verified safe with Regrets regression testing:
- 15 clusters: all GREEN
- 27 raw outputs: match pre-refactor KEBENARAN 1 exactly
- 15 fingerprints: match pre-refactor KEBENARAN 2
- 2 chain hashes: match pre-refactor chains
@TamimEhsan
TamimEhsan merged commit 11d893b into TamimEhsan:master Jun 15, 2026
1 check passed
@TamimEhsan

Copy link
Copy Markdown
Owner

Thanks for the PR! Looks good to me!

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.

2 participants