|
5 | 5 | import com.badlogic.gdx.utils.ObjectIntMap;
|
6 | 6 | import com.badlogic.gdx.utils.ObjectSet;
|
7 | 7 |
|
| 8 | +import java.util.ArrayList; |
| 9 | +import java.util.HashMap; |
| 10 | +import java.util.HashSet; |
| 11 | + |
8 | 12 | public class LZIntEncoding {
|
9 | 13 | public static int[] compressToInts(String uncompressedStr) {
|
10 | 14 | if (uncompressedStr == null) return null;
|
11 | 15 | if (uncompressedStr.isEmpty()) return new int[0];
|
12 | 16 | final int bitsPerChar = 32;
|
13 | 17 | int i, value;
|
14 |
| - ObjectIntMap<String> context_dictionary = new ObjectIntMap<>(); |
15 |
| - ObjectSet<String> context_dictionaryToCreate = new ObjectSet<>(); |
| 18 | + HashMap<String, Integer> context_dictionary = new HashMap<>(256, 0.5f); |
| 19 | + HashSet<String> context_dictionaryToCreate = new HashSet<>(256, 0.5f); |
16 | 20 | String context_c;
|
17 | 21 | String context_wc;
|
18 | 22 | String context_w = "";
|
@@ -91,7 +95,7 @@ public static int[] compressToInts(String uncompressedStr) {
|
91 | 95 | }
|
92 | 96 | context_dictionaryToCreate.remove(context_w);
|
93 | 97 | } else {
|
94 |
| - value = context_dictionary.get(context_w, 0); |
| 98 | + value = context_dictionary.get(context_w); |
95 | 99 | for (i = 0; i < context_numBits; i++) {
|
96 | 100 | context_data_val = (context_data_val << 1) | (value & 1);
|
97 | 101 | if (context_data_position == bitsPerChar - 1) {
|
@@ -170,7 +174,7 @@ public static int[] compressToInts(String uncompressedStr) {
|
170 | 174 |
|
171 | 175 | context_dictionaryToCreate.remove(context_w);
|
172 | 176 | } else {
|
173 |
| - value = context_dictionary.get(context_w, 0); |
| 177 | + value = context_dictionary.get(context_w); |
174 | 178 | for (i = 0; i < context_numBits; i++) {
|
175 | 179 | context_data_val = (context_data_val << 1) | (value & 1);
|
176 | 180 | if (context_data_position == bitsPerChar - 1) {
|
@@ -218,7 +222,7 @@ public static String decompressFromInts(int[] getNextValue) {
|
218 | 222 | if(length == 0)
|
219 | 223 | return "";
|
220 | 224 | final int resetValue = 0x80000000;
|
221 |
| - Array<String> dictionary = new Array<>(String.class); |
| 225 | + ArrayList<String> dictionary = new ArrayList<>(length >>> 1); |
222 | 226 | int enlargeIn = 4, dictSize = 4, numBits = 3, position = resetValue, index = 1, resb, maxpower, power;
|
223 | 227 | String entry, w, c;
|
224 | 228 | StringBuilder res = new StringBuilder(length);
|
@@ -340,7 +344,7 @@ public static String decompressFromInts(int[] getNextValue) {
|
340 | 344 | numBits++;
|
341 | 345 | }
|
342 | 346 |
|
343 |
| - if (cc < dictionary.size && dictionary.get(cc) != null) { |
| 347 | + if (cc < dictionary.size() && dictionary.get(cc) != null) { |
344 | 348 | entry = dictionary.get(cc);
|
345 | 349 | } else {
|
346 | 350 | if (cc == dictSize) {
|
|
0 commit comments