39. Strings stdlib (std.strings, 2026-11-21)
- 39.1 Alphabet-domain automata (
Trie<A>,AhoCorasick<A>,SuffixAutomaton<A>,PalindromicTree<A>). String automata parameterize over an alphabet domainA(such as'a'..='z'or0..2) rather than hardcoding 26 lowercase letters. Reason: binary/digit/general alphabets avoid wasted memory andc - 'a'arithmetic while keeping[A]?Int/[A]Intinline and bounds-checked at domain entry (spec/lib/strings.md§2). Reverse: add a concreteStr-specialized wrapper if ports show repeated[Letter(c) for c in s]boilerplate.
- 39.2 Layered suffix arrays: O(n) free functions plus O(n log n)
SuffixArray<T>.suffix_array(s)andlcp_array(s, sa)stay O(n) SA-IS + Kasai with no hidden RMQ build;SuffixArray<T>(s)buildssa,rank,lcp, and a sparse table for O(1)lcp_betweenandcompare, O(|pat| log n)matches/count, and O(log n)lcp_range. Reason: visible costs (no secret O(n log n) work behindsuffix_array) while eliminating repeated binary search and RMQ boilerplate (research/archive/frictions/friction-backlog-batch-10.mdT4). Reverse: dropSuffixArray<T>.
- 39.3
manacher(s)returnsPalindromes(odd, even)with O(1)is_palindrome(l, r). Keepingoddandevenas public fields preserves direct radius access while addingis_palindrome(l, r),count, andlongestso callers never re-derive the center formula. Reason: eliminates a classic off-by-one bug class. Reverse: return a plain tuple(odd, even).
- 39.4
Hash2D<R, C>returns double-modHashVal, not a single-modInt. Promoted fromexamples/local-lib/str/hash2d.cp, upgraded to the same double-modHashValasRollingHashso 2D hashes are anti-hack safe on Codeforces. Reason: single 31-bit hashes collide easily at contest grid sizes. Reverse: revert to a singleMod<2147483647>.