Refactor acl_string: convert namespace class to proper String class + comprehensive tests - #21
Merged
Conversation
Replace the static-method-only `class string` (which was just a namespace) with a `String` class that wraps a sequence and exposes suffix_array, lcp_array, and z_algorithm as instance methods. Internal helper _sa_is is now a module-level private function. Added __len__, __getitem__, and __repr__ for basic sequence protocol support.
31 test cases covering: - suffix_array: empty/single/two-char, all-same, known strings (abab, mississippi, abcbcba), integer list input, practice2-I problem - lcp_array: basic, auto-SA, all-same, all-distinct, single-char, mississippi boundary checks - z_algorithm: empty/single, all-same, known patterns, Z-property invariant, pattern search application - String protocol: __len__, __getitem__ (slice), __repr__, __str__, integer list getitem
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.
変更内容
acl_string.py のリファクタリング
class stringは全メソッドがselfなしで定義されており、クラスを名前空間代わりに使うだけの実装だった。これを文字列をラップする本物のクラスStringに変更した。主な変更:
class string→class Stringに改名String(s)で文字列または整数リストをラップsuffix_array()、lcp_array(sa=None)、z_algorithm()をインスタンスメソッドに変換lcp_array()はsa省略時に内部でsuffix_array()を自動計算__len__、__getitem__、__repr__、__str__でシーケンスプロトコルに対応sa_is→_sa_isとしてモジュールレベルのプライベート関数に移動使用例:
テストの整備
TODOだったテストを含め、31ケースに拡充した。
TestSuffixArrayTestLcpArrayTestZAlgorithmTestStringProtocol__len__・__getitem__(スライス含む)・__repr__・__str__Generated by Claude Code