Skip to content

Refactor acl_string: convert namespace class to proper String class + comprehensive tests - #21

Merged
shakayami merged 3 commits into
masterfrom
claude/string-implementation-refactor-dqw5rw
Jul 11, 2026
Merged

Refactor acl_string: convert namespace class to proper String class + comprehensive tests#21
shakayami merged 3 commits into
masterfrom
claude/string-implementation-refactor-dqw5rw

Conversation

@shakayami

Copy link
Copy Markdown
Owner

変更内容

acl_string.py のリファクタリング

class string は全メソッドが self なしで定義されており、クラスを名前空間代わりに使うだけの実装だった。これを文字列をラップする本物のクラス String に変更した。

主な変更:

  • class stringclass String に改名
  • コンストラクタ String(s) で文字列または整数リストをラップ
  • suffix_array()lcp_array(sa=None)z_algorithm() をインスタンスメソッドに変換
  • lcp_array()sa 省略時に内部で suffix_array() を自動計算
  • __len____getitem____repr____str__ でシーケンスプロトコルに対応
  • 内部ヘルパー sa_is_sa_is としてモジュールレベルのプライベート関数に移動

使用例:

from acl_string import String

st = String("abcbcba")
sa = st.suffix_array()
lcp = st.lcp_array(sa)   # or st.lcp_array() for auto-SA
z = st.z_algorithm()

テストの整備

TODOだったテストを含め、31ケースに拡充した。

クラス テスト数 内容
TestSuffixArray 12 空文字・1文字・2文字・全同一・既知文字列・整数リスト・practice2-I
TestLcpArray 6 基本・SA自動計算・全同一・全異なる・1文字・mississippi境界
TestZAlgorithm 8 空・1文字・全同一・既知パターン・Z不変条件・パターン検索応用
TestStringProtocol 5 __len____getitem__(スライス含む)・__repr____str__

Generated by Claude Code

claude added 2 commits July 11, 2026 06:58
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
@shakayami
shakayami merged commit 30426a7 into master Jul 11, 2026
19 checks passed
@shakayami
shakayami deleted the claude/string-implementation-refactor-dqw5rw branch July 11, 2026 07:11
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.

現状のStringの実装がクラスである意味ないので名前空間にするかクラスっぽくする

2 participants