Exemple #1
0
        public static erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet Of(int a)
        {
            erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet s = new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet();

            s.Add(a);
            return(s);
        }
Exemple #2
0
 public virtual erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet Or(IIntSet a)
 {
     erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet o = new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet();
     o.AddAll(this);
     o.AddAll(a);
     return(o);
 }
Exemple #3
0
 public virtual erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet AddAll(IIntSet set)
 {
     if (set == null)
     {
         return(this);
     }
     if (set is erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet)
     {
         erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet other = (erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet)set;
         // walk set and add each interval
         int n = other.intervals.Count;
         for (int i = 0; i < n; i++)
         {
             Interval I = other.intervals[i];
             this.Add(I.a, I.b);
         }
     }
     else
     {
         foreach (int value in set.ToList())
         {
             Add(value);
         }
     }
     return(this);
 }
Exemple #4
0
 /// <summary>
 /// Are two IntervalSets equal?  Because all intervals are sorted
 /// and disjoint, equals is a simple linear walk over both lists
 /// to make sure they are the same.
 /// </summary>
 /// <remarks>
 /// Are two IntervalSets equal?  Because all intervals are sorted
 /// and disjoint, equals is a simple linear walk over both lists
 /// to make sure they are the same.  Interval.equals() is used
 /// by the List.equals() method to check the ranges.
 /// </remarks>
 public override bool Equals(object obj)
 {
     if (obj == null || !(obj is erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet))
     {
         return(false);
     }
     erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet other = (erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet)obj;
     return(this.intervals.SequenceEqual(other.intervals));
 }
Exemple #5
0
 /// <summary>combine all sets in the array returned the or'd value</summary>
 public static erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet Or(erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet[] sets)
 {
     erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet r = new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet();
     foreach (erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet s in sets)
     {
         r.AddAll(s);
     }
     return(r);
 }
Exemple #6
0
 public virtual erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet Subtract(IIntSet a)
 {
     if (a == null || a.IsNil)
     {
         return(new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet(this));
     }
     if (a is erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet)
     {
         return(Subtract(this, (erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet)a));
     }
     erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet other = new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet();
     other.AddAll(a);
     return(Subtract(this, other));
 }
Exemple #7
0
 /// <summary>
 /// <inheritDoc/>
 ///
 /// </summary>
 public virtual erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet Complement(IIntSet vocabulary)
 {
     if (vocabulary == null || vocabulary.IsNil)
     {
         return(null);
     }
     // nothing in common with null set
     erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet vocabularyIS;
     if (vocabulary is erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet)
     {
         vocabularyIS = (erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet)vocabulary;
     }
     else
     {
         vocabularyIS = new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet();
         vocabularyIS.AddAll(vocabulary);
     }
     return(vocabularyIS.Subtract(this));
 }
Exemple #8
0
 public IntervalSet(erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet set)
     : this()
 {
     AddAll(set);
 }
