Skip to content

Add suffix_tree/string_function_calculation port (closes #1) - #2

Merged
m-hu merged 1 commit into
masterfrom
feat/1-suffix-tree
Nov 3, 2026
Merged

m-hu merged 1 commit into
masterfrom
feat/1-suffix-tree

Conversation

@m-hu

@m-hu m-hu commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Closes #1 — ports the clojure-only
src/string_related/suffix_tree/string_function_calculation.clj (audited
line by line: build-tree/follow-link/tree-value) to
src/string_related/suffix_tree/string_function_calculation.py (140 lines).

Algorithm

Ukkonen online suffix tree over input + terminal $; answer = max over
nodes of string-depth × leaf-count. O(n) time / O(n) space, same as the
.clj.

Validation

  • Difftest vs brute-force oracle: new port 143/143 (edges + 120 seeded
    fuzz + structured), old suffix_array twin 143/143; 5/5 IO edge cases.
  • JVM cross-check of the .clj: 8/8 values byte-identical (incl.
    mississippi→11, aabaaabaaab→14); blank/malformed stdout+stderr
    byte-identical.
  • Scaling: identical outputs everywhere; ~1.3–2.1x faster than the old
    twin on adversarial inputs.
  • run_tests.py --only suffix_tree/string_function_calculation: 8 passed,
    0 failed locally.

Note for the merger

The 8 hand-built test cases could not be committed: tests/resources/ is
gitignored and the encrypted bundle needs RESOURCES_PASSPHRASE. A
passphrase holder must add cases to resource/shared and run
tools/build_bundle.sh before CI perf-callgrind picks up the benchmark.

AI-Tool: Muse Code (Meta Muse Spark)

Ukkonen online suffix tree over the input plus a terminal mark, then
max over nodes of string depth times leaf count. O(n) time, O(n) space,
same algorithm and complexity as the .clj.

Fixes #1.

AI-Tool: Muse Code (Meta Muse Spark)

@michael-h-hu michael-h-hu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — round 1

Inspected the full diff (1 new file, 140 lines, no other files touched) against the linked issue #1 and the in-repo suffix_array twin.

What was checked:

  • Read src/string_related/suffix_tree/string_function_calculation.py end to end: Ukkonen online construction over input + $ terminal, answer = max over nodes of string-depth x leaf-count, explicit stacks (no recursion), ans = n init and empty-input guard matching the twin.
  • Ran an independent 137-case difftest of string_value vs a brute-force oracle (edges, mississippi, aabaaabaaab, 120 seeded fuzz over small alphabets, adversarial repeats): 0 mismatches.
  • CLI: mississippi -> 11, blank input -> silent exit 0, non-lowercase -> stderr error with empty stdout (stderr is ignored by the run_tests.py stdout-only comparison, so this is safe; it mirrors the .clj malformed-input behavior cited in the PR body).
  • CI: test + all 4 test shards green; all 4 perf-callgrind shards green after a retry of an unrelated environmental wall-clock timeout (dp/edit_distance 45B-Ir case, pre-existing knife-edge, passed on rerun with no code change); report green. New benchmark measured 11/11 cases in perf with 0 failures.
  • Issue #1 acceptance: same algorithm/complexity as the .clj (Ukkonen O(n)/O(n)); shared-layout cases resolve from the bundle; run_tests.py green; benchmark present in the perf sweep.

Residual notes (non-blocking):

  • The PR body's "cases could not be committed" caveat is stale: the shared-layout suffix_tree cases already exist in the encrypted bundle (same resource path as the clojure side) and CI measured 11 of them. No passphrase-holder action needed.
  • .clj line-by-line fidelity relies on the crew's audit plus the behavioral evidence above; I did not re-read the .clj source in this pass.

No findings. Merging is the author's call.

AI-Tool: Muse Code (Meta Muse Spark)

@m-hu
m-hu merged commit da2e2e4 into master Nov 3, 2026
28 of 30 checks passed
m-hu added a commit that referenced this pull request Nov 3, 2026
…#4)

Post-#2 shard rotation tipped the ~45B-instruction edit_distance
case from usually-pass to usually-timeout at 300s wall clock.
2x headroom; genuine hangs still fail.

AI-Tool: Muse Code (Meta Muse Spark)
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.

Add missing string_related/suffix_tree/string_function_calculation port

2 participants