Data update

This commit is contained in:
Ingy döt Net 2023-12-16 21:33:55 -08:00
parent 35bcdeebf8
commit 74c69a0df6
2427 changed files with 31826 additions and 3468 deletions

View file

@ -1,38 +1,43 @@
fun compress = List by text uncompressed
Map dictionary = text%int[].with(256, <int i|text%int(chr(i) => i))
text w
List result = int[]
type LzwCompression
fun compress ← List by text uncompressed
List output ← int[]
text working ← Text.EMPTY
Map symbolTable ← text%int[].with(256, <int i|text%int(chr(i) => i))
for each text c in uncompressed
text wc = w + c
if dictionary.has(wc)
w = wc
text augmented ← working + c
if symbolTable.has(augmented)
working ← augmented
else
result.append(dictionary[w])
dictionary.insert(wc, dictionary.length)
w = c
end
symbolTable.insert(augmented, symbolTable.length)
int i ← symbolTable[working]
output.append(i)
working ← c
end
end
if not w.isEmpty() do result.append(dictionary[w]) end
return result
if not working.isEmpty()
int i ← symbolTable[working]
output.append(i)
end
return output
end
fun decompress = text by List compressed
Map dictionary = int%text[].with(256, <int i|int%text(i => chr(i)))
text w = chr(compressed[0])
text result = *w
for each int k in compressed.extract(1)
text entry
if dictionary.has(k)
entry = dictionary[k]
else if k == dictionary.length
entry = w + w[0]
fun decompress text by List compressed
Map symbolTable ← int%text[].with(256, <int i|int%text(i => chr(i)))
text working ← symbolTable[compressed[0]]
text output ← *working
for each int i in compressed.extract(1)
text s
if symbolTable.has(i)
s ← symbolTable[i]
else if i æ symbolTable.length # cScSc problem
s ← working + working[0]
else
error(65, "Error decompressing")
end
result.append(entry)
dictionary.insert(dictionary.length, w + entry[0])
w = entry
output.append(s)
symbolTable.insert(symbolTable.length, working + s[0])
working ← s
end
return result
return output
end
List compressed = compress("TOBEORNOTTOBEORTOBEORNOT")
writeLine(compressed)