示例#1
0
        /// <summary>
        /// Compares a Triple Pattern to another Triple Pattern
        /// </summary>
        /// <param name="other">Other Triple Pattern</param>
        /// <returns></returns>
        /// <remarks>
        /// <para>
        /// The aim of this function is to sort Triple Patterns into what is hopefully an optimal order such that during execution the query space is restricted as early as possible.
        /// </para>
        /// <para>
        /// The basic rules of this are as follows:
        /// <ol>
        ///     <li>Patterns with fewer variables should be executed first</li>
        ///     <li>Patterns using the same variables should be executed in sequence</li>
        ///     <li>Patterns using indexes which are considered more useful should be executed first</li>
        /// </ol>
        /// </para>
        /// </remarks>
        public virtual int CompareTo(ITriplePattern other)
        {
            if (this._vars.Count < other.Variables.Count)
            {
                //We have fewer variables so we go before the other pattern
                return(-1);
            }
            else if (this._vars.Count > other.Variables.Count)
            {
                //We have more variables so we go after the other pattern
                return(1);
            }
            else
            {
                if (this._vars.Count > 0)
                {
                    for (int i = 0; i < this._vars.Count; i++)
                    {
                        int c = this._vars[i].CompareTo(other.Variables[i]);
                        if (c < 0)
                        {
                            //Our variables occur alphabetically sooner than the other patterns so we go before the other pattern
                            return(-1);
                        }
                        else if (c > 0)
                        {
                            //Other variables occur alphabetically sooner than ours so we go after
                            return(1);
                        }
                        //Otherwise we continue checking
                    }

                    //If we reach this point then we contain the same variables
                    //Now we order based on our Index Types
                    TripleIndexSorter sorter = new TripleIndexSorter();
                    return(sorter.Compare(this.IndexType, other.IndexType));
                }
                else
                {
                    //Neither pattern has any variables so we consider these to be equivalent
                    //Order of these patterns has no effect
                    return(0);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Compares a Triple Pattern to another Triple Pattern
        /// </summary>
        /// <param name="other">Other Triple Pattern</param>
        /// <returns></returns>
        /// <remarks>
        /// <para>
        /// The aim of this function is to sort Triple Patterns into what is hopefully an optimal order such that during execution the query space is restricted as early as possible.
        /// </para>
        /// <para>
        /// The basic rules of this are as follows:
        /// <ol>
        ///     <li>Patterns with fewer variables should be executed first</li>
        ///     <li>Patterns using the same variables should be executed in sequence</li>
        ///     <li>Patterns using indexes which are considered more useful should be executed first</li>
        /// </ol>
        /// </para>
        /// </remarks>
        public virtual int CompareTo(ITriplePattern other)
        {
            if (this._vars.Count < other.Variables.Count)
            {
                //We have fewer variables so we go before the other pattern
                return -1;
            }
            else if (this._vars.Count > other.Variables.Count)
            {
                //We have more variables so we go after the other pattern
                return 1;
            }
            else
            {
                if (this._vars.Count > 0)
                {
                    for (int i = 0; i < this._vars.Count; i++)
                    {
                        int c = this._vars[i].CompareTo(other.Variables[i]);
                        if (c < 0)
                        {
                            //Our variables occur alphabetically sooner than the other patterns so we go before the other pattern
                            return -1;
                        }
                        else if (c > 0)
                        {
                            //Other variables occur alphabetically sooner than ours so we go after
                            return 1;
                        }
                        //Otherwise we continue checking
                    }

                    //If we reach this point then we contain the same variables
                    //Now we order based on our Index Types
                    TripleIndexSorter sorter = new TripleIndexSorter();
                    return sorter.Compare(this.IndexType, other.IndexType);
                }
                else
                {
                    //Neither pattern has any variables so we consider these to be equivalent
                    //Order of these patterns has no effect
                    return 0;
                }
            }
        }