LZW compression: Difference between revisions
Content added Content deleted
Line 1,751: | Line 1,751: | ||
=={{header|EMal}}== |
=={{header|EMal}}== |
||
<syntaxhighlight lang="emal"> |
<syntaxhighlight lang="emal"> |
||
type LzwCompression |
|||
fun compress |
fun compress ← List by text uncompressed |
||
⚫ | |||
⚫ | |||
text w |
|||
text working ← Text.empty |
|||
⚫ | |||
⚫ | |||
for each text c in uncompressed |
for each text c in uncompressed |
||
text |
text augmented ← working + c |
||
if |
if symbolTable.has(augmented) |
||
working ← augmented |
|||
else |
else |
||
⚫ | |||
result.append(dictionary[w]) |
|||
int i ← symbolTable[working] |
|||
⚫ | |||
output.append(i) |
|||
w = c |
|||
working ← c |
|||
⚫ | |||
⚫ | |||
end |
end |
||
if not |
if not working.isEmpty() |
||
int i ← symbolTable[working] |
|||
⚫ | |||
output.append(i) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
text result = *w |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
text output ← *working |
|||
⚫ | |||
⚫ | |||
entry = dictionary[k] |
|||
⚫ | |||
⚫ | |||
⚫ | |||
entry = w + w[0] |
|||
s ← symbolTable[i] |
|||
⚫ | |||
s ← working + working[0] |
|||
else |
else |
||
error(65, "Error decompressing") |
error(65, "Error decompressing") |
||
end |
end |
||
output.append(s) |
|||
symbolTable.insert(symbolTable.length, working + s[0]) |
|||
working ← s |
|||
end |
end |
||
return |
return output |
||
end |
end |
||
List compressed = compress("TOBEORNOTTOBEORTOBEORNOT") |
List compressed = compress("TOBEORNOTTOBEORTOBEORNOT") |