import algorithm from sequtils import repeat import strutils except repeat const Stx = '\2' Etx = '\3' #--------------------------------------------------------------------------------------------------- func bwTransform*(s: string): string = ## Apply Burrows–Wheeler transform to input string. doAssert(Stx notin s and Etx notin s, "Input string cannot contain STX and ETX characters") let s = Stx & s & Etx # Add start and end of text marker. # Build the table of rotated strings and sort it. var table = newSeqOfCap[string](s.len) for i in 0..s.high: table.add(s[i + 1..^1] & s[0..i]) table.sort() # Extract last column of the table. for item in table: result.add(item[^1]) #--------------------------------------------------------------------------------------------------- func invBwTransform*(r: string): string = ## Apply inverse Burrows–Wheeler transform. # Build table. var table = repeat("", r.len) for _ in 1..r.len: for i in 0..