Skip to content

Fix: replace per-iteration OrderBy with HashSet.SetEquals in GetPayBack#34

Open
HashidaTKS wants to merge 1 commit into
masterfrom
fix/simulator-orderby-in-loop
Open

Fix: replace per-iteration OrderBy with HashSet.SetEquals in GetPayBack#34
HashidaTKS wants to merge 1 commit into
masterfrom
fix/simulator-orderby-in-loop

Conversation

@HashidaTKS

Copy link
Copy Markdown
Owner

問題点

Simulator.GetPayBack() で「ループ内で毎回 OrderBy するのを避け」というコメントがあったが、result.Item1.OrderBy(_ => _) はループ内に残っており、コメントと実装が矛盾していた(line 261)。

結果として毎イテレーションで O(n log n) のソートが実行され続けていた。

改善内容

  • BetDatum.HorseNumListHashSet<int> に変換(ループ前に一度だけ)
  • result.Item1.OrderBy().SequenceEqual()betHorsesSet.SetEquals(result.Item1) に置き換え
  • 順序非依存かつ O(n) の比較が実現し、コメントの意図とも一致する

Test plan

  • Quinella / Wide / Trio の払い戻し計算が正しく機能することを確認
  • 馬番号の順序が異なる場合でも正しくマッチすることを確認

🤖 Generated with Claude Code

The comment said to avoid OrderBy inside the loop, but result.Item1.OrderBy()
was still called on every iteration. Replace the sorted-sequence comparison
with HashSet.SetEquals, which is order-independent and O(n) rather than
O(n log n) per iteration, eliminating both the correctness inconsistency
and the redundant sort.

Co-Authored-By: Claude Sonnet 4.6 <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