intWA[MAXN],WB[MAXN],WV[MAXN],WS[MAXN];intcmpint*r,intAintBintl) { returnR[a] = = R[b] && r[a+l] = = r[b+l];}voidDa (int*r,int*sa,intNintm) { intI, J, p, *x = WA, *y = WB, *T; for(i =0; I < m; i++) Ws[i]=0; for(i =0; I < n; i++) Ws[x[i]= r[i]]++; for(i =1; I < m; i++) Ws[i]+ = ws[i-1]; for(i = n1; I >=0; i--) sa[--ws[x[i]] =i; for(j =1, p =1; P < n; J <<=1, M =p) { for*pb=0, i = n-j; I < n; i++) Y[p++]=i; for(i =0; I < n; i++) if(Sa[i] >=j) Y[p+ +] = Sa[i]-J; for(i =0; I < n; i++) Wv[i]=X[y[i]]; for(i =0; I < m; i++) Ws[i]=0; for(i =0; I < n; i++) Ws[wv[i]]++; for(i =1; I < m; i++) Ws[i]+ = ws[i-1]; for(i = n1; I >=0; i--) sa[--ws[wv[i]] =Y[i]; for(t = x,x = Y,y = T,p =1, x[sa[0]] =0, i =1; I < n;i++) X[sa[i]]=CMP (y,sa[i-1],sa[i],j)? p1:p + +; }}
The suffix array finally gets the SA and RANK two arrays, Sa[i] is the row I name who, Rank[i] is the first character to begin with the suffix row number, because any suffix has a definite size, so the SA is strictly from small to large arrangement, that is, any I have sa[i]<sa[ I+1]
Then just say the array used, the x array is an unfinished rank array, the Y array is a pseudo "SA" array to compare, and the WS array is the prefix and array of rank. Initialize the words y[i]=n-i, because the first interview when the default words must be supplemented by the length of the order, then y[0] that is the smallest auxiliary beginning is the last one, and then traverse the time is actually from y[n-1] that is 0 start, so the original code is not very reasonable written.
The WV array is not necessary.
First, the question of the keyword, the initial first keyword is s[i], the second keyword is its subscript i, and then into the for loop in the first keyword is s[i,i+2^k-1], the second keyword is s[i+2^k,i+2^ (k+1)-1].
Sa[--ws[wv[i]] = Y[i]; This is the key statement of the sort, for the first sort keyword is the same case, then the second keyword is the larger the more in the back, in order to ensure this, from y[n-1] to y[0] traversal.
This is the use of the bucket sorting method, that is, the first keyword is the same must be in a continuous and the rest of the non-intersecting areas, can be combined with the preprocessing that paragraph to understand, because in the space is not continuous distribution, so this paragraph will be a bit difficult to understand
Suffix array Multiplication Method understanding