Ejemplo n.º 1
0
    private void Build(int treeArrayIndex, int segmentStartIndex, int segmentEndIndex)
    {
        if (segmentStartIndex == segmentEndIndex)
        {
            _treeArray[treeArrayIndex] = new PushQueryObject(segmentStartIndex);
            return;
        }

        int leftChildTreeArrayIndex  = 2 * treeArrayIndex + 1;
        int rightChildTreeArrayIndex = leftChildTreeArrayIndex + 1;
        int leftChildSegmentEndIndex = (segmentStartIndex + segmentEndIndex) / 2;

        Build(leftChildTreeArrayIndex, segmentStartIndex, leftChildSegmentEndIndex);
        Build(rightChildTreeArrayIndex, leftChildSegmentEndIndex + 1, segmentEndIndex);

        _treeArray[treeArrayIndex] = _treeArray[leftChildTreeArrayIndex].Combine(_treeArray[rightChildTreeArrayIndex]);
    }
Ejemplo n.º 2
0
 public void Update(PushQueryObject updatedLeftChild, PushQueryObject updatedRightChild)
 => LitUpCountWithoutRangePushes = updatedLeftChild.LitUpCount + updatedRightChild.LitUpCount;
Ejemplo n.º 3
0
 public PushQueryObject Combine(PushQueryObject rightAdjacentObject)
 => new PushQueryObject(
     segmentStartIndex: SegmentStartIndex,
     segmentEndIndex: rightAdjacentObject.SegmentEndIndex,
     litUpCountWithoutRangePushes: LitUpCount + rightAdjacentObject.LitUpCount);