private void RURQSumQuery()
        {
            var rurqBinaryIndexedTree = new RURQBinaryIndexedTree(_array);

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

                rurqBinaryIndexedTree.SumQuery(range.Item1, range.Item2);
            }
        }
        private void RURQRandomOperation()
        {
            var rurqBinaryIndexedTree = new RURQBinaryIndexedTree(_array);

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

                if (range.Item1 % 2 == 0)
                {
                    rurqBinaryIndexedTree.SumQuery(range.Item1, range.Item2);
                }
                else
                {
                    rurqBinaryIndexedTree.RangeUpdate(range.Item1, range.Item2, 1);
                }
            }
        }
Example #3
0
        public void VerifiesRURQBinaryIndexedTree()
        {
            var rand = new Random();

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

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

                    if (mode == 0)
                    {
                        NaiveBinaryIndexedTreeAlternatives.RangeUpdate(sourceArray, startIndex, endIndex, delta: r);
                        rurqBinaryIndexedTree.RangeUpdate(startIndex, endIndex, delta: r);
                    }
                    else
                    {
                        var expected = NaiveBinaryIndexedTreeAlternatives.SumQuery(sourceArray, startIndex, endIndex);
                        Assert.AreEqual(expected, rurqBinaryIndexedTree.SumQuery(startIndex, endIndex));
                    }
                }
            }
        }