Repository navigation
TrieString: 配列・辞書版の文字列ハンドルと厳密な辞書順比較を追加 - #1094
Merged
Merged
Conversation
kemuniku
marked this pull request as ready for review
October 26, 2026 14:27
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
変更内容
Trie上の節点IDを文字列・要素列のハンドルとして使い、過去の任意のハンドルから末尾追加・親への移動・厳密な辞書順比較を行える構造を追加します。同じ
(親, 要素)は同じIDを返し、popは節点を破棄しません。initTrieStringArray('a'..'z'): 固定char範囲の配列版initTrieStringTable(T): 汎用要素の辞書版(initTrieString()はchar版の短縮形)add,pop,compare,lcp,lcpNode,prefix,toString,toSeq,trie[node,index]。根・長さ・節点数も取得できます。ValueError。char列はNUL・非ASCIIを含め0..255のbyte順。GCは含みません。各節点に親・深さ・1本のskew-binary jumpを持ち、二分累乗表やrolling hashを使いません。正規化した辺によりLCAがLCPに対応します。API契約・使用例・計算量の根拠はNimのdocコメントに記載しています。
計算量
Nは根を含む作成済み節点数、σは配列版の文字種数です。
変換は長さLに対し時間・出力空間 O(L+1)。ジャンプ作成そのものは最悪 O(1) ですが、seq拡張を含む追加を最悪 O(1) とは主張しません。辞書版は定数サイズ要素のhash/等値判定/比較と良好なhash分布を仮定し、悪意ある衝突では追加が線形になり得ます。衝突は答えの正しさには影響しません。
検証と差分の範囲
差分は以下の3ファイルだけです。
src/cplib/str/trie_string.nimsrc/verify/str/trie_string_test.nimsrc/verify/str/trie_string_import_test.nimテストは既存Trieや他の回帰テストと同じ
PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/ITP1_1_Aの形式で、全assertion実行後にHello Worldを出力します。既存のverification workflowで実行し、専用workflow、verify外のテスト、Markdown、ベンチマークファイルは追加しません。Hello World\nとなることを確認。回帰テスト本体はローカルで約2秒、既存の10秒制限内でした。ローカルの単一VM・1回測定では800,001節点の鎖構築が辞書0.330秒・配列σ=2で0.102秒でした。RSSには入力配列・余剰容量・再確保ピークを含みます。これは追加/親取得/比較の計測で、LCP等の実測や漸近境界の証明ではありません。測定コード・ログ・補足資料はローカルだけに保持しています。