Beispiel #1
0
        public RangeSet Intersection(RangeSet rs2)
        {
            RangeSet rOut = new RangeSet();
            RangeSet rs1  = this;

            int i1 = 0;
            int i2 = 0;

            while (i1 < rs1.RangeCount && i2 < rs2.RangeCount)
            {
                Range r1 = rs1.ranges[i1];
                Range r2 = rs2.ranges[i2];

                ulong olo = Math.Max(r1.lo, r2.lo);
                ulong ohi = Math.Min(r1.hi, r2.hi);

                // if there is overlap in this section then we emit it
                if (olo < ohi)
                {
                    rOut.AddRange(olo, ohi);
                }

                if (r1.hi < r2.hi)
                {
                    i1++;
                }
                else
                {
                    i2++;
                }
            }

            return(rOut);
        }
Beispiel #2
0
        public bool Equals(RangeSet rs)
        {
            int c = ranges.Count;

            if (c != rs.ranges.Count)
            {
                return(false);
            }

            for (int i = 0; i < c; i++)
            {
                Range r1 = ranges[i];
                Range r2 = rs.ranges[i];

                if (r1.lo != r2.lo)
                {
                    return(false);
                }

                if (r1.hi != r2.hi)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #3
0
        public void RemoveRangeSet(RangeSet merge)
        {
            int c = merge.ranges.Count;

            for (int i = 0; i < c; i++)
            {
                Range r = merge.ranges[i];
                RemoveRange(r.lo, r.hi);
            }
        }
Beispiel #4
0
        public RangeSet Union(RangeSet rs2)
        {
            RangeSet rOut = new RangeSet();
            RangeSet rs1  = this;

            int i1 = 0;
            int i2 = 0;

            // try to add them in order because appending is the fastest
            while (i1 < rs1.RangeCount && i2 < rs2.RangeCount)
            {
                Range r1 = rs1.ranges[i1];
                Range r2 = rs2.ranges[i2];

                if (r1.hi < r2.hi)
                {
                    rOut.AddRange(r1.lo, r1.hi);
                    i1++;
                }
                else
                {
                    rOut.AddRange(r2.lo, r2.hi);
                    i2++;
                }
            }

            // now add whatever is left, we could have just done this in the first place but we wanted them in order

            while (i1 < rs1.RangeCount)
            {
                Range r1 = rs1.ranges[i1];
                rOut.AddRange(r1.lo, r1.hi);
                i1++;
            }

            while (i2 < rs2.RangeCount)
            {
                Range r2 = rs2.ranges[i2];
                rOut.AddRange(r2.lo, r2.hi);
                i2++;
            }

            return(rOut);
        }