Exemple #9
0
        /// <summary>
        /// <inheritDoc/>
        ///
        /// </summary>
        public virtual erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet And(IIntSet other)
        {
            if (other == null)
            {
                //|| !(other instanceof IntervalSet) ) {
                return(null);
            }
            // nothing in common with null set
            IList <Interval> myIntervals    = this.intervals;
            IList <Interval> theirIntervals = ((erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet)other).intervals;

            erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet intersection = null;
            int mySize    = myIntervals.Count;
            int theirSize = theirIntervals.Count;
            int i         = 0;
            int j         = 0;

            // iterate down both interval lists looking for nondisjoint intervals
            while (i < mySize && j < theirSize)
            {
                Interval mine   = myIntervals[i];
                Interval theirs = theirIntervals[j];
                //System.out.println("mine="+mine+" and theirs="+theirs);
                if (mine.StartsBeforeDisjoint(theirs))
                {
                    // move this iterator looking for interval that might overlap
                    i++;
                }
                else
                {
                    if (theirs.StartsBeforeDisjoint(mine))
                    {
                        // move other iterator looking for interval that might overlap
                        j++;
                    }
                    else
                    {
                        if (mine.ProperlyContains(theirs))
                        {
                            // overlap, add intersection, get next theirs
                            if (intersection == null)
                            {
                                intersection = new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet();
                            }
                            intersection.Add(mine.Intersection(theirs));
                            j++;
                        }
                        else
                        {
                            if (theirs.ProperlyContains(mine))
                            {
                                // overlap, add intersection, get next mine
                                if (intersection == null)
                                {
                                    intersection = new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet();
                                }
                                intersection.Add(mine.Intersection(theirs));
                                i++;
                            }
                            else
                            {
                                if (!mine.Disjoint(theirs))
                                {
                                    // overlap, add intersection
                                    if (intersection == null)
                                    {
                                        intersection = new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet();
                                    }
                                    intersection.Add(mine.Intersection(theirs));
                                    // Move the iterator of lower range [a..b], but not
                                    // the upper range as it may contain elements that will collide
                                    // with the next iterator. So, if mine=[0..115] and
                                    // theirs=[115..200], then intersection is 115 and move mine
                                    // but not theirs as theirs may collide with the next range
                                    // in thisIter.
                                    // move both iterators to next ranges
                                    if (mine.StartsAfterNonDisjoint(theirs))
                                    {
                                        j++;
                                    }
                                    else
                                    {
                                        if (theirs.StartsAfterNonDisjoint(mine))
                                        {
                                            i++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (intersection == null)
            {
                return(new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet());
            }
            return(intersection);
        }
Exemple #10
0
        public static erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet Subtract(erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet left, erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet right)
        {
            if (left == null || left.IsNil)
            {
                return(new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet());
            }
            erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet result = new erl.Oracle.TnsNames.Antlr4.Runtime.Misc.IntervalSet(left);

            if (right == null || right.IsNil)
            {
                // right set has no elements; just return the copy of the current set
                return(result);
            }
            int resultI = 0;
            int rightI  = 0;

            while (resultI < result.intervals.Count && rightI < right.intervals.Count)
            {
                Interval resultInterval = result.intervals[resultI];
                Interval rightInterval  = right.intervals[rightI];
                // operation: (resultInterval - rightInterval) and update indexes
                if (rightInterval.b < resultInterval.a)
                {
                    rightI++;
                    continue;
                }
                if (rightInterval.a > resultInterval.b)
                {
                    resultI++;
                    continue;
                }
                Interval?beforeCurrent = null;
                Interval?afterCurrent  = null;
                if (rightInterval.a > resultInterval.a)
                {
                    beforeCurrent = new Interval(resultInterval.a, rightInterval.a - 1);
                }
                if (rightInterval.b < resultInterval.b)
                {
                    afterCurrent = new Interval(rightInterval.b + 1, resultInterval.b);
                }
                if (beforeCurrent != null)
                {
                    if (afterCurrent != null)
                    {
                        // split the current interval into two
                        result.intervals[resultI] = beforeCurrent.Value;
                        result.intervals.Insert(resultI + 1, afterCurrent.Value);
                        resultI++;
                        rightI++;
                        continue;
                    }
                    else
                    {
                        // replace the current interval
                        result.intervals[resultI] = beforeCurrent.Value;
                        resultI++;
                        continue;
                    }
                }
                else
                {
                    if (afterCurrent != null)
                    {
                        // replace the current interval
                        result.intervals[resultI] = afterCurrent.Value;
                        rightI++;
                        continue;
                    }
                    else
                    {
                        // remove the current interval (thus no need to increment resultI)
                        result.intervals.RemoveAt(resultI);
                        continue;
                    }
                }
            }
            // If rightI reached right.intervals.size(), no more intervals to subtract from result.
            // If resultI reached result.intervals.size(), we would be subtracting from an empty set.
            // Either way, we are done.
            return(result);
        }