Esempio n. 1
0
        public virtual object encode_BinaryHeap_cast <T_c>()
        {
            if (global::haxe.lang.Runtime.eq(typeof(T), typeof(T_c)))
            {
                return(this);
            }

            global::encode.BinaryHeap <T_c> new_me = new global::encode.BinaryHeap <T_c>(global::haxe.lang.EmptyObject.EMPTY);
            global::Array <object>          fields = global::Reflect.fields(this);
            int i = 0;

            while ((i < fields.length))
            {
                string field = global::haxe.lang.Runtime.toString(fields[i++]);
                global::Reflect.setField(new_me, field, global::Reflect.field(this, field));
            }

            return(new_me);
        }
Esempio n. 2
0
 public static object __hx_cast <T_c_c>(global::encode.BinaryHeap me)
 {
     return(((me != null)) ? (me.encode_BinaryHeap_cast <T_c_c>()) : default(object));
 }
Esempio n. 3
0
        public static void CompareAndPushToHeap(global::Array <object> @out, int[] cluster_size, int idx1, int idx2, global::encode.BinaryHeap <object> pairs)
        {
            if ((idx1 == idx2))
            {
                return;
            }

            if ((idx2 < idx1))
            {
                int t = idx2;
                idx2 = idx1;
                idx1 = t;
            }

            bool store_pair = false;

            global::encode.cluster.HistogramPair p = new global::encode.cluster.HistogramPair();
            p.idx1      = idx1;
            p.idx2      = idx2;
            p.valid     = true;
            p.cost_diff = (0.5 * global::encode.Cluster.ClusterCostDiff(((int)(((int[])(cluster_size))[idx1])), ((int)(((int[])(cluster_size))[idx2]))));
            p.cost_diff = ((p.cost_diff -= ((global::encode.histogram.Histogram)(@out[idx1])).bit_cost_) - ((global::encode.histogram.Histogram)(@out[idx2])).bit_cost_);
            if ((((global::encode.histogram.Histogram)(@out[idx1])).total_count_ == 0))
            {
                p.cost_combo = ((global::encode.histogram.Histogram)(@out[idx2])).bit_cost_;
                store_pair   = true;
            }
            else if ((((global::encode.histogram.Histogram)(@out[idx2])).total_count_ == 0))
            {
                p.cost_combo = ((global::encode.histogram.Histogram)(@out[idx1])).bit_cost_;
                store_pair   = true;
            }
            else
            {
                double threshold = (((pairs.size() == 0)) ? (1e99) : (global::System.Math.Max(((double)(0.0)), ((double)(global::haxe.lang.Runtime.toDouble(global::haxe.lang.Runtime.getField(pairs.arr[0], "cost_diff", 1698677367, true)))))));
                global::encode.histogram.Histogram combo = new global::encode.histogram.Histogram(((int)((((int[])(((global::encode.histogram.Histogram)(@out[idx1])).data_)) as global::System.Array).Length)));
                combo.bit_cost_ = ((global::encode.histogram.Histogram)(@out[idx1])).bit_cost_;
                {
                    int _g1 = 0;
                    int _g  = (((int[])(((global::encode.histogram.Histogram)(@out[idx1])).data_)) as global::System.Array).Length;
                    while ((_g1 < _g))
                    {
                        int a = _g1++;
                        ((int[])(combo.data_))[a] = ((int[])(((global::encode.histogram.Histogram)(@out[idx1])).data_))[a];
                    }
                }

                combo.kDataSize    = ((global::encode.histogram.Histogram)(@out[idx1])).kDataSize;
                combo.total_count_ = ((global::encode.histogram.Histogram)(@out[idx1])).total_count_;
                combo.AddHistogram(((global::encode.histogram.Histogram)(@out[idx2])));
                double cost_combo = global::encode.Bit_cost.PopulationCost(combo);
                if ((cost_combo < (threshold - p.cost_diff)))
                {
                    p.cost_combo = cost_combo;
                    store_pair   = true;
                }
            }

            if (store_pair)
            {
                p.cost_diff += p.cost_combo;
                pairs.push(p);
            }
        }
Esempio n. 4
0
 public static void __hx_ctor_encode_BinaryHeap <T_c>(global::encode.BinaryHeap <T_c> __hx_this)
 {
     __hx_this.arr  = new global::Array <object>(new object[] {});
     __hx_this.comp = ((global::haxe.lang.Function)(new global::haxe.lang.Closure(__hx_this, "HistogramPairComparator", 961126132)));
 }
Esempio n. 5
0
        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);
                        }
                    }
                }
            }
        }