1- '''
1+ """
22suffix_array.py
33
44Professional implementation of Suffix Array and LCP (Longest Common Prefix) array in Python.
1111
1212Author: Idris Ibrahim Erten
1313License: MIT
14- '''
14+ """
15+
1516
1617def build_suffix_array (s : str ) -> list [int ]:
1718 """
@@ -27,7 +28,7 @@ def build_suffix_array(s: str) -> list[int]:
2728 O(n log n) time and O(n) space.
2829 """
2930 # Append a sentinel that is lexicographically smaller than all other characters
30- s += ' \0 '
31+ s += " \0 "
3132 n = len (s )
3233 # Initial ranking by character code
3334 ranks = [ord (c ) for c in s ]
@@ -89,9 +90,9 @@ def build_lcp_array(s: str, sa: list[int]) -> list[int]:
8990 return lcp [1 :]
9091
9192
92- if __name__ == ' __main__' :
93+ if __name__ == " __main__" :
9394 # Example usage and simple tests
94- test_strings = [' banana' , ' abracadabra' , ' mississippi' ]
95+ test_strings = [" banana" , " abracadabra" , " mississippi" ]
9596 for s in test_strings :
9697 sa = build_suffix_array (s )
9798 lcp = build_lcp_array (s , sa )
@@ -100,7 +101,7 @@ def build_lcp_array(s: str, sa: list[int]) -> list[int]:
100101 print (f"LCP Array : { lcp } \n " )
101102
102103 # Assertions for correctness
103- s = ' banana'
104+ s = " banana"
104105 expected_sa = [5 , 3 , 1 , 0 , 4 , 2 ] # indices of sorted suffixes
105- assert build_suffix_array (s ) == expected_sa , ' SA test failed'
106- print (' All tests passed!' )
106+ assert build_suffix_array (s ) == expected_sa , " SA test failed"
107+ print (" All tests passed!" )
0 commit comments