<s> __author__ = """<STR_LIT>""" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from os import getcwd <EOL> from os import sys <EOL> sys . path . append ( getcwd ( ) ) <EOL> from MOAL . helpers . display import Section <EOL> from MOAL . helpers . display import prnt <EOL> from MOAL . helpers . text import words_unix_dict <EOL> class SuffixArray : <EOL> def __init__ ( self , strings = None ) : <EOL> self . strings = strings if strings is not None else [ ] <EOL> def __str__ ( self ) : <EOL> return str ( self . strings ) <EOL> def __getitem__ ( self , string ) : <EOL> self . strings . append ( string ) <EOL> def __setitem__ ( self , string , val ) : <EOL> self . strings [ string ] = val <EOL> def __delitem__ ( self , string ) : <EOL> del self . strings [ string ] <EOL> @ classmethod <EOL> def make_substring ( cls , string ) : <EOL> return [ string [ k : ] + '<STR_LIT:$>' for k , char in enumerate ( reversed ( string ) ) ] <EOL> def make_superstring ( self , strings = None ) : <EOL> if strings is None : <EOL> strings = self . strings <EOL> self . strings = [ [ self . make_substring ( string ) ] for string in strings ] <EOL> class PrefixArray ( SuffixArray ) : <EOL> @ classmethod <EOL> def make_substring ( cls , string ) : <EOL> return [ string [ k : ] + '<STR_LIT:$>' for k , char in enumerate ( string ) ] <EOL> class InfixArray ( SuffixArray ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def make_substring ( cls , string , bisector = <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> ia = [ ] <EOL> if len ( string ) < bisector : <EOL> bisector = len ( string ) <EOL> for k , char in enumerate ( string ) : <EOL> ia . append ( [ string [ bisector : ] + '<STR_LIT:$>' , string [ : bisector ] ] ) <EOL> return ia <EOL> class SuperSuffixArray ( SuffixArray ) : <EOL> def _view ( self , suffixes ) : <EOL> prnt ( suffixes [ <NUM_LIT:0> ] [ : - <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> for k , substr in enumerate ( suffixes ) : <EOL> max_width = ( len ( suffixes [ : - <NUM_LIT:1> ] ) + <NUM_LIT:30> ) <EOL> spaces = '<STR_LIT>' * max_width <EOL> print ( spaces ) <EOL> print ( '<STR_LIT>' . format ( <EOL> substr , '<STR_LIT:U+0020>' * ( max_width - len ( substr ) - <NUM_LIT:12> ) , len ( substr ) , k ) ) <EOL> def __repr__ ( self ) : <EOL> for suffix_group in self . strings : <EOL> for _ , suffixes in enumerate ( suffix_group ) : <EOL> self . _view ( suffixes ) <EOL> return '<STR_LIT>' <EOL> def sort ( self ) : <EOL> for k , suffix_group in enumerate ( self . strings ) : <EOL> for j , suffixes in enumerate ( suffix_group ) : <EOL> self . strings [ k ] [ j ] = sorted ( self . strings [ k ] [ j ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> with Section ( '<STR_LIT>' ) : <EOL> DEBUG = False <EOL> word_gen = words_unix_dict ( ) <EOL> iarray = InfixArray ( ) <EOL> iarray . make_superstring ( strings = [ word_gen . next ( ) for _ in range ( <NUM_LIT:2> ) ] ) <EOL> prnt ( '<STR_LIT>' , iarray ) <EOL> ssarray = SuperSuffixArray ( ) <EOL> ssarray . make_superstring ( strings = [ word_gen . next ( ) for _ in range ( <NUM_LIT:10> ) ] ) <EOL> prnt ( '<STR_LIT>' , ssarray , func = repr ) <EOL> ssarray . sort ( ) <EOL> prnt ( '<STR_LIT>' , ssarray , func = repr ) <EOL> if DEBUG : <EOL> ssarray2 = SuperSuffixArray ( ) <EOL> ssarray2 . make_superstring ( <EOL> strings = [ '<STR_LIT>' ] ) <EOL> prnt ( '<STR_LIT>' , ssarray2 , func = repr ) </s>
