Skip to content

Fix #39 graph items: heaps and O(1) queues - #41

Closed
m-hu wants to merge 1 commit into
masterfrom
fix/39-graph-complexity
Closed

m-hu wants to merge 1 commit into
masterfrom
fix/39-graph-complexity

Conversation

@m-hu

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

Copy link
Copy Markdown
Collaborator

Part of #39 — the six graph items: every BFS/queue dequeue and heap pop
that cost an extra linear factor now runs in the python twin's complexity.

Changes

  • graph/flow/min_cost_max_flow: Dijkstra heap pop O(h log h) re-sort →
    O(log h) java.util.PriorityQueue (complete-DAG n=300: 10.1s → 3.9s).
  • graph/matching/blossom, graph/matching/gale_shapley,
    graph/minimum_spanning_tree/second_best_mst, graph/shortest_path/spfa:
    O(n) (vec rest) / vec-concat dequeue → O(1) PersistentQueue
    pop/peek (gale_shapley n=1500: 11.2s → 2.3s; spfa star n=60000:
    7.4s → 0.7s; second_best_mst n=250: 5.4s → 2.0s).
  • graph/shortest_path/dag_shortest_paths: topo poll re-sort + O(n)
    acc-scan → O(log h) PQ + O(1) seen-vector (edgeless n=20000:
    4.2s → 0.4s).

FIFO/order semantics preserved (PQ ascending order = prior sort order).

Validation

  • 38/38 before/after pairs byte-identical via JVM clojure.main on
    hand-built small + adversarial inputs (shared GPG cases unavailable
    locally — full run_tests.py + perf-callgrind coverage comes from CI
    on this PR).
  • Only the 6 .clj files touched.

AI-Tool: Muse Code (Meta Muse Spark)

- min_cost_max_flow: sorted-vector heap re-sorted per pop -> java.util.PriorityQueue (pop O(h log h) -> O(log h))
- blossom, gale_shapley, second_best_mst, spfa: vector queue copied per dequeue -> PersistentQueue (dequeue O(n) -> O(1) amortized)
- dag_shortest_paths: topo vector re-sorted per vertex + O(n) acc-membership scan per edge -> PriorityQueue + seen vector (poll O(h log h)+scan -> O(log h)+O(1))

Validation: 38 hand-built before/after runs (small + adversarial), all byte-identical; e.g. gale n=1500 11.2s->2.3s, spfa star60k 7.4s->0.7s, dag indep20k 4.2s->0.4s, mcmf n=300 10.1s->3.9s, sbmst star250 5.4s->2.0s.

AI-Tool: Muse Code (Meta Muse Spark)
@m-hu

m-hu commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #45 — all four area branches merged into one batch PR.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

🐰 Bencher Report

Projectclojure-code-snippet
Branchfix/39-graph-complexity
Testbedubuntu-latest-clojure-rs

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

🐰 View full continuous benchmarking report in Bencher

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