Пример #1
0
 private void SetFieldLayout(int offset, int count, FieldLayoutTag tag)
 {
     for (int index = 0; index < count; index++)
     {
         SetFieldLayout(offset + index, tag);
     }
 }
Пример #2
0
        private void SetFieldLayout(int offset, FieldLayoutTag tag)
        {
            FieldLayoutTag existingTag = _fieldLayout[offset];

            if (existingTag != tag)
            {
                if (existingTag != FieldLayoutTag.Empty)
                {
                    ThrowFieldLayoutError(offset);
                }
                _fieldLayout[offset] = tag;
            }
        }
Пример #3
0
 public FieldLayoutInterval(int start, int size, FieldLayoutTag tag)
 {
     Start = start;
     Size  = size;
     Tag   = tag;
 }
Пример #4
0
 private void SetFieldLayout(int offset, int count, FieldLayoutTag tag)
 {
     SetFieldLayout(_fieldLayout, offset, count, tag);
 }
Пример #5
0
        private void SetFieldLayout(List <FieldLayoutInterval> fieldLayoutInterval, int offset, int count, FieldLayoutTag tag)
        {
            if (count == 0)
            {
                return;
            }

            var newInterval = new FieldLayoutInterval(offset, count, tag);

            int binarySearchIndex = fieldLayoutInterval.BinarySearch(newInterval);

            if (binarySearchIndex >= 0)
            {
                var existingInterval = fieldLayoutInterval[binarySearchIndex];

                // Exact match found for start of interval.
                if (tag != existingInterval.Tag)
                {
                    ThrowFieldLayoutError(offset);
                }

                if (existingInterval.Size >= count)
                {
                    // Existing interval is big enough.
                }
                else
                {
                    // Expand existing interval, and then check to see if that's valid.
                    existingInterval.Size = count;
                    fieldLayoutInterval[binarySearchIndex] = existingInterval;

                    ValidateAndMergeIntervalWithFollowingIntervals(fieldLayoutInterval, binarySearchIndex);
                }
            }
            else
            {
                // No exact start match found.

                int newIntervalLocation = ~binarySearchIndex;

                // Check for previous interval overlaps cases
                if (newIntervalLocation > 0)
                {
                    var  previousInterval = fieldLayoutInterval[newIntervalLocation - 1];
                    bool tagMatches       = previousInterval.Tag == tag;

                    if (previousInterval.EndSentinel > offset)
                    {
                        // Previous interval overlaps.
                        if (!tagMatches)
                        {
                            ThrowFieldLayoutError(offset);
                        }
                    }

                    if (previousInterval.EndSentinel > offset || (tagMatches && previousInterval.EndSentinel == offset))
                    {
                        // Previous interval overlaps, or exactly matches up with new interval and tag matches. Instead
                        // of expanding interval set, simply expand the previous interval.
                        previousInterval.EndSentinel = newInterval.EndSentinel;

                        fieldLayoutInterval[newIntervalLocation - 1] = previousInterval;
                        newIntervalLocation = newIntervalLocation - 1;
                    }
                    else
                    {
                        fieldLayoutInterval.Insert(newIntervalLocation, newInterval);
                    }
                }
                else
                {
                    // New interval added at start
                    fieldLayoutInterval.Insert(newIntervalLocation, newInterval);
                }

                ValidateAndMergeIntervalWithFollowingIntervals(fieldLayoutInterval, newIntervalLocation);
            }
        }