Пример #1
0
def decompress(compressed_data):
    decompressed_string = ""

    for d in compressed_data:
        if d["length"] != 0:
            decompressed_string = back_copy(decompressed_string, d["length"], d["offset"])
        decompressed_string += d["symbol"]

    return decompressed_string
Пример #2
0
#
#Kabopan - Readable Algorithms. Public Domain, 2007-2009

from kbp.comp._lz77 import find_longest_match, back_copy

assert find_longest_match("abc","a") == (3, 1)
assert find_longest_match("abc","d") == (0, 0)
assert find_longest_match("abcab","ab") == (2, 2)

assert back_copy("a", 1, 1) == "aa"
assert back_copy("ab", 2, 2) == "abab"
assert back_copy("duplicate me please", 9, 19) == "duplicate me pleaseduplicate"