예제 #1
0
        private Dictionary <HuffmanTreeLeaf, int> Evaluate(int restriction,
                                                           Dictionary <int, List <HuffmanTreeComponent> > coinDrawers)
        {
            Dictionary <HuffmanTreeLeaf, int> codeWordLengths = new Dictionary <HuffmanTreeLeaf, int>();

            for (int denominationPower = -restriction; denominationPower < 0; denominationPower++)
            {
                List <HuffmanTreeComponent> currentDrawer = coinDrawers[denominationPower];
                foreach (HuffmanTreeComponent coin in currentDrawer)
                {
                    if (coin.GetType().IsAssignableFrom(typeof(HuffmanTreeLeaf)) || coin.GetType().IsAssignableFrom(typeof(HuffmanTreeNullLeaf)))
                    {
                        HuffmanTreeLeaf symbol = (HuffmanTreeLeaf)coin;
                        if (codeWordLengths.ContainsKey(symbol))
                        {
                            codeWordLengths[symbol]++;
                        }
                        else
                        {
                            codeWordLengths.Add(symbol, 1);
                        }
                    }
                }
            }

            return(codeWordLengths);
        }
예제 #2
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }

            if (obj == null || GetType().Name != obj.GetType().Name)
            {
                return(false);
            }

            HuffmanTreeLeaf that = (HuffmanTreeLeaf)obj;

            return(_symbol == that._symbol);
        }