#NEWLINE# def get_lcp( self ) : #NEWLINE# #INDENT# 'Returns the LCP array' #NEWLINE# if ( not self . _completed_suffixes ) : #NEWLINE# #INDENT# self . get_suffixes ( ) #NEWLINE# #UNINDENT# assert self . _completed_suffixes #NEWLINE# rank = [ [ 0 for _ in xrange ( len ( d_list ) ) ] for d_list in self . data ] #NEWLINE# lcp = [ 0 for _ in xrange ( self . length ) ] #NEWLINE# for i in range ( self . length ) : #NEWLINE# #INDENT# ( glyph_idx , tok_idx ) = self . suffixes [ i ] #NEWLINE# rank [ glyph_idx ] [ tok_idx ] = i #NEWLINE# #UNINDENT# for glyph_idx in xrange ( len ( self . data ) ) : #NEWLINE# #INDENT# cur_h = 0 #NEWLINE# chstring = rank . data [ glyph_idx ] #NEWLINE# for tok_idx in xrange ( len ( chstring ) ) : #NEWLINE# #INDENT# cur_rank = rank [ glyph_idx ] [ tok_idx ] #NEWLINE# if ( cur_rank > 0 ) : #NEWLINE# #INDENT# ( last_glidx , last_tidx ) = self . suffixes [ ( cur_rank - 1 ) ] #NEWLINE# last_chstring = self . data [ last_glidx ] #NEWLINE# while ( ( ( last_tidx + cur_h ) < len ( last_chstring ) ) and ( ( tok_idx + cur_h ) < len ( chstring ) ) and ( last_chstring [ ( last_tidx + cur_h ) ] == self . data [ glyph_idx ] [ ( tok_idx + cur_h ) ] ) ) : #NEWLINE# #INDENT# cur_h += 1 #NEWLINE# #UNINDENT# lcp [ cur_rank ] = cur_h #NEWLINE# if ( cur_h > 0 ) : #NEWLINE# #INDENT# cur_h -= 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return lcp