Menu

[r350]: / XRLE.MPL  Maximize  Restore  History

Download this file

44 lines (34 with data), 786 Bytes

/*
  RUN-LENGTH ENCODING - MPL VERSION
  A VERY SIMPLE RLE. NO ERROR CHECKING.
  HTTPS://ROSETTACODE.ORG/WIKI/RUN-LENGTH_ENCODING
*/

##LIBHDR

RLE.ENCODE(D,S;DD,SS,TT,C) [
  DD=0; SS=1; SS<=%S @ [
    C=S%(TT=SS); @ ++TT<=%S ? C==S%TT;
    D%++DD=TT-SS; D%++DD=C; SS=TT
  ];
  %D=DD
]

RLE.DECODE(D,S;DD,SS,C,I) [
  DD=SS=0; SS<%S @ [
    I=S%++SS; C=S%++SS;
    >I-- @ D%++DD=C
  ];
  %D=DD
]

RLE.DISPLAY(D;DD) [
  DD=0; DD<%D @ WRITEF("%N%C",D%++DD,D%++DD); NEWLINE()
]


.ORG="WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
.NEW=!.STR127
.RLE=!.STR127

.() [
  RLE.ENCODE(.RLE,.ORG);
  RLE.DECODE(.NEW,.RLE);
  WRITEF("ORG = %S*N", .ORG);
  WRITES("RLE = "); RLE.DISPLAY(.RLE);
  WRITEF("NEW = %S*N", .NEW);
  0
]

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.