PPhraseNacre
Workflows

Coding workflows · LZ78 phrase tokens

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

LZ78 phrase tokens

A concrete starting point
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 output

The 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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