Burrows–Wheeler transform: Difference between revisions

Improve Seed7 example
(Add Seed7 example)
(Improve Seed7 example)
Line 2,559:
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const func string: burrowsWheelerTransform (in string: START_MARKERstri) is "\256;";func
const string: END_MARKER is "\257;";
 
const func string: burrowsWheelerTransform (in var string: stri) is func
result
var string: encoded is "";
Line 2,570 ⟶ 2,567:
var array string: rotations is 0 times "";
begin
length := succ(length(stri));
if pos(stri, START_MARKER) <> 0 or pos(stri, END_MARKER) <> 0 then
raise RANGE_ERROR; # Input string cannot contain START_MARKER and END_MARKER characters.
end if;
stri := START_MARKER & stri & END_MARKER;
length := length(stri);
rotations := length times "";
for index range 1 to length do
rotations[index] := stri[index ..] & "\256;" & stri[.. pred(index)];
end for;
rotations := sort(rotations);
Line 2,602 ⟶ 2,595:
rotations := sort(rotations);
end for;
decoded := rotations[1];
for index range 1 to length until decoded <> "" do
index := pos(decoded, "\256;");
if endsWith(rotations[index], END_MARKER) then
decoded := rotationsdecoded[succ(index) ..][2 & decoded[.. pred(lengthindex)];
end if;
end for;
end func;
 
Line 2,629 ⟶ 2,620:
test("TO BE OR NOT TO BE OR WANT TO BE OR NOT?");
test("SIX.MIXED.PIXIES.SIFT.SIXTY.PIXIE.DUST.BOXES");
end func;</syntaxhighlight>
</syntaxhighlight>
{{out}}
<pre>
Line 2,654 ⟶ 2,644:
---> SIX.MIXED.PIXIES.SIFT.SIXTY.PIXIE.DUST.BOXES
</pre>
 
=={{header|Sidef}}==
{{trans|Python}}
29

edits