!7 sclass TreeEl { new ByteBuffer a; new IntBuffer b; new IntBuffer c; } cprint { start-thread { byte[] input2 = toUTF8("hello hello"); int de1 = 3; int de2 = 16; S decode = '0.'; L tree = ll(new TreeEl); int window_start = 1; int window_end = 15; double low = 1; double high = 1; double middle = 1; new StringBuilder compressed; for count2 to 50000: { window = subByteArray(input2, window_start - 1, window_end); window_start++; window_end++; int char_location = 15; int remove = 2; int char_index = 1; LPair> predictions = ll( pair(" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&*()_+-=[]{}\|';\":/.,?><€ƒ„†…‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝޝ ‚\t\nßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ", rep(0.00001, 226))); int node = 0; while (!(char_index == 0 || char_location == 0) && window_end != 16) { if (char_location != 15) { byte _char = window.get(char_location - 1); char_index = tree,get(node).a.indexOf(_char) + 1; } char_location++; if (char_index != 0 && char_location == 16) { predictions.insert(1, tree[node - 1: node + 1]); node = 0; char_location -= remove; remove++; } else if (char_index != 0) node = tree.get(node).c.get(char_index - 1); } Pair> predict = pair("", ll()); int remaining = 1; for q over predictions: { Pair> j = predictions.get(q); double sum2 = doubleSum(j.b); double w = sum2 / (226 if len(j[-1]) == 226 else 7 * len(j[-1]) * [0.72, 0.86, 0.95, 0.93, 0.97][len(j[-1]) - 1] if len(j[-1]) < 6 else len(j[-1]) * 7); w = 0.96 if w > 20 else 0.92 if w > 10 else 0.89 if w > 3 else 0.75 if w > 1.5 else 0.64 if w > 1 else 0.57 if w > 0.7 else 0.5 if w > 0.5 else 0.44 if w > 0.4 else w; double _25ofRoof = (w * [0.916, 0.88, 0.78, 0.96, 0.9, 0.83, 0.82, 0.54, 0.49, 0.25, 0.25, 0.27, 0.33, 0.53, 0.5, 0.53, 0.72][len(predictions) - 1 - q]) * remaining; remaining -= _25ofRoof; for (int g = 0; g < l(j.a); g++) { double k = j.b[g]; double freq = j.b[g]; char_index = predict.a.find(k) + 1; if (char_index == 0) { predict.a += k; predict.b.add((freq / sum2) * _25ofRoof); } else predict.b.set(char_index - 1, predict.b.get(char_index - 1) + (freq / sum2) * _25ofRoof)); } } double summ = 1 - doubleSum(predict.b); for n in range(len(predict.b)) predict.b.set(n, predict.b.get(n) + summ / l(predict.b)); low = high; decodepart = parseDouble('0.' + str(decode[de1 - 1: de2])); for (int m = 0; m < l(predict.a); m++) { byte x = (byte) predict.a.charAt(m); high = low; low -= predict.b.get(m) * middle; if (eq(decode, "0.") && x == last(window)) break; else if (high > decodepart && decodepart > low) { window += x; input2 += x; break; } } char_location = lCommonPrefix(str(low), str(high)); compressed.append(substr(str(low), 2, char_location])); char_location -= 2; for count to char_location: { high *= 10; low *= 10 de1++; de2++; } middle = floor(low); high -= middle; low -= middle; middle = high - low; node = 0; for (byte i : window) { TreeEl el = tree.get(node); char_index = el.a.indexOf(i) + 1; if (char_index == 0) { el.a.add(i); el.b.add(1); el.c.add(l(tree)); tree.add(new TreeEl); node = l(tree); } else { el.b.set(char_index - 1, l.get(char_index - 1) + 1); node = el.c.get(char_index - 1); } } } } }