Exemplo n.º 1
0
        /// <summary>
        /// Determines if this QSET is equal to <paramref name="other"/>
        /// </summary>
        /// <param name="other">The QSET to compare to</param>
        /// <returns>True if the two QSETs contain identical content</returns>
        public bool Equals(QSET <T> other)
        {
            bool result = false;

            if (other != null)
            {
                result = (this.OriginalText != null ? this.OriginalText.Equals(other.OriginalText) : other.OriginalText == null) &&
                         base.Equals(other);
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Translate to a QSET
        /// </summary>
        public QSET <T> TranslateToQSET()
        {
            // A little more trickily done...
            // Basically we need to gather like terms and express
            // them as an QSI, QSU, QSP, QSS or QSD
            QSET <T> currentQset = null;

            List <SXCM <T> > likeTerms = new List <SXCM <T> >(10);
            SetOperator?     lastTerm  = SetOperator.Inclusive;
            int count = 0;

            foreach (var term in this)
            {
                // Usually the first we may have to default to inclusive
                SetOperator thisTerm = term.Operator ?? SetOperator.Inclusive;

                // same operator or is first one
                if (thisTerm.Equals(lastTerm) || count == 0 || currentQset == null && likeTerms.Count == 1)
                {
                    likeTerms.Add(term);
                }
                else
                {
                    currentQset = TranslateToQSETInternal(lastTerm.Value, likeTerms, currentQset);
                    likeTerms.Clear();
                    likeTerms.Add(term);
                }

                // prepare for next iteration
                lastTerm = thisTerm;
                count++;
            }

            currentQset = TranslateToQSETInternal(lastTerm.Value, likeTerms, currentQset);

            return(currentQset);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Translate to a QSET data internally
        /// </summary>
        private QSET <T> TranslateToQSETInternal(SetOperator operation, List <SXCM <T> > collectedTerms, QSET <T> context)
        {
            // We need to construct the appropriate structure
            switch (operation)
            {
            case SetOperator.Exclusive:     // difference
            {
                // QSD must be broken into groups of two
                int     iofs    = 0;
                QSD <T> diffSet = null;
                if (context == null)         // Null, then the minuend is our first term
                {
                    diffSet = new QSD <T>(collectedTerms[0].TranslateToQSETComponent(), null);
                    iofs    = 1;
                }
                else         // Not, then the current QSET is the minuend
                {
                    diffSet = new QSD <T>(context, null);
                }
                for (int i = iofs; i < collectedTerms.Count; i++)
                {
                    diffSet.Subtrahend = collectedTerms[i].TranslateToQSETComponent();
                    if (i + 1 < collectedTerms.Count)         // We need to make a new QSD where this is the minuend
                    {
                        diffSet = new QSD <T>(diffSet, null);
                    }
                }
                context = diffSet;
                break;
            }

            case SetOperator.Inclusive:     // union is pretty easy
            {
                QSU <T> unionSet       = new QSU <T>();
                bool    isQssCandidate = true;
                if (context != null)
                {
                    isQssCandidate &= (context is QSS <T>) && (context as QSS <T>).Count() == 1;
                    unionSet.Add(context);
                }
                foreach (var itm in collectedTerms)
                {
                    var qsuItem = itm.TranslateToQSETComponent();
                    isQssCandidate &= (qsuItem is QSS <T>) && (qsuItem as QSS <T>).Count() == 1;
                    unionSet.Add(qsuItem);
                }

                // Is the union set composed entirely of QSS instances with one item?
                if (isQssCandidate)
                {
                    var qssSet = new QSS <T>();
                    foreach (var itm in unionSet)
                    {
                        qssSet.Add((itm as QSS <T>).First());
                    }
                    context = qssSet;
                }
                else
                {
                    context = unionSet;
                }
                break;
            }

            case SetOperator.Intersect:     // intersect, also pretty easy
            {
                QSI <T> intersectSet = new QSI <T>();
                if (context != null)
                {
                    intersectSet.Add(context);
                }
                foreach (var itm in collectedTerms)
                {
                    intersectSet.Add(itm.TranslateToQSETComponent());
                }
                context = intersectSet;
                break;
            }

            case SetOperator.PeriodicHull:     // periodic hull, same as difference
            {
                // QSP must be broken into groups of two
                int     iofs      = 0;
                QSP <T> periodSet = null;
                if (context == null)         // Null, then the minuend is our first term
                {
                    periodSet = new QSP <T>(collectedTerms[0].TranslateToQSETComponent(), null);
                    iofs      = 1;
                }
                else         // Not, then the current QSET is the minuend
                {
                    periodSet = new QSP <T>(context, null);
                }
                for (int i = iofs; i < collectedTerms.Count; i++)
                {
                    periodSet.High = collectedTerms[i].TranslateToQSETComponent();
                    if (i + 1 < collectedTerms.Count)         // We need to make a new QSD where this is the minuend
                    {
                        periodSet = new QSP <T>(periodSet, null);
                    }
                }
                context = periodSet;
                break;
            }

            case SetOperator.Hull:     // convex hull
            {
                throw new InvalidOperationException("Cannot represent a HULL value");
            }
            }

            return(context);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Create a new instance of the GTS class with the specified <paramref name="hull"/>
 /// </summary>
 /// <param name="hull">The SXPR&lt;TS> to set as the hull</param>
 public GTS(QSET <TS> hull)
     : base()
 {
     this.Hull = hull;
 }