public static void HistogramCombine(global::Array <object> @out, int[] cluster_size, int[] symbols, int symbols_off, int symbols_size, int max_clusters) { unchecked { double cost_diff_threshold = 0.0; int min_cluster_size = 1; global::Array <int> all_symbols = new global::Array <int>(); global::Array <int> clusters = new global::Array <int>(); { int _g1 = 0; while ((_g1 < symbols_size)) { int i = _g1++; if ((all_symbols.indexOf(((int)(((int[])(symbols))[(symbols_off + i)])), default(global::haxe.lang.Null <int>)) == -1)) { if ((all_symbols.indexOf(((int)(((int[])(symbols))[(symbols_off + i)])), default(global::haxe.lang.Null <int>)) == -1)) { all_symbols.push(((int)(((int[])(symbols))[(symbols_off + i)]))); } clusters.push(((int)(((int[])(symbols))[(symbols_off + i)]))); } } } global::encode.BinaryHeap <object> pairs = new global::encode.BinaryHeap <object>(); { int _g11 = 0; int _g = clusters.length; while ((_g11 < _g)) { int idx1 = _g11++; { int _g3 = (idx1 + 1); int _g2 = clusters.length; while ((_g3 < _g2)) { global::encode.Cluster.CompareAndPushToHeap(@out, cluster_size, clusters[idx1], clusters[_g3++], pairs); } } } } while ((clusters.length > min_cluster_size)) { if ((global::haxe.lang.Runtime.compare(global::haxe.lang.Runtime.getField(pairs.arr[0], "cost_diff", 1698677367, true), cost_diff_threshold) >= 0)) { cost_diff_threshold = 1e99; min_cluster_size = max_clusters; continue; } int best_idx1 = ((int)(global::haxe.lang.Runtime.toInt(global::haxe.lang.Runtime.getField(pairs.arr[0], "idx1", 1169404244, true)))); int best_idx2 = ((int)(global::haxe.lang.Runtime.toInt(global::haxe.lang.Runtime.getField(pairs.arr[0], "idx2", 1169404245, true)))); ((global::encode.histogram.Histogram)(@out[best_idx1])).AddHistogram(((global::encode.histogram.Histogram)(@out[best_idx2]))); ((global::encode.histogram.Histogram)(@out[best_idx1])).bit_cost_ = ((double)(global::haxe.lang.Runtime.toDouble(global::haxe.lang.Runtime.getField(pairs.arr[0], "cost_combo", 589325724, true)))); ((int[])(cluster_size))[best_idx1] = (((int)(((int[])(cluster_size))[best_idx1])) + ((int)(((int[])(cluster_size))[best_idx2]))); { int _g12 = 0; while ((_g12 < symbols_size)) { int i1 = _g12++; if ((((int)(((int[])(symbols))[(symbols_off + i1)])) == best_idx2)) { ((int[])(symbols))[(symbols_off + i1)] = best_idx1; } } } { int _g13 = 0; int _g4 = clusters.length; while ((_g13 < _g4)) { int i2 = _g13++; if ((clusters[i2] >= best_idx2)) { clusters[i2] = clusters[(i2 + 1)]; } } } clusters.pop(); { int _g14 = 0; int _g5 = pairs.size(); while ((_g14 < _g5)) { global::encode.cluster.HistogramPair p = ((global::encode.cluster.HistogramPair)(pairs.arr[_g14++])); if (((((p.idx1 == best_idx1) || (p.idx2 == best_idx1)) || (p.idx1 == best_idx2)) || (p.idx2 == best_idx2))) { p.valid = false; } } } while (((pairs.size() != 0) && (!(global::haxe.lang.Runtime.toBool(global::haxe.lang.Runtime.getField(pairs.arr[0], "valid", 834172156, true)))))) { pairs.pop(); } { int _g15 = 0; int _g6 = clusters.length; while ((_g15 < _g6)) { global::encode.Cluster.CompareAndPushToHeap(@out, cluster_size, best_idx1, clusters[_g15++], pairs); } } } } }