Burrows–Wheeler transform: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: simplified the code, eliminated the use of a subroutine.)
Line 741: Line 741:
$.7= "bad─bad thingy"'fd'x /* ◄─── this string can't be processed.*/
$.7= "bad─bad thingy"'fd'x /* ◄─── this string can't be processed.*/
end
end
/* [↑] show blank line between outputs*/

do t=1 while $.t\='' /*process each of the inputs (or input)*/
do t=1 while $.t\=''; if t\==1 then say /*process each of the inputs (or input)*/
if t\==1 then say /*insert a blank line between outputs. */
out= BWT($.t) /*invoke the BWT function, get result*/
out= BWT($.t) /*invoke the BWT function, get result*/
ori= iBWT(out) /* " " iBWT " " " */
ori= iBWT(out) /* " " iBWT " " " */
Line 754: Line 753:
BWT: procedure expose ?.; parse arg y,,$ /*obtain the input; nullify $ string. */
BWT: procedure expose ?.; parse arg y,,$ /*obtain the input; nullify $ string. */
?.1= 'fd'x; ?.2= "fc"x /*assign the STX and ETX strings. */
?.1= 'fd'x; ?.2= "fc"x /*assign the STX and ETX strings. */
do i=1 for 2 /* [↓] check for invalid input string.*/
do i=1 for 2 /* [↓] check for invalid input string.*/
loc= verify(y, ?.i, 'M') /*look for invalid character in input. */
_= verify(y, ?.i, 'M'); if _==0 then iterate; er= '***error*** BWT: '
say er "invalid input: " y
if loc\==0 then call BWTer /*there an " " " " ? */
say er 'The input string contains an invalid character at position' _"."; exit 13
end /*i*/ /* [↑] if error, perform a hard exit.*/
end /*i*/ /* [↑] if error, perform a hard exit.*/
y= ?.1 || y || ?.2 /*obtain the input; add a fence to it.*/
y= ?.1 || y || ?.2 /*obtain the input; add a fence to it.*/
L= length(y); m= L-1 /*get the length of new text; get L-1.*/
L= length(y); m= L-1 /*get the length of new text; get L-1.*/
Line 769: Line 769:
end /*k*/ /* ··· the array's right─most character*/
end /*k*/ /* ··· the array's right─most character*/
return $ /*return the constructed answer. */
return $ /*return the constructed answer. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
BWTer: er= '***error*** BWT: '; say er "invalid input: " y
say er 'The input string contains an invalid character at position' loc"."; exit 13
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
iBWT: procedure expose ?.; parse arg y,,@. /*obtain the input; nullify @. string.*/
iBWT: procedure expose ?.; parse arg y,,@. /*obtain the input; nullify @. string.*/