Beispiel #1
0
        /** Given the set of possible values (rather than, say UNICODE or MAXINT),
         *  return a new set containing all elements in vocabulary, but not in
         *  this.  The computation is (vocabulary - this).
         *
         *  'this' is assumed to be either a subset or equal to vocabulary.
         */
        public virtual IIntSet Complement(IIntSet vocabulary)
        {
            if (vocabulary == null)
            {
                return(null); // nothing in common with null set
            }
            if (!(vocabulary is IntervalSet))
            {
                throw new ArgumentException("can't complement with non IntervalSet (" +
                                            vocabulary.GetType().Name + ")");
            }
            IntervalSet vocabularyIS = ((IntervalSet)vocabulary);
            int         maxElement   = vocabularyIS.GetMaxElement();

            IntervalSet compl = new IntervalSet();
            int         n     = intervals.Count;

            if (n == 0)
            {
                return(compl);
            }
            Interval first = (Interval)intervals[0];

            // add a range from 0 to first.a constrained to vocab
            if (first.a > 0)
            {
                IntervalSet s = IntervalSet.Of(0, first.a - 1);
                IntervalSet a = (IntervalSet)s.And(vocabularyIS);
                compl.AddAll(a);
            }
            for (int i = 1; i < n; i++)
            { // from 2nd interval .. nth
                Interval    previous = (Interval)intervals[i - 1];
                Interval    current  = (Interval)intervals[i];
                IntervalSet s        = IntervalSet.Of(previous.b + 1, current.a - 1);
                IntervalSet a        = (IntervalSet)s.And(vocabularyIS);
                compl.AddAll(a);
            }
            Interval last = (Interval)intervals[n - 1];

            // add a range from last.b to maxElement constrained to vocab
            if (last.b < maxElement)
            {
                IntervalSet s = IntervalSet.Of(last.b + 1, maxElement);
                IntervalSet a = (IntervalSet)s.And(vocabularyIS);
                compl.AddAll(a);
            }
            return(compl);
        }
Beispiel #2
0
        public static BitSet Of(IIntSet set)
        {
            if (set == null)
            {
                return(null);
            }

            if (set is BitSet)
            {
                return((BitSet)set);
            }
            if (set is IntervalSet)
            {
                BitSet s = new BitSet();
                s.AddAll(set);
                return(s);
            }
            throw new ArgumentException("can't create BitSet from " + set.GetType().Name);
        }
Beispiel #3
0
        public virtual Antlr4.Runtime.Misc.IntervalSet AddAll(IIntSet set)
        {
            if (set == null)
            {
                return(this);
            }
            if (!(set is Antlr4.Runtime.Misc.IntervalSet))
            {
                throw new ArgumentException("can't add non IntSet (" + set.GetType().FullName + ") to IntervalSet");
            }
            Antlr4.Runtime.Misc.IntervalSet other = (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);
            }
            return(this);
        }
Beispiel #4
0
 public virtual void AddAll(IIntSet set)
 {
     if (set is BitSet)
     {
         this.OrInPlace((BitSet)set);
     }
     else if (set is IntervalSet)
     {
         IntervalSet other = (IntervalSet)set;
         // walk set and add each interval
         foreach (Interval I in other.intervals)
         {
             this.OrInPlace(BitSet.Range(I.a, I.b));
         }
     }
     else
     {
         throw new ArgumentException("can't add " +
                                     set.GetType().Name +
                                     " to BitSet");
     }
 }
Beispiel #5
0
        public virtual void AddAll(IIntSet set)
        {
            if (set == null)
            {
                return;
            }
            if (!(set is IntervalSet))
            {
                throw new ArgumentException("can't add non IntSet (" +
                                            set.GetType().Name +
                                            ") to IntervalSet");
            }
            IntervalSet other = (IntervalSet)set;
            // walk set and add each interval
            int n = other.intervals.Count;

            for (int i = 0; i < n; i++)
            {
                Interval I = (Interval)other.intervals[i];
                this.Add(I.a, I.b);
            }
        }
Beispiel #6
0
 /// <summary>
 /// Given the set of possible values (rather than, say UNICODE or MAXINT),
 /// return a new set containing all elements in vocabulary, but not in
 /// this.
 /// </summary>
 /// <remarks>
 /// Given the set of possible values (rather than, say UNICODE or MAXINT),
 /// return a new set containing all elements in vocabulary, but not in
 /// this.  The computation is (vocabulary - this).
 /// 'this' is assumed to be either a subset or equal to vocabulary.
 /// </remarks>
 public virtual Antlr4.Runtime.Misc.IntervalSet Complement(IIntSet vocabulary)
 {
     if (vocabulary == null)
     {
         return null;
     }
     // nothing in common with null set
     if (!(vocabulary is Antlr4.Runtime.Misc.IntervalSet))
     {
         throw new ArgumentException("can't complement with non IntervalSet (" + vocabulary
             .GetType().FullName + ")");
     }
     Antlr4.Runtime.Misc.IntervalSet vocabularyIS = ((Antlr4.Runtime.Misc.IntervalSet)
         vocabulary);
     int maxElement = vocabularyIS.GetMaxElement();
     Antlr4.Runtime.Misc.IntervalSet compl = new Antlr4.Runtime.Misc.IntervalSet();
     int n = intervals.Count;
     if (n == 0)
     {
         return compl;
     }
     Interval first = intervals[0];
     // add a range from 0 to first.a constrained to vocab
     if (first.a > 0)
     {
         Antlr4.Runtime.Misc.IntervalSet s = Antlr4.Runtime.Misc.IntervalSet.Of(0, first.a
              - 1);
         Antlr4.Runtime.Misc.IntervalSet a = s.And(vocabularyIS);
         compl.AddAll(a);
     }
     for (int i = 1; i < n; i++)
     {
         // from 2nd interval .. nth
         Interval previous = intervals[i - 1];
         Interval current = intervals[i];
         Antlr4.Runtime.Misc.IntervalSet s = Antlr4.Runtime.Misc.IntervalSet.Of(previous.b
              + 1, current.a - 1);
         Antlr4.Runtime.Misc.IntervalSet a = s.And(vocabularyIS);
         compl.AddAll(a);
     }
     Interval last = intervals[n - 1];
     // add a range from last.b to maxElement constrained to vocab
     if (last.b < maxElement)
     {
         Antlr4.Runtime.Misc.IntervalSet s = Antlr4.Runtime.Misc.IntervalSet.Of(last.b + 1
             , maxElement);
         Antlr4.Runtime.Misc.IntervalSet a = s.And(vocabularyIS);
         compl.AddAll(a);
     }
     return compl;
 }
Beispiel #7
0
 public virtual Antlr4.Runtime.Misc.IntervalSet AddAll(IIntSet set)
 {
     if (set == null)
     {
         return this;
     }
     if (!(set is Antlr4.Runtime.Misc.IntervalSet))
     {
         throw new ArgumentException("can't add non IntSet (" + set.GetType().FullName + ") to IntervalSet"
             );
     }
     Antlr4.Runtime.Misc.IntervalSet other = (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);
     }
     return this;
 }