Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
76
Task/LZW-compression/REXX/lzw-compression-1.rexx
Normal file
76
Task/LZW-compression/REXX/lzw-compression-1.rexx
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/* REXX ---------------------------------------------------------------
|
||||
* 20.07.2014 Walter Pachl translated from Java
|
||||
* 21.07.2014 WP allow for blanks in the string
|
||||
*--------------------------------------------------------------------*/
|
||||
Parse Arg str
|
||||
default="TOBEORNOTTOBEORTOBEORNOT"
|
||||
If str='' Then
|
||||
str=default
|
||||
/* str=space(str,0) */
|
||||
Say 'str='str
|
||||
compressed = compress(str)
|
||||
Say compressed
|
||||
If str=default Then Do
|
||||
cx='[84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263]'
|
||||
If cx==compressed Then Say 'compression ok'
|
||||
End
|
||||
decompressed = decompress(compressed)
|
||||
Say 'dec='decompressed
|
||||
If decompressed=str Then Say 'decompression ok'
|
||||
Exit
|
||||
|
||||
compress: Procedure
|
||||
Parse Arg uncompressed
|
||||
dict.=''
|
||||
Do i=0 To 255
|
||||
z=d2c(i)
|
||||
d.i=z
|
||||
dict.z=i
|
||||
End
|
||||
dict_size=256
|
||||
res='['
|
||||
w=''
|
||||
Do i=1 To length(uncompressed)
|
||||
c=substr(uncompressed,i,1)
|
||||
wc=w||c
|
||||
If dict.wc<>'' Then
|
||||
w=wc
|
||||
Else Do
|
||||
res=res||dict.w', '
|
||||
dict.wc=dict_size
|
||||
dict_size=dict_size+1
|
||||
w=c
|
||||
End
|
||||
End
|
||||
If w<>'' Then
|
||||
res=res||dict.w', '
|
||||
Return left(res,length(res)-2)']'
|
||||
|
||||
decompress: Procedure
|
||||
Parse Arg compressed
|
||||
compressed=space(translate(compressed,'','[],'))
|
||||
d.=''
|
||||
Do i=0 To 255
|
||||
z=d2c(i)
|
||||
d.i=z
|
||||
End
|
||||
dict_size=256
|
||||
Parse Var compressed w compressed
|
||||
res=d.w
|
||||
w=d.w
|
||||
Do i=1 To words(compressed)
|
||||
k=word(compressed,i)
|
||||
Select
|
||||
When d.k<>'' | d.k==' ' then /* allow for blank */
|
||||
entry=d.k
|
||||
When k=dict_size Then
|
||||
entry=w||substr(w,1,1)
|
||||
Otherwise
|
||||
Say "Bad compressed k: " k
|
||||
End
|
||||
res=res||entry
|
||||
d.dict_size=w||substr(entry,1,1)
|
||||
dict_size=dict_size+1
|
||||
w=entry
|
||||
End
|
||||
Return res
|
||||
24
Task/LZW-compression/REXX/lzw-compression-2.rexx
Normal file
24
Task/LZW-compression/REXX/lzw-compression-2.rexx
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*REXX program compresses text using the LZW (Lempel─Ziv─Welch), and reconstitutes it.*/
|
||||
$$$= '"There is nothing permanent except change." ─── Heraclitus [540 ── 475 BCE]'
|
||||
parse arg text; if text='' then text= $$$ /*get an optional argument from the CL.*/
|
||||
say 'original text=' text /* [↑] Not specified? Then use default*/
|
||||
cypher= LZWc(text) /*compress text using the LZW algorithm*/
|
||||
say 'reconstituted=' LZWd(cypher) /*display the reconstituted string. */
|
||||
say; say ' LZW integers=' cypher /* " " LZW integers used. */
|
||||
exit 0 /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
LZWi: arg i,@.; #=256; do j=0 for #; _=d2c(j); if i then @.j=_; else @._=j; end; return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
LZWc: procedure; parse arg y,,$; call LZWi 0; w= /*LZW compress.*/
|
||||
do k=1 for length(y)+1; z= w || substr(y, k, 1)
|
||||
if @.z=='' then do; $= $ @.w; @.z= #; #= # + 1; w= substr(y, k, 1); end
|
||||
else w= z /*#: the dictionary size.*/
|
||||
end /*k*/; return substr($, 2) /*elide a leading blank. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
LZWd: procedure; parse arg x y; call LZWi 1; $= @.x; w= $ /*LZW decompress.*/
|
||||
do k=1 for words(y); z= word(y, k)
|
||||
if @.z\=='' | @.k==" " then ?= @.z
|
||||
else if z==# then ?= w || left(w, 1)
|
||||
$= $ || ?
|
||||
@.#= w || left(?, 1); w= ?; #= # + 1 /*bump dict. size*/
|
||||
end /*k*/; return $
|
||||
Loading…
Add table
Add a link
Reference in a new issue