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);
        }
 public void __HackTest() {
    IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(0, 1000);
    var list = new LinkedList<UniqueIdentificationSet.Segment>();
    list.AddFirst(new UniqueIdentificationSet.Segment { low = 2000, high = 3000 });
    list.AddLast(new UniqueIdentificationSet.Segment { low = 4000, high = 5000 });
    uidSet.__Assign(list);
    list.First.Value.low = 133337; // tests clone rather than reference copy
    uidSet.__Access(x => {
       AssertEquals(2, x.Count);
       AssertEquals(2000U, x.First.Value.low);
       AssertEquals(3000U, x.First.Value.high);
       AssertEquals(4000U, x.Last.Value.low);
       AssertEquals(5000U, x.Last.Value.high);
    });
 }
        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)));
        }
        public void __HackTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(0, 1000);
            var list = new LinkedList <UniqueIdentificationSet.Segment>();

            list.AddFirst(new UniqueIdentificationSet.Segment {
                low = 2000, high = 3000
            });
            list.AddLast(new UniqueIdentificationSet.Segment {
                low = 4000, high = 5000
            });
            uidSet.__Assign(list);
            list.First.Value.low = 133337; // tests clone rather than reference copy
            uidSet.__Access(x => {
                AssertEquals(2, x.Count);
                AssertEquals(2000U, x.First.Value.low);
                AssertEquals(3000U, x.First.Value.high);
                AssertEquals(4000U, x.Last.Value.low);
                AssertEquals(5000U, x.Last.Value.high);
            });
        }
 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;
 }
      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));
      }