Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,98 @@
|
|||
DEFINE SYMBOL_TABLE_SIZE="26"
|
||||
|
||||
PROC InitSymbolTable(BYTE ARRAY table BYTE len)
|
||||
BYTE i
|
||||
|
||||
FOR i=0 TO len-1
|
||||
DO
|
||||
table(i)=i+'a
|
||||
OD
|
||||
RETURN
|
||||
|
||||
BYTE FUNC Find(BYTE ARRAY table BYTE len,c)
|
||||
BYTE i
|
||||
|
||||
FOR i=0 TO len-1
|
||||
DO
|
||||
IF table(i)=c THEN
|
||||
RETURN (i)
|
||||
FI
|
||||
OD
|
||||
Break()
|
||||
RETURN (0)
|
||||
|
||||
PROC MoveToFront(BYTE ARRAY table BYTE len,pos)
|
||||
BYTE sym
|
||||
|
||||
sym=table(pos)
|
||||
WHILE pos>0
|
||||
DO
|
||||
table(pos)=table(pos-1)
|
||||
pos==-1
|
||||
OD
|
||||
table(pos)=sym
|
||||
RETURN
|
||||
|
||||
PROC Encode(CHAR ARRAY in BYTE ARRAY out BYTE POINTER outLen)
|
||||
BYTE ARRAY table(SYMBOL_TABLE_SIZE)
|
||||
BYTE i,pos
|
||||
|
||||
outLen^=0
|
||||
InitSymbolTable(table,SYMBOL_TABLE_SIZE)
|
||||
FOR i=1 TO in(0)
|
||||
DO
|
||||
pos=Find(table,SYMBOL_TABLE_SIZE,in(i))
|
||||
out(outLen^)=pos
|
||||
outLen^==+1
|
||||
MoveToFront(table,SYMBOL_TABLE_SIZE,pos)
|
||||
OD
|
||||
RETURN
|
||||
|
||||
PROC Decode(BYTE ARRAY in BYTE inLen CHAR ARRAY out)
|
||||
BYTE ARRAY table(SYMBOL_TABLE_SIZE)
|
||||
BYTE i,pos,len
|
||||
|
||||
len=0
|
||||
InitSymbolTable(table,SYMBOL_TABLE_SIZE)
|
||||
FOR i=0 TO inLen-1
|
||||
DO
|
||||
pos=in(i)
|
||||
len==+1
|
||||
out(len)=table(pos)
|
||||
MoveToFront(table,SYMBOL_TABLE_SIZE,pos)
|
||||
OD
|
||||
out(0)=len
|
||||
RETURN
|
||||
|
||||
PROC Test(CHAR ARRAY s)
|
||||
BYTE ARRAY encoded(255)
|
||||
CHAR ARRAY decoded(256)
|
||||
BYTE encodedLength,i
|
||||
|
||||
Print("Source: ")
|
||||
PrintE(s)
|
||||
|
||||
Encode(s,encoded,@encodedLength)
|
||||
Print("Encoded: ")
|
||||
FOR i=0 TO encodedLength-1
|
||||
DO
|
||||
PrintB(encoded(i)) Put(32)
|
||||
OD
|
||||
PutE()
|
||||
|
||||
Decode(encoded,encodedLength,decoded)
|
||||
Print("Decoded: ")
|
||||
PrintE(decoded)
|
||||
IF SCompare(s,decoded)=0 THEN
|
||||
PrintE("Decoded is equal to the source.")
|
||||
ELSE
|
||||
PrintE("Decoded is different from the source!")
|
||||
FI
|
||||
PutE()
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
Test("broood")
|
||||
Test("bananaaa")
|
||||
Test("hiphophiphop")
|
||||
RETURN
|
||||
Loading…
Add table
Add a link
Reference in a new issue