Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/java/com/thealgorithms/compression/LZ78.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import java.util.objects;
/**
* An implementation of the Lempel-Ziv 78 (LZ78) compression algorithm.
* <p>
Expand Down Expand Up @@ -97,12 +97,13 @@ public static List<Token> compress(String text) {
}

// Handle remaining phrase at end of input
if (currentNode != root) {
if (!currentNode.equals(root)) {
compressedOutput.add(new Token(lastMatchedIndex, END_OF_STREAM));
}

return compressedOutput;
}
}


/**
* Decompresses a list of LZ78 tokens back into the original string.
Expand Down
Loading