求height数组
procedure getheight; var i,po1,po2:longint; begin for i:=1 to len do begin if k>0 then k:=k-1; po1:=i;po2:=sa[rank[i]-1]; while (a[po1+k]=a[po2+k]) and (po1+k<=len) and (po2+k<=len) do inc(k); height[i]:=k; end; end;
其中height[i]表示suffix(i)与suffix(sa[rank[i]-1])的最长公共前缀
____________________________________________________
c++
void getheight(){ int k=0; int po1,po2; for (int i=1;i<=n;i++){ po1=i,po2=sa[rank[i]-1]; if (k) k--; while ((st[po1+k]==st[po2+k])&&(po1+k<=len)&&(po2+k<=len)) k++; height[rank[i]-1]=k; } }
其中height[i]表示rank[i]+1与rank[i]的最长公共前缀