public PartitionBlockInterval[] ConvertToPartitionBlockIntervals(IUniqueIdentificationSet set) {
    PartitionBlockInterval[] intervals = null;
    set.__Access(segments => {
       intervals = segments.Select(segment => new PartitionBlockInterval(segment.low, segment.high + 1)).ToArray();
    });
    return intervals;
 }
Пример #2
0
        public IUniqueIdentificationSet Intersect(IUniqueIdentificationSet setInput)
        {
            // [1     5]   [10        16]  [18  22]
            // [12] [4 6] [9   12]  [15      20]
            var set = new UniqueIdentificationSet(false).With(x => setInput.__Access(x.__Assign));

            lock (m_lock) {
                var resultList   = new LinkedList <Segment>();
                var leftCurrent  = m_segments.First;
                var rightCurrent = set.m_segments.First;
                while (leftCurrent != null && rightCurrent != null)
                {
                    var intersects = !(leftCurrent.Value.high <rightCurrent.Value.low ||
                                                               leftCurrent.Value.low> rightCurrent.Value.high);
                    if (intersects)
                    {
                        resultList.AddLast(new Segment {
                            low  = Math.Max(leftCurrent.Value.low, rightCurrent.Value.low),
                            high = Math.Min(leftCurrent.Value.high, rightCurrent.Value.high)
                        });
                    }

                    if (leftCurrent.Value.high < rightCurrent.Value.high)
                    {
                        leftCurrent = leftCurrent.Next;
                    }
                    else
                    {
                        rightCurrent = rightCurrent.Next;
                    }
                }
                return(new UniqueIdentificationSet(false).With(x => x.__Assign(resultList)));
            }
        }
Пример #3
0
        public IUniqueIdentificationSet Except(IUniqueIdentificationSet removedSetInput)
        {
            var result     = new UniqueIdentificationSet(false).With(x => this.__Access(x.__Assign));
            var removedSet = new UniqueIdentificationSet(false).With(x => removedSetInput.__Access(x.__Assign));

            removedSet.__Access(removedSegments => {
                foreach (var segment in removedSegments)
                {
                    result.TakeRange(segment.low, segment.high);
                }
            });
            return(result);
        }
Пример #4
0
        public IUniqueIdentificationSet Merge(IUniqueIdentificationSet otherInput)
        {
            // clone other to prevent deadlock
            UniqueIdentificationSet other = new UniqueIdentificationSet(false);

            otherInput.__Access(other.__Assign);

            var results = new LinkedList <Segment>();

            other.__Access(otherSegments => {
                lock (m_lock) {
                    Segment currentSegment = null;
                    foreach (var segment in MergeHelper_OrderSegmentsByLower(m_segments, otherSegments))
                    {
                        if (currentSegment == null)
                        {
                            currentSegment = segment;
                        }
                        else
                        {
                            if (currentSegment.high != UInt32.MaxValue && currentSegment.high + 1 >= segment.low)
                            {
                                currentSegment.high = Math.Max(currentSegment.high, segment.high);
                            }
                            else
                            {
                                results.AddLast(currentSegment);
                                currentSegment = new Segment {
                                    low = segment.low, high = segment.high
                                };
                            }
                        }
                    }
                    if (currentSegment != null)
                    {
                        results.AddLast(currentSegment);
                    }
                }
            });
            return(new UniqueIdentificationSet(false).With(uidSet => uidSet.__Assign(results)));
        }
Пример #5
0
      public IUniqueIdentificationSet Intersect(IUniqueIdentificationSet setInput) {
         // [1     5]   [10        16]  [18  22]
         // [12] [4 6] [9   12]  [15      20]
         var set = new UniqueIdentificationSet(false).With(x => setInput.__Access(x.__Assign));
         lock (m_lock) {
            var resultList = new LinkedList<Segment>();
            var leftCurrent = m_segments.First;
            var rightCurrent = set.m_segments.First;
            while (leftCurrent != null && rightCurrent != null) {
               var intersects = !(leftCurrent.Value.high < rightCurrent.Value.low ||
                                  leftCurrent.Value.low > rightCurrent.Value.high);
               if (intersects) {
                  resultList.AddLast(new Segment {
                     low = Math.Max(leftCurrent.Value.low, rightCurrent.Value.low),
                     high = Math.Min(leftCurrent.Value.high, rightCurrent.Value.high)
                  });
               }

               if (leftCurrent.Value.high < rightCurrent.Value.high) {
                  leftCurrent = leftCurrent.Next;
               } else {
                  rightCurrent = rightCurrent.Next;
               }
            }
            return new UniqueIdentificationSet(false).With(x => x.__Assign(resultList));
         }
      }
Пример #6
0
 public IUniqueIdentificationSet Except(IUniqueIdentificationSet removedSetInput) {
    var result = new UniqueIdentificationSet(false).With(x => this.__Access(x.__Assign));
    var removedSet = new UniqueIdentificationSet(false).With(x => removedSetInput.__Access(x.__Assign));
    removedSet.__Access(removedSegments => {
       foreach (var segment in removedSegments) {
          result.TakeRange(segment.low, segment.high);
       }
    });
    return result;
 }
Пример #7
0
      public IUniqueIdentificationSet Merge(IUniqueIdentificationSet otherInput) {
         // clone other to prevent deadlock
         UniqueIdentificationSet other = new UniqueIdentificationSet(false);
         otherInput.__Access(other.__Assign);

         var results = new LinkedList<Segment>();
         other.__Access(otherSegments => {
            lock (m_lock) {
               Segment currentSegment = null;
               foreach (var segment in MergeHelper_OrderSegmentsByLower(m_segments, otherSegments)) {
                  if (currentSegment == null) {
                     currentSegment = segment;
                  } else {
                     if (currentSegment.high != UInt32.MaxValue && currentSegment.high + 1 >= segment.low) {
                        currentSegment.high = Math.Max(currentSegment.high, segment.high);
                     } else {
                        results.AddLast(currentSegment);
                        currentSegment = new Segment { low = segment.low, high = segment.high };
                     }
                  }
               }
               if (currentSegment != null) {
                  results.AddLast(currentSegment);
               }
            }
         });
         return new UniqueIdentificationSet(false).With(uidSet => uidSet.__Assign(results));
      }