コード例 #1
0
        /// <summary>for testing purposes only</summary>
        public static void Main(string[] args)
        {
            object[] a1 = new object[] { "a", "b" };
            object[] a2 = new object[] { "a", "b" };
            System.Console.Out.WriteLine(Arrays.Equals(a1, a2));
            GeneralizedCounter <string> gc = new GeneralizedCounter <string>(3);

            gc.IncrementCount(Arrays.AsList(new string[] { "a", "j", "x" }), 3.0);
            gc.IncrementCount(Arrays.AsList(new string[] { "a", "l", "x" }), 3.0);
            gc.IncrementCount(Arrays.AsList(new string[] { "b", "k", "y" }), 3.0);
            gc.IncrementCount(Arrays.AsList(new string[] { "b", "k", "z" }), 3.0);
            System.Console.Out.WriteLine("incremented counts.");
            System.Console.Out.WriteLine(gc.DumpKeys());
            System.Console.Out.WriteLine("string representation of generalized counter:");
            System.Console.Out.WriteLine(gc.ToString());
            gc.PrintKeySet();
            System.Console.Out.WriteLine("entry set:\n" + gc.EntrySet());
            ArrayPrintDouble(gc.GetCounts(Arrays.AsList(new string[] { "a", "j", "x" })));
            ArrayPrintDouble(gc.GetCounts(Arrays.AsList(new string[] { "a", "j", "z" })));
            ArrayPrintDouble(gc.GetCounts(Arrays.AsList(new string[] { "b", "k", "w" })));
            ArrayPrintDouble(gc.GetCounts(Arrays.AsList(new string[] { "b", "k", "z" })));
            GeneralizedCounter <string> gc1 = gc.Conditionalize(Arrays.AsList(new string[] { "a" }));

            gc1.IncrementCount(Arrays.AsList(new string[] { "j", "x" }));
            gc1.IncrementCount2D("j", "z");
            GeneralizedCounter <string> gc2 = gc1.Conditionalize(Arrays.AsList(new string[] { "j" }));

            gc2.IncrementCount1D("x");
            System.Console.Out.WriteLine("Pretty-printing gc after incrementing gc1:");
            gc.PrettyPrint();
            System.Console.Out.WriteLine("Total: " + gc.TotalCount());
            gc1.PrintKeySet();
            System.Console.Out.WriteLine("another entry set:\n" + gc1.EntrySet());
            ClassicCounter <IList <string> > c = gc.CounterView();

            System.Console.Out.WriteLine("string representation of counter view:");
            System.Console.Out.WriteLine(c.ToString());
            double d1 = c.GetCount(Arrays.AsList(new string[] { "a", "j", "x" }));
            double d2 = c.GetCount(Arrays.AsList(new string[] { "a", "j", "w" }));

            System.Console.Out.WriteLine(d1 + " " + d2);
            ClassicCounter <IList <string> > c1 = gc1.CounterView();

            System.Console.Out.WriteLine("Count of {j,x} -- should be 3.0\t" + c1.GetCount(Arrays.AsList(new string[] { "j", "x" })));
            System.Console.Out.WriteLine(c.KeySet() + " size " + c.KeySet().Count);
            System.Console.Out.WriteLine(c1.KeySet() + " size " + c1.KeySet().Count);
            System.Console.Out.WriteLine(c1.Equals(c));
            System.Console.Out.WriteLine(c.Equals(c1));
            System.Console.Out.WriteLine(c.Equals(c));
            System.Console.Out.WriteLine("### testing equality of regular Counter...");
            ClassicCounter <string> z1 = new ClassicCounter <string>();
            ClassicCounter <string> z2 = new ClassicCounter <string>();

            z1.IncrementCount("a1");
            z1.IncrementCount("a2");
            z2.IncrementCount("b");
            System.Console.Out.WriteLine(z1.Equals(z2));
            System.Console.Out.WriteLine(z1.ToString());
            System.Console.Out.WriteLine(z1.KeySet().ToString());
        }
コード例 #2
0
        /// <summary>Equivalent to incrementCount( new Object[] { first, second }, count ).</summary>
        /// <remarks>
        /// Equivalent to incrementCount( new Object[] { first, second }, count ).
        /// Makes the special case easier, and also more efficient.
        /// </remarks>
        public virtual void IncrementCount2D(K first, K second, double count)
        {
            if (depth != 2)
            {
                WrongDepth();
            }
            //throws exception
            this.AddToTotal(count);
            GeneralizedCounter <K> next = this.ConditionalizeHelper(first);

            next.IncrementCount1D(second, count);
        }
コード例 #3
0
        /// <summary>same as incrementCount(List, double) but as if Object o were at the end of the list</summary>
        public virtual void IncrementCount(IList <K> l, K o, double count)
        {
            if (l.Count != depth - 1)
            {
                WrongDepth();
            }
            GeneralizedCounter <K> next = this;

            foreach (K o2 in l)
            {
                next.AddToTotal(count);
                next = next.ConditionalizeHelper(o2);
            }
            next.AddToTotal(count);
            next.IncrementCount1D(o, count);
        }
コード例 #4
0
        /// <summary>
        /// Adds to count for the
        /// <see cref="GeneralizedCounter{K}.Depth()"/>
        /// -dimensional key
        /// <paramref name="l"/>
        /// .
        /// </summary>
        public virtual void IncrementCount(IList <K> l, double count)
        {
            if (l.Count != depth)
            {
                WrongDepth();
            }
            //throws exception
            GeneralizedCounter <K> next = this;
            IEnumerator <K>        i    = l.GetEnumerator();
            K o = i.Current;

            while (i.MoveNext())
            {
                next.AddToTotal(count);
                next = next.ConditionalizeHelper(o);
                o    = i.Current;
            }
            next.IncrementCount1D(o, count);
        }