Example #1
0
        /** TODO: implement this! */
        public IIntSet Or(IIntSet a)
        {
            IntervalSet o = new IntervalSet();

            o.AddAll(this);
            o.AddAll(a);
            //throw new NoSuchMethodError();
            return(o);
        }
Example #2
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);
        }