anly2 / cirrus-board

A Cloud Management Console UI with focus on multi-item edits. Additional goal is for it to be a hostless single-page web application.
0 stars 0 forks source link

Implement a simple compression algorithm #11

Open anly2 opened 5 years ago

anly2 commented 5 years ago

Mostly as an exercise, implement a compression algorithm.

Akin to RLE (Run-Length Encoding) and double RLE: Find the longest repeating substring. Replace it with a special symbol. Store the mapping. Stretch goal: pick most effective replacement by calculating char saving and sorting on that.

Additionally, generate the self-uncompressing snippet.

// selfUncompressing = 'String.prototype.r = String.prototype.replaceAll;'
// selfUncompressing += "'compressed'.r('яш', 'longRepeatedString').r('я', 'evenLongerRepeatedString')"
// base64EncodedString = btoa('selfUncompressing')
eval(atob('base64EncodedString'))
anly2 commented 5 years ago

See if ambiguous cases like "aa" vs "a", "a" can be handled without completly abandoning the idea. (Huffman encoding, but not just binary?)