예제 #1
0
        public void VerifiesPURQBinaryIndexedTree()
        {
            var rand = new Random();

            for (int a = 0; a < _sourceArrays.Length; ++a)
            {
                var sourceArray = _sourceArrays[a];
                var purqBinaryIndexedTree = new PURQBinaryIndexedTree(sourceArray);

                for (int r = 0; r < 1000; ++r)
                {
                    int firstIndex = rand.Next(0, sourceArray.Length);
                    int secondIndex = rand.Next(0, sourceArray.Length);
                    int mode = rand.Next(2);

                    if (mode == 0)
                    {
                        NaiveBinaryIndexedTreeAlternatives.PointUpdate(sourceArray, firstIndex, delta: r);
                        purqBinaryIndexedTree.PointUpdate(firstIndex, delta: r);
                    }
                    else
                    {
                        int startIndex = Math.Min(firstIndex, secondIndex);
                        int endIndex = Math.Max(firstIndex, secondIndex);

                        var expected = NaiveBinaryIndexedTreeAlternatives.SumQuery(sourceArray, startIndex, endIndex);
                        Assert.AreEqual(expected, purqBinaryIndexedTree.SumQuery(startIndex, endIndex));
                    }
                }
            }
        }
예제 #2
0
        private void PURQRandomOperation()
        {
            var purqBinaryIndexedTree = new PURQBinaryIndexedTree(_array);

            for (int i = 0; i < _randomRangesCount; ++i)
            {
                Tuple<int, int> range = _randomRanges[i];

                if (range.Item1 % 2 == 0)
                {
                    purqBinaryIndexedTree.SumQuery(range.Item1, range.Item2);
                }
                else
                {
                    for (int j = range.Item1; j <= range.Item2; ++j)
                    {
                        purqBinaryIndexedTree.PointUpdate(j, 1);
                    }
                }
            }
        }
예제 #3
0
        private void PURQRangeUpdate()
        {
            var purqBinaryIndexedTree = new PURQBinaryIndexedTree(_array);

            for (int i = 0; i < _randomRangesCount; ++i)
            {
                Tuple<int, int> range = _randomRanges[i];

                for (int j = range.Item1; j <= range.Item2; ++j)
                {
                    purqBinaryIndexedTree.PointUpdate(j, 1);
                }
            }
        }