Ejemplo n.º 1
0
        public IntIntervals Clone()
        {
            var clone = new IntIntervals();

            clone.starts = new Map <BigInteger, BigInteger>(starts);
            clone.ends   = new Map <BigInteger, BigInteger>(ends);
            return(clone);
        }
Ejemplo n.º 2
0
 public void UnionWith(IntIntervals intrvls)
 {
     Contract.Requires(intrvls != null);
     foreach (var intr in intrvls.starts)
     {
         Add(intr.Key, intr.Value);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns an new set of intervals containing the intersection of the inputs.
        /// </summary>
        public static IntIntervals MkIntersection(IntIntervals i1, IntIntervals i2)
        {
            Contract.Requires(i1 != null && i2 != null);
            if (i1 == i2)
            {
                return(i1.Clone());
            }

            var intrs = new IntIntervals();

            if (i1.Count == 0 || i2.Count == 0)
            {
                return(intrs);
            }

            BigInteger left, right;

            using (var it1 = i1.starts.GetEnumerator())
            {
                it1.MoveNext();
                using (var it2 = i2.starts.GetEnumerator())
                {
                    it2.MoveNext();
                    while (true)
                    {
                        left  = BigInteger.Max(it1.Current.Key, it2.Current.Key);
                        right = BigInteger.Min(it1.Current.Value, it2.Current.Value);
                        if (left <= right)
                        {
                            intrs.Add(left, right);
                        }

                        if (it2.Current.Value < it1.Current.Value)
                        {
                            if (!it2.MoveNext())
                            {
                                return(intrs);
                            }
                        }
                        else if (!it1.MoveNext())
                        {
                            return(intrs);
                        }
                    }
                }
            }
        }