以下提供模板:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
h:高度數組 | |
sa:後綴數組 | |
rank:排名 | |
*/ | |
inline void suffix_array_lcp(const char *s,int len,int *h,int *sa,int *rank){ | |
for(int i=0;i<len;++i)rank[sa[i]]=i; | |
for(int i=0,k=0;i<len;++i){ | |
if(rank[i]==0)continue; | |
if(k)--k; | |
while(s[i+k]==s[sa[rank[i]-1]+k])++k; | |
h[rank[i]]=k; | |
} | |
h[0]=0; | |
} |
沒有留言:
張貼留言