-
-
Save cloudwu/6349562 to your computer and use it in GitHub Desktop.
LZW 伪代码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Encode: | |
[.c.] = Empty; | |
[.c.]k = First Character in CharStream; | |
while ([.c.]k != EOF ) | |
{ | |
if ( [.c.]k is in the StringTable) | |
{ | |
[.c.] = [.c.]k; | |
} | |
else | |
{ | |
add [.c.]k to the StringTable; | |
Output the Index of [.c.] in the StringTable to the CodeStream; | |
[.c.] = k; | |
} | |
[.c.]k = Next Character in CharStream; | |
} | |
Output the Index of [.c.] in the StringTable to the CodeStream; | |
Decode: | |
[code] = First Code in the CodeStream; | |
Output the String for [code] to the CharStream; | |
[old] = [code]; | |
[code] = Next Code in the CodeStream; | |
while ([code] != EOF ) | |
{ | |
if ( [code] is in the StringTable) | |
{ | |
Output the String for [code] to the CharStream; // 输出[code]所对应的字符串 | |
[...] = translation for [old]; // [old]所对应的字符串 | |
k = first character of translation for [code]; // [code]所对应的字符串的第一个字符 | |
add [...]k to the StringTable; | |
[old] = [code]; | |
} | |
else | |
{ | |
[...] = translation for [old]; | |
k = first character of [...]; | |
Output [...]k to CharStream; | |
add [...]k to the StringTable; | |
[old] = [code]; | |
} | |
[code] = Next Code in the CodeStream; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment