示例#1
0
        public IntervalNode GetTopNodeAtIndex(int idx)
        {
            IntervalNode topNode = this.SupportPoints[idx];

            if (topNode != null && topNode.parent != null)
            {
                // Get the "top" node
                IntervalNode top = topNode.parent;
                while (top.parent != null)
                {
                    top = top.parent;
                }

                // Make the top node the parent of all nodes along the way from the "leaf"
                while (topNode.parent != top)
                {
                    IntervalNode next = topNode.parent;
                    topNode.parent = top;
                    topNode        = next;
                }

                topNode = top;
            }

            return(topNode);
        }
示例#2
0
        public void MergeAndIntegrate(DateIntervalEfficiency eff)
        {
            int leftIdx  = this.GetSupportIndexAtTime(eff.Min.Value.Ticks);
              int rightIdx = this.GetSupportIndexAtTime(eff.Max.Value.Ticks);

              IntervalNode leftNode  = this.GetTopNodeAtIndex(leftIdx);
              IntervalNode rightNode = this.GetTopNodeAtIndex(rightIdx);
              IntervalNode newTopNode = null;

              if (leftNode != null) {
            if (leftNode == rightNode)
              // If node is the same on both sides the current interval is fully covered
              return;

            newTopNode = new IntervalNode(null, leftNode.startIdx, rightIdx);

            // Adjust left marker
            leftIdx = leftNode.endIdx;
              }

              if (rightNode != null) {
            if (newTopNode == null) {
              newTopNode = new IntervalNode(null, leftIdx, rightNode.endIdx);
            }
            else
              newTopNode.endIdx = rightNode.endIdx;

            // Adjust right marker
            rightIdx = rightNode.startIdx;
              }

              // Create new leaf node and include the free points from 'leftIdx' to 'rightIdx'
              IntervalNode newLeafNode = new IntervalNode(null, leftIdx, rightIdx);

              // Scanning from left to right

              // Marking the start point, but skipping the integration, since it contains the ticks from the previous delta interval
              this.SupportPoints[leftIdx] = newLeafNode;

              // Mark empty support points inside interval range, while jumping over the already "marked" intervals
              while (++leftIdx <= rightIdx) {
            // Integrate the delta interval
            this.EffectiveDeltaTime[leftIdx] = (long)(this.EffectiveDeltaTime[leftIdx] * 0.01 * eff.Efficiency);

            IntervalNode curTopNode = this.GetTopNodeAtIndex(leftIdx);
            if (curTopNode != null)
              // Jump over existing interval
              leftIdx = curTopNode.endIdx;
            else
              // "Brand" point with the current node
              this.SupportPoints[leftIdx] = newLeafNode;
              }

              // Create links to new top node
              if (newTopNode != null) {
            if (leftNode != null) leftNode.parent = newTopNode;
            if (rightNode != null) rightNode.parent = newTopNode;
            newLeafNode.parent = newTopNode;

            // Check if we have the whole support range covered
            if (newTopNode.startIdx == 0 && newTopNode.endIdx == this.SupportPoints.Length - 1)
              this.IsFullyCovered = true;
              }
        }
示例#3
0
        public void MergeAndIntegrate(DateIntervalEfficiency eff)
        {
            int leftIdx  = this.GetSupportIndexAtTime(eff.Min.Value.Ticks);
            int rightIdx = this.GetSupportIndexAtTime(eff.Max.Value.Ticks);

            IntervalNode leftNode   = this.GetTopNodeAtIndex(leftIdx);
            IntervalNode rightNode  = this.GetTopNodeAtIndex(rightIdx);
            IntervalNode newTopNode = null;

            if (leftNode != null)
            {
                if (leftNode == rightNode)
                {
                    // If node is the same on both sides the current interval is fully covered
                    return;
                }

                newTopNode = new IntervalNode(null, leftNode.startIdx, rightIdx);

                // Adjust left marker
                leftIdx = leftNode.endIdx;
            }

            if (rightNode != null)
            {
                if (newTopNode == null)
                {
                    newTopNode = new IntervalNode(null, leftIdx, rightNode.endIdx);
                }
                else
                {
                    newTopNode.endIdx = rightNode.endIdx;
                }

                // Adjust right marker
                rightIdx = rightNode.startIdx;
            }

            // Create new leaf node and include the free points from 'leftIdx' to 'rightIdx'
            IntervalNode newLeafNode = new IntervalNode(null, leftIdx, rightIdx);

            // Scanning from left to right

            // Marking the start point, but skipping the integration, since it contains the ticks from the previous delta interval
            this.SupportPoints[leftIdx] = newLeafNode;

            // Mark empty support points inside interval range, while jumping over the already "marked" intervals
            while (++leftIdx <= rightIdx)
            {
                // Integrate the delta interval
                this.EffectiveDeltaTime[leftIdx] = (long)(this.EffectiveDeltaTime[leftIdx] * 0.01 * eff.Efficiency);

                IntervalNode curTopNode = this.GetTopNodeAtIndex(leftIdx);
                if (curTopNode != null)
                {
                    // Jump over existing interval
                    leftIdx = curTopNode.endIdx;
                }
                else
                {
                    // "Brand" point with the current node
                    this.SupportPoints[leftIdx] = newLeafNode;
                }
            }

            // Create links to new top node
            if (newTopNode != null)
            {
                if (leftNode != null)
                {
                    leftNode.parent = newTopNode;
                }
                if (rightNode != null)
                {
                    rightNode.parent = newTopNode;
                }
                newLeafNode.parent = newTopNode;

                // Check if we have the whole support range covered
                if (newTopNode.startIdx == 0 && newTopNode.endIdx == this.SupportPoints.Length - 1)
                {
                    this.IsFullyCovered = true;
                }
            }
        }