Last active
January 12, 2020 23:33
-
-
Save mabj/0b6dfd8a7761cc69f0455ce4ffd96140 to your computer and use it in GitHub Desktop.
This file contains 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
class Compressor: | |
def init(level): | |
buffer = List(level*2) | |
def add(element): | |
tmp = None | |
if not element: | |
return tmp | |
if len(buffer) == level*2: | |
tmp = buffer.pop(0) | |
buffer.append(element) | |
analyse() | |
return tmp | |
def analyse(): | |
if buffer[0:half] == buffer[half:]: | |
update_counters() | |
buffer = buffer[0:half] | |
def update_counters(): | |
for i in range(0:level): | |
buffer[i].counter += buffer[i+level].counter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment