public void GiveRange_MergeMultipleTest() {
         var hardList = new LinkedList<UniqueIdentificationSet.Segment>().With(list => {
            list.AddLast(new UniqueIdentificationSet.Segment { low = 1, high = 5 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 12, high = 15 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 30, high = 50 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 52, high = 100 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 150, high = 200 });
         });
         IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);
         uidSet.__Assign(hardList);
         uidSet.GiveRange(0, 16);
         AssertEquals("[0, 16][30, 50][52, 100][150, 200]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.GiveRange(15, 51);
         AssertEquals("[1, 5][12, 100][150, 200]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.GiveRange(15, UInt32.MaxValue);
         AssertEquals("[1, 5][12, " + UInt32.MaxValue + "]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.GiveRange(0, UInt32.MaxValue);
         AssertEquals("[0, " + UInt32.MaxValue + "]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.GiveRange(201, 1000);
         AssertEquals("[1, 5][12, 15][30, 50][52, 100][150, 1000]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.GiveRange(0, 0);
         AssertEquals("[0, 5][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString());
      }
 public void GiveRange_MergeAfterFirstTest() {
    IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);
    uidSet.GiveRange(1, 5);
    uidSet.GiveRange(10, 12);
    uidSet.GiveRange(8, 9);
    AssertEquals("[1, 5][8, 12]", uidSet.ToString());
 }
        public void ContainsTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(1, 4);

            uidSet.GiveRange(6, 15);
            uidSet.TakeRange(10, 11);

            AssertFalse(uidSet.Contains(0));
            AssertTrue(uidSet.Contains(1));
            AssertTrue(uidSet.Contains(2));
            AssertTrue(uidSet.Contains(3));
            AssertTrue(uidSet.Contains(4));
            AssertFalse(uidSet.Contains(5));
            AssertTrue(uidSet.Contains(6));
            AssertTrue(uidSet.Contains(7));
            AssertTrue(uidSet.Contains(8));
            AssertTrue(uidSet.Contains(9));
            AssertFalse(uidSet.Contains(10));
            AssertFalse(uidSet.Contains(11));
            AssertTrue(uidSet.Contains(12));
            AssertTrue(uidSet.Contains(13));
            AssertTrue(uidSet.Contains(14));
            AssertTrue(uidSet.Contains(15));
            AssertFalse(uidSet.Contains(16));

            AssertTrue(new UniqueIdentificationSet(0, 4).Contains(0));
        }
        public void IntersectTest()
        {
            var setA = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList <UniqueIdentificationSet.Segment>().With(x => {
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 1, high = 5
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 10, high = 16
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 18, high = 22
                });
            })));
            var setB = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList <UniqueIdentificationSet.Segment>().With(x => {
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 1, high = 2
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 4, high = 6
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 9, high = 12
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 15, high = 20
                });
            })));

            AssertEquals("[1, 2][4, 5][10, 12][15, 16][18, 20]", setA.Intersect(setB).ToString());
        }
Esempio n. 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)));
            }
        }
        public void Any_ComplexTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(1, 2);

            uidSet.GiveRange(4, 5);

            AssertEquals(4, uidSet.Count);
        }
 public void GiveRange_AppendInMiddleTest() {
    IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);
    uidSet.GiveRange(12, 15);
    uidSet.GiveRange(18, 20);
    uidSet.GiveRange(1, 5);
    uidSet.GiveRange(7, 10);
    AssertEquals("[1, 5][7, 10][12, 15][18, 20]", uidSet.ToString());
 }
 public void GiveRange_PrependToFrontTest() {
    IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);
    uidSet.Clear();
    uidSet.GiveRange(18, 20);
    uidSet.GiveRange(12, 15);
    uidSet.GiveRange(7, 10);
    uidSet.GiveRange(1, 5);
    AssertEquals("[1, 5][7, 10][12, 15][18, 20]", uidSet.ToString());
 }
        public void GiveRange_MergeAfterFirstTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);

            uidSet.GiveRange(1, 5);
            uidSet.GiveRange(10, 12);
            uidSet.GiveRange(8, 9);
            AssertEquals("[1, 5][8, 12]", uidSet.ToString());
        }
Esempio n. 10
0
        public void GiveTakeMergeExceptInvertIntersectRangeRandomTest()
        {
            var random = new Random();
            var set    = new HashSet <uint>();
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);

            for (var it = 0; it < 20000; it++)
            {
                var low  = (uint)(random.NextDouble() * (long)100000);
                var high = low + (uint)(random.NextDouble() * (long)100);

                if (random.Next() % 2 == 0)
                {
                    for (var val = low; val <= high; val++)
                    {
                        AssertEquals(set.Add(val), !uidSet.Contains(val));
                    }
                    if (random.Next() % 2 == 0)
                    {
                        uidSet.GiveRange(low, high);
                    }
                    else
                    {
                        uidSet = uidSet.Merge(new UniqueIdentificationSet(low, high).Invert().Invert());
                    }
                    for (var val = low; val <= high; val++)
                    {
                        AssertTrue(uidSet.Contains(val));
                    }
                }
                else
                {
                    for (var val = low; val <= high; val++)
                    {
                        AssertEquals(set.Remove(val), uidSet.Contains(val));
                    }
                    var rand = random.Next() % 3;
                    if (rand == 0)
                    {
                        uidSet.TakeRange(low, high);
                    }
                    else if (rand == 1)
                    {
                        uidSet = uidSet.Except(new UniqueIdentificationSet(low, high).Invert().Invert());
                    }
                    else
                    {
                        uidSet = uidSet.Intersect(new UniqueIdentificationSet(low, high).Invert());
                    }
                    for (var val = low; val <= high; val++)
                    {
                        AssertFalse(uidSet.Contains(val));
                    }
                }
            }
        }
      public IUniqueIdentificationSet ConvertToUidSet(PartitionBlockInterval[] intervals) {
         var segments = new LinkedList<UniqueIdentificationSet.Segment>();
         foreach (var interval in intervals) {
            segments.AddLast(new UniqueIdentificationSet.Segment { low = interval.StartBlockInclusive, high = interval.EndBlockExclusive - 1 });
         }

         var result = new UniqueIdentificationSet(false);
         result.__Assign(segments);
         return result;
      }
Esempio n. 12
0
        public void GiveRange_AppendInMiddleTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);

            uidSet.GiveRange(12, 15);
            uidSet.GiveRange(18, 20);
            uidSet.GiveRange(1, 5);
            uidSet.GiveRange(7, 10);
            AssertEquals("[1, 5][7, 10][12, 15][18, 20]", uidSet.ToString());
        }
Esempio n. 13
0
        public void GiveRange_PrependToFrontTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);

            uidSet.Clear();
            uidSet.GiveRange(18, 20);
            uidSet.GiveRange(12, 15);
            uidSet.GiveRange(7, 10);
            uidSet.GiveRange(1, 5);
            AssertEquals("[1, 5][7, 10][12, 15][18, 20]", uidSet.ToString());
        }
Esempio n. 14
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);
        }
 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);
    });
 }
Esempio n. 16
0
        public void MergeTest()
        {
            IUniqueIdentificationSet first = new UniqueIdentificationSet(false).With(x => {
                x.__Assign(new LinkedList <UniqueIdentificationSet.Segment>().With(list => {
                    list.AddLast(new UniqueIdentificationSet.Segment {
                        low = 1, high = 5
                    });
                    list.AddLast(new UniqueIdentificationSet.Segment {
                        low = 10, high = 12
                    });
                    list.AddLast(new UniqueIdentificationSet.Segment {
                        low = 15, high = 20
                    });
                    list.AddLast(new UniqueIdentificationSet.Segment {
                        low = 22, high = 30
                    });
                    list.AddLast(new UniqueIdentificationSet.Segment {
                        low = 40, high = UInt32.MaxValue - 1
                    });
                }));
            });
            IUniqueIdentificationSet second = new UniqueIdentificationSet(false).With(x => {
                x.__Assign(new LinkedList <UniqueIdentificationSet.Segment>().With(list => {
                    list.AddLast(new UniqueIdentificationSet.Segment {
                        low = 0, high = 0
                    });
                    list.AddLast(new UniqueIdentificationSet.Segment {
                        low = 6, high = 7
                    });
                    list.AddLast(new UniqueIdentificationSet.Segment {
                        low = 13, high = 14
                    });
                    list.AddLast(new UniqueIdentificationSet.Segment {
                        low = 20, high = 21
                    });
                    list.AddLast(new UniqueIdentificationSet.Segment {
                        low = 22, high = 30
                    });
                    list.AddLast(new UniqueIdentificationSet.Segment {
                        low = UInt32.MaxValue, high = UInt32.MaxValue
                    });
                }));
            });

            AssertEquals(first.Merge(second).ToString(), "[0, 7][10, 30][40, " + UInt32.MaxValue + "]");
        }
Esempio n. 17
0
        public void GiveRange_MergeMultipleTest()
        {
            var hardList = new LinkedList <UniqueIdentificationSet.Segment>().With(list => {
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 1, high = 5
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 12, high = 15
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 30, high = 50
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 52, high = 100
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 150, high = 200
                });
            });
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);

            uidSet.__Assign(hardList);
            uidSet.GiveRange(0, 16);
            AssertEquals("[0, 16][30, 50][52, 100][150, 200]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.GiveRange(15, 51);
            AssertEquals("[1, 5][12, 100][150, 200]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.GiveRange(15, UInt32.MaxValue);
            AssertEquals("[1, 5][12, " + UInt32.MaxValue + "]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.GiveRange(0, UInt32.MaxValue);
            AssertEquals("[0, " + UInt32.MaxValue + "]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.GiveRange(201, 1000);
            AssertEquals("[1, 5][12, 15][30, 50][52, 100][150, 1000]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.GiveRange(0, 0);
            AssertEquals("[0, 5][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString());
        }
Esempio n. 18
0
        public void TakeRangeStartTest()
        {
            var hardList = new LinkedList <UniqueIdentificationSet.Segment>().With(list => {
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 1, high = 5
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 12, high = 15
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 30, high = 50
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 52, high = 100
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 150, high = 200
                });
            });
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);

            uidSet.__Assign(hardList);
            uidSet.TakeRange(3, 11);
            AssertEquals("[1, 2][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.TakeRange(0, 300);
            AssertEquals("", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.TakeRange(1, 3);
            AssertEquals("[4, 5][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.TakeRange(1, 5);
            AssertEquals("[12, 15][30, 50][52, 100][150, 200]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.TakeRange(150, 200);
            AssertEquals("[1, 5][12, 15][30, 50][52, 100]", uidSet.ToString());
        }
Esempio n. 19
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)));
        }
Esempio n. 20
0
        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 void GiveTakeMergeExceptInvertIntersectRangeRandomTest() {
         var random = new Random();
         var set = new HashSet<uint>();
         IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);
         for (var it = 0; it < 20000; it++) {
            var low = (uint)(random.NextDouble() * (long)100000);
            var high = low + (uint)(random.NextDouble() * (long)100);

            if (random.Next() % 2 == 0) {
               for (var val = low; val <= high; val++) {
                  AssertEquals(set.Add(val), !uidSet.Contains(val));
               }
               if (random.Next() % 2 == 0) {
                  uidSet.GiveRange(low, high);
               } else {
                  uidSet = uidSet.Merge(new UniqueIdentificationSet(low, high).Invert().Invert());
               }
               for (var val = low; val <= high; val++) {
                  AssertTrue(uidSet.Contains(val));
               }
            } else {
               for (var val = low; val <= high; val++) {
                  AssertEquals(set.Remove(val), uidSet.Contains(val));
               }
               var rand = random.Next() % 3;
               if (rand == 0) {
                  uidSet.TakeRange(low, high);
               } else if (rand == 1) {
                  uidSet = uidSet.Except(new UniqueIdentificationSet(low, high).Invert().Invert());
               } else {
                  uidSet = uidSet.Intersect(new UniqueIdentificationSet(low, high).Invert());
               }
               for (var val = low; val <= high; val++) {
                  AssertFalse(uidSet.Contains(val));
               }
            }
         }
      }
Esempio n. 22
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));
      }
Esempio n. 23
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;
 }
      public void TakeRangeStartTest() {
         var hardList = new LinkedList<UniqueIdentificationSet.Segment>().With(list => {
            list.AddLast(new UniqueIdentificationSet.Segment { low = 1, high = 5 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 12, high = 15 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 30, high = 50 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 52, high = 100 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 150, high = 200 });
         });
         IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);
         uidSet.__Assign(hardList);
         uidSet.TakeRange(3, 11);
         AssertEquals("[1, 2][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.TakeRange(0, 300);
         AssertEquals("", uidSet.ToString());
       
         uidSet.__Assign(hardList);
         uidSet.TakeRange(1, 3);
         AssertEquals("[4, 5][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString()); 

         uidSet.__Assign(hardList);
         uidSet.TakeRange(1, 5);
         AssertEquals("[12, 15][30, 50][52, 100][150, 200]", uidSet.ToString()); 

         uidSet.__Assign(hardList);
         uidSet.TakeRange(150, 200);
         AssertEquals("[1, 5][12, 15][30, 50][52, 100]", uidSet.ToString()); 
      }
 public void IntersectTest() {
    var setA = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList<UniqueIdentificationSet.Segment>().With(x => {
       x.AddLast(new UniqueIdentificationSet.Segment { low = 1, high = 5 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 10, high = 16 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 18, high = 22 });
    })));
    var setB = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList<UniqueIdentificationSet.Segment>().With(x => {
       x.AddLast(new UniqueIdentificationSet.Segment { low = 1, high = 2 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 4, high = 6 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 9, high = 12 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 15, high = 20 });
    })));
    AssertEquals("[1, 2][4, 5][10, 12][15, 16][18, 20]", setA.Intersect(setB).ToString());
 }
 public void InvertTest() {
    var setA = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList<UniqueIdentificationSet.Segment>().With(x => {
       x.AddLast(new UniqueIdentificationSet.Segment { low = 0, high = 5 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 10, high = 16 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 18, high = 22 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 25, high = 100 });
    })));
    var setB = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList<UniqueIdentificationSet.Segment>().With(x => {
       x.AddLast(new UniqueIdentificationSet.Segment { low = 1, high = 5 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 10, high = 16 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 18, high = 22 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 25, high = 100 });
    })));
    var setC = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList<UniqueIdentificationSet.Segment>().With(x => {
       x.AddLast(new UniqueIdentificationSet.Segment { low = 1, high = 5 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 10, high = 16 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 18, high = 22 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 25, high = uint.MaxValue });
    })));
    var setD = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList<UniqueIdentificationSet.Segment>().With(x => {
       x.AddLast(new UniqueIdentificationSet.Segment { low = 0, high = 5 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 10, high = 16 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 18, high = 22 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 25, high = uint.MaxValue });
    })));
    AssertEquals("[6, 9][17, 17][23, 24][101, " + UInt32.MaxValue + "]", setA.Invert().ToString());
    AssertEquals("[0, 0][6, 9][17, 17][23, 24][101, " + UInt32.MaxValue + "]", setB.Invert().ToString());
    AssertEquals("[0, 0][6, 9][17, 17][23, 24]", setC.Invert().ToString());
    AssertEquals("[6, 9][17, 17][23, 24]", setD.Invert().ToString());
 }
      public void Any_ComplexTest() {
         IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(1, 2);
         uidSet.GiveRange(4, 5);

         AssertEquals(4, uidSet.Count);
      }
 public void MergeTest () {
    IUniqueIdentificationSet first = new UniqueIdentificationSet(false).With(x => {
       x.__Assign(new LinkedList<UniqueIdentificationSet.Segment>().With(list => {
          list.AddLast(new UniqueIdentificationSet.Segment { low = 1, high = 5 });
          list.AddLast(new UniqueIdentificationSet.Segment { low = 10, high = 12 });
          list.AddLast(new UniqueIdentificationSet.Segment { low = 15, high = 20 });
          list.AddLast(new UniqueIdentificationSet.Segment { low = 22, high = 30 });
          list.AddLast(new UniqueIdentificationSet.Segment { low = 40, high = UInt32.MaxValue - 1 });
       }));
    });
    IUniqueIdentificationSet second = new UniqueIdentificationSet(false).With(x => {
       x.__Assign(new LinkedList<UniqueIdentificationSet.Segment>().With(list => {
          list.AddLast(new UniqueIdentificationSet.Segment { low = 0, high = 0 });
          list.AddLast(new UniqueIdentificationSet.Segment { low = 6, high = 7 });
          list.AddLast(new UniqueIdentificationSet.Segment { low = 13, high = 14 });
          list.AddLast(new UniqueIdentificationSet.Segment { low = 20, high = 21 });
          list.AddLast(new UniqueIdentificationSet.Segment { low = 22, high = 30 });
          list.AddLast(new UniqueIdentificationSet.Segment { low = UInt32.MaxValue, high = UInt32.MaxValue });
       }));
    });
    AssertEquals(first.Merge(second).ToString(), "[0, 7][10, 30][40, " + UInt32.MaxValue + "]");
 }
