UpdateSize() private method

Updates the size.
private UpdateSize ( ) : void
return void
Beispiel #1
0
        /// <summary>
        /// Caps the specified d.
        /// </summary>
        /// <param name="d">The d.</param>
        /// <returns></returns>
        public override Domain Cap(Domain d)
        {
            if (!(d is AllenDomain))
            {
                return(EMPTY);
            }
            var         newD = new AllenDomain();
            AllenDomain d0   = this;
            var         d1   = (AllenDomain)d;

            try {
                int i0 = 0;
                int i1 = 0;
                while (i0 < d0.intervals.Count && i1 < d1.intervals.Count)
                {
                    var interval = (int[])d0.intervals[i0];
                    int min0     = interval[0];
                    int max0     = interval[1];
                    interval = (int[])d1.intervals[i1];
                    int min1 = interval[0];
                    int max1 = interval[1];
                    if (max0 < min1)
                    {
                        i0++;
                        continue;
                    }
                    if (max1 < min0)
                    {
                        i1++;
                        continue;
                    }
                    interval    = new int[2];
                    interval[0] = Math.Max(min0, min1);
                    interval[1] = Math.Min(max0, max1);
                    newD.intervals.Add(interval);
                    if (max0 <= max1)
                    {
                        i0++;
                    }
                    if (max1 <= max0)
                    {
                        i1++;
                    }
                }
            } catch (IndexOutOfRangeException) {
            }
            newD.UpdateSize();
            newD.UpdateMinMax();
            if (newD.Empty)
            {
                return(EMPTY);
            }
            return(newD);
        }
Beispiel #2
0
        /// <summary>
        /// Deletes the specified lo.
        /// </summary>
        /// <param name="lo">The lo.</param>
        /// <param name="hi">The hi.</param>
        /// <returns></returns>
        public virtual AllenDomain Delete(int lo, int hi)
        {
            if (sizeField == 0 || lo > hi || hi < minField || maxField < lo)
            {
                return(this);
            }
            if (lo == hi)
            {
                return(Delete(lo));
            }
            var d = new AllenDomain();

            try {
                for (int i = 0; i < intervals.Count; i++)
                {
                    var interval = (int[])intervals[i];
                    int mi       = Math.Max(lo, interval[0]);
                    int ma       = Math.Min(hi, interval[1]);
                    if (mi <= ma)
                    {
                        if (interval[0] < mi)
                        {
                            var inv = new int[2];
                            inv[0] = interval[0];
                            inv[1] = mi - 1;
                            d.intervals.Add(inv);
                        }
                        if (ma < interval[1])
                        {
                            var inv = new int[2];
                            inv[0] = ma + 1;
                            inv[1] = interval[1];
                            d.intervals.Add(inv);
                        }
                    }
                    else
                    {
                        var inv = new int[2];
                        inv[0] = interval[0];
                        inv[1] = interval[1];
                        d.intervals.Add(inv);
                    }
                }
            } catch (IndexOutOfRangeException) {
            }
            d.UpdateSize();
            d.UpdateMinMax();
            return(d);
        }
Beispiel #3
0
 /// <summary>
 /// Deletes the specified lo.
 /// </summary>
 /// <param name="lo">The lo.</param>
 /// <param name="hi">The hi.</param>
 /// <returns></returns>
 public virtual AllenDomain Delete(int lo, int hi)
 {
     if (sizeField == 0 || lo > hi || hi < minField || maxField < lo)
         return this;
     if (lo == hi)
         return Delete(lo);
     var d = new AllenDomain();
     try {
         for (int i = 0; i < _intervals.Count; i++) {
             var interval = (int[])_intervals[i];
             int mi = Math.Max(lo, interval[0]);
             int ma = Math.Min(hi, interval[1]);
             if (mi <= ma) {
                 if (interval[0] < mi) {
                     var inv = new int[2];
                     inv[0] = interval[0];
                     inv[1] = mi - 1;
                     d._intervals.Add(inv);
                 }
                 if (ma < interval[1]) {
                     var inv = new int[2];
                     inv[0] = ma + 1;
                     inv[1] = interval[1];
                     d._intervals.Add(inv);
                 }
             } else {
                 var inv = new int[2];
                 inv[0] = interval[0];
                 inv[1] = interval[1];
                 d._intervals.Add(inv);
             }
         }
     } catch (IndexOutOfRangeException) {
     }
     d.UpdateSize();
     d.UpdateMinMax();
     return d;
 }
Beispiel #4
0
 /// <summary>
 /// Caps the specified d.
 /// </summary>
 /// <param name="d">The d.</param>
 /// <returns></returns>
 public override Domain Cap(Domain d)
 {
     if (!(d is AllenDomain))
         return EMPTY;
     var newD = new AllenDomain();
     AllenDomain d0 = this;
     var d1 = (AllenDomain)d;
     try {
         int i0 = 0;
         int i1 = 0;
         while (i0 < d0._intervals.Count && i1 < d1._intervals.Count) {
             var interval = (int[])d0._intervals[i0];
             int min0 = interval[0];
             int max0 = interval[1];
             interval = (int[])d1._intervals[i1];
             int min1 = interval[0];
             int max1 = interval[1];
             if (max0 < min1) {
                 i0++;
                 continue;
             }
             if (max1 < min0) {
                 i1++;
                 continue;
             }
             interval = new int[2];
             interval[0] = Math.Max(min0, min1);
             interval[1] = Math.Min(max0, max1);
             newD._intervals.Add(interval);
             if (max0 <= max1)
                 i0++;
             if (max1 <= max0)
                 i1++;
         }
     } catch (IndexOutOfRangeException) {
     }
     newD.UpdateSize();
     newD.UpdateMinMax();
     if (newD.Empty)
         return EMPTY;
     return newD;
 }