Skip to content

Fix: replace O(n*m) linear scan with O(n+m) dictionary lookup in GetSameTicketOddsData#36

Open
HashidaTKS wants to merge 1 commit into
masterfrom
fix/enumerable-utils-on2-to-dict
Open

Fix: replace O(n*m) linear scan with O(n+m) dictionary lookup in GetSameTicketOddsData#36
HashidaTKS wants to merge 1 commit into
masterfrom
fix/enumerable-utils-on2-to-dict

Conversation

@HashidaTKS
Copy link
Copy Markdown
Owner

問題点

EnumerableUtils.GetSameTicketOddsData()froms のリストを毎要素 FirstOrDefault() で線形探索していた(line 28)。

needs のサイズを n、froms のサイズを m とすると O(n*m) の計算量となり、シミュレーションで大量のオッズデータを処理する際にボトルネックになる。

改善内容

  • froms をループ前に Dictionary<string, OddsDatum> に変換(O(m))
  • キーは馬番号のカンマ区切り文字列(順序依存チケットはそのまま、順序非依存チケットはソート済み)
  • ループ内では TryGetValue で O(1) ルックアップ → 全体で O(n+m)

Test plan

  • Win / Exacta / Trifecta(順序依存)で同一馬番号が正しくマッチすることを確認
  • Quinella / Wide / Trio(順序非依存)で順序が異なっても正しくマッチすることを確認
  • 該当なしの場合に null が返されることを確認

🤖 Generated with Claude Code

…ameTicketOddsData

The original implementation called targetFromList.FirstOrDefault() inside
a foreach over targetNeedList, resulting in O(n*m) complexity. For typical
race data with many odds entries this becomes a bottleneck in simulation.

Build a Dictionary<string, OddsDatum> keyed by the horse number signature
(comma-joined, sorted for order-independent ticket types) from froms before
the loop, reducing the overall complexity to O(n+m).

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