MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / decompress

Method decompress

src/main/java/com/thealgorithms/compression/LZ77.java:142–167  ·  view source on GitHub ↗

Decompresses a list of LZ77 tokens back into the original string. @param compressedData The list of Token objects. Must not be null. @return The original, uncompressed string.

(List<Token> compressedData)

Source from the content-addressed store, hash-verified

140 * @return The original, uncompressed string.
141 */
142 public static String decompress(List<Token> compressedData) {
143 if (compressedData == null) {
144 return "";
145 }
146
147 StringBuilder decompressedText = new StringBuilder();
148
149 for (Token token : compressedData) {
150 // Copy matched characters from the sliding window
151 if (token.length > 0) {
152 int startIndex = decompressedText.length() - token.offset;
153
154 // Handle overlapping matches (e.g., when length > offset)
155 for (int i = 0; i < token.length; i++) {
156 decompressedText.append(decompressedText.charAt(startIndex + i));
157 }
158 }
159
160 // Append the next character (if not END_OF_STREAM)
161 if (token.nextChar != END_OF_STREAM) {
162 decompressedText.append(token.nextChar);
163 }
164 }
165
166 return decompressedText.toString();
167 }
168}

Callers 15

testNoInitialRepeatsMethod · 0.95
testLongerExampleMethod · 0.95
testEmptyStringMethod · 0.95
testAllSameCharactersMethod · 0.95
testSingleCharacterMethod · 0.95
testMatchToEndMethod · 0.95
testSmallWindowSizeMethod · 0.95

Calls 3

lengthMethod · 0.80
appendMethod · 0.45
toStringMethod · 0.45

Tested by 15

testNoInitialRepeatsMethod · 0.76
testLongerExampleMethod · 0.76
testEmptyStringMethod · 0.76
testAllSameCharactersMethod · 0.76
testSingleCharacterMethod · 0.76
testMatchToEndMethod · 0.76
testSmallWindowSizeMethod · 0.76