Exemple #1
0
        public void SqrtOperatorTest()
        {
            string path = @"sqrttests.txt";

            File.WriteAllText(path, "9");
            SqrtOperator sqrt = new SqrtOperator(File.OpenText(path));

            Assert.AreEqual(sqrt.Evaluate(), 3);
            Assert.AreEqual(sqrt.ToString(), "Sqrt(9)");
        }
Exemple #2
0
        public SqrtDecomposer(T[] a, SqrtOperator <T> valueCombiner, SqrtOperator <T> bucketCombiner)
        {
            Values         = a;
            ValueCombiner  = valueCombiner;
            BucketCombiner = bucketCombiner;
            Count          = a.Length;
            BucketSize     = (int)Math.Ceiling(Math.Sqrt(Count));
            BucketNum      = (int)Math.Ceiling((Count * 1.0) / BucketSize);
            Buckets        = new T[BucketNum];

            for (int i = 0; i < BucketNum; i++)
            {
                for (int j = 0; j < BucketSize; j++)
                {
                    if (i * BucketSize + j >= Count)
                    {
                        break;
                    }
                    ValueCombiner.Eval(ref Buckets[i], a[i * BucketSize + j]);
                }
            }
        }