public static void Main() { string tree = File.ReadAllText("tree.txt"); Deflate2Tree tr = new Deflate2Tree(tree); Deflate2.CompressAPI(File.ReadAllText("json.txt"), tr); }
public static byte[] CompressAPI(string tocompress, Deflate2Tree tree) { short[] idxs = new short[tocompress.Length]; BitArray used = new BitArray(tocompress.Length); var srt = (from i in tree.GetReplacements() orderby i.Key.Length descending select i).ToArray(); for (int ijk = 0; ijk < srt.Length; ijk++) { var i = srt[ijk]; Console.WriteLine(i.Key); int pos = -1; do { pos = tocompress.IndexOf(i.Key, pos + 1); bool ok = true; for (int j = pos; j < pos + i.Key.Length; j++) { if (used.Get(j)) { ok = false; break; } } if (!ok) { continue; } for (int j = pos; j < pos + i.Key.Length; j++) { used.Set(j, true); } idxs[pos] = (short)(ijk + 1); } while(pos >= 0); } StreamWriter sw = new StreamWriter("cerr.txt"); foreach (var i in idxs) { sw.WriteLine(i); } sw.Close(); return(null); }