Burrows–Wheeler transform: Difference between revisions

m
→‎{{header|REXX}}: changed some comments and whitespace.
m (→‎{{header|REXX}}: changed some comments and whitespace.)
Line 1,437:
BWT: procedure expose ?.; parse arg y,,$ /*obtain the input; nullify $ string. */
?.1= 'fd'x; ?.2= "fc"x /*assign the STX and ETX strings. */
do i=1 for 2 /* [↓] check for invalid input string.*/
_= verify(y, ?.i, 'M'); if _==0 then iterate; er= '***error*** BWT: '
say er "invalid input: " y
say er 'The input string contains an invalid character at position' _"."; exit 13_
end /*i*/ /* [↑] if error, perform a hard exit.*/
y= ?.1 || y || ?.2; L= length(y) /*obtainget the input; & add a fence; togel itlen.*/
L@.1= length(y); m= L - 1 /*getdefine the lengthfirst element of new text;the get L-1.table*/
@.1= y do j=2 for m; _= j-1 /*now, define the first elementrest of the tableelements.*/
do j=2 for m; _= j-1 /*now, define the rest of the elements.*/
@.j= right(@._,1)left(@._,m) /*construct a table from the Y input.*/
end /*j*/ /* [↑] each element: left & right part*/
call cSort L /*invoke lexicographical sort for array*/
do k=1 for L /* [↓] construct the answer from array*/
$= $ || right(@.k, 1) /*build the answer from each of ··· */
end /*k*/ /* ··· the array's right─most character*/
return $ /*return the constructed answer. */