Open the context
Choose the project folder and name the files or behavior involved.
Encode at most 4096 bytes into LZ78 dictionary-index and next-byte pairs. Test empty and repeated input, using a final null byte marker only for a phrase already in the dictionary.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def lz78_tokens(data):
if type(data) is not bytes or len(data) > 4096:
raise ValueError("lz78.input")
dictionary, phrase, output = {b"": 0}, b"", []
for byte in data:
extended = phrase + bytes([byte])
if extended in dictionary:
phrase = extended
else:
output.append((dictionary[phrase], byte))
dictionary[extended] = len(dictionary)
phrase = b""
if phrase:
output.append((dictionary[phrase], None))
return outputThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.