Esempio n. 29
0
        public void InvertTest()
        {
            var setA = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList <UniqueIdentificationSet.Segment>().With(x => {
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 0, high = 5
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 10, high = 16
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 18, high = 22
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 25, high = 100
                });
            })));
            var setB = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList <UniqueIdentificationSet.Segment>().With(x => {
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 1, high = 5
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 10, high = 16
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 18, high = 22
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 25, high = 100
                });
            })));
            var setC = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList <UniqueIdentificationSet.Segment>().With(x => {
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 1, high = 5
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 10, high = 16
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 18, high = 22
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 25, high = uint.MaxValue
                });
            })));
            var setD = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList <UniqueIdentificationSet.Segment>().With(x => {
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 0, high = 5
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 10, high = 16
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 18, high = 22
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 25, high = uint.MaxValue
                });
            })));

            AssertEquals("[6, 9][17, 17][23, 24][101, " + UInt32.MaxValue + "]", setA.Invert().ToString());
            AssertEquals("[0, 0][6, 9][17, 17][23, 24][101, " + UInt32.MaxValue + "]", setB.Invert().ToString());
            AssertEquals("[0, 0][6, 9][17, 17][23, 24]", setC.Invert().ToString());
            AssertEquals("[6, 9][17, 17][23, 24]", setD.Invert().ToString());
        }
Esempio n. 30
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));
         }
      }
      public void ContainsTest() {
         IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(1, 4);
         uidSet.GiveRange(6, 15);
         uidSet.TakeRange(10, 11);

         AssertFalse(uidSet.Contains(0));
         AssertTrue(uidSet.Contains(1));
         AssertTrue(uidSet.Contains(2));
         AssertTrue(uidSet.Contains(3));
         AssertTrue(uidSet.Contains(4));
         AssertFalse(uidSet.Contains(5));
         AssertTrue(uidSet.Contains(6));
         AssertTrue(uidSet.Contains(7));
         AssertTrue(uidSet.Contains(8));
         AssertTrue(uidSet.Contains(9));
         AssertFalse(uidSet.Contains(10));
         AssertFalse(uidSet.Contains(11));
         AssertTrue(uidSet.Contains(12));
         AssertTrue(uidSet.Contains(13));
         AssertTrue(uidSet.Contains(14));
         AssertTrue(uidSet.Contains(15));
         AssertFalse(uidSet.Contains(16));

         AssertTrue(new UniqueIdentificationSet(0, 4).Contains(0));
      }