Exemple #1
0
        private bool CompareSortIndexDesc(int[] id)
        {
            if (id.Length < indexDesc.Length)
            {
                return(false);
            }
            int j            = 0;
            int lenId        = id.Length;
            int lenIndexDesc = indexDesc.Length;

            for (int i = 0; i < lenId && j < lenIndexDesc; i++)
            {
                if (id[i] == indexDesc[j])
                {
                    j++;
                }
                else
                {
                    ColumnInfo canColumn = candidateColumns[DataKey.ColumnOrder(id[i])];
                    if (!(canColumn != null && canColumn.equalsOperator))
                    {
                        return(false);
                    }
                }
            }
            return(j == lenIndexDesc);
        }
Exemple #2
0
        private int CompareRecords(int record1, int record2)
        {
            int lenIndexDesc = indexDesc.Length;

            for (int i = 0; i < lenIndexDesc; i++)
            {
                Int32 d = indexDesc[i];
                int   c = table.Columns[DataKey.ColumnOrder(d)].Compare(record1, record2);
                if (c != 0)
                {
                    if (DataKey.SortDecending(d))
                    {
                        c = -c;
                    }
                    return(c);
                }
            }

            int id1  = table.recordManager[record1] == null? 0: table.recordManager[record1].rowID;
            int id2  = table.recordManager[record2] == null? 0: table.recordManager[record2].rowID;
            int diff = id1 - id2;

            // if they're two records in the same row, we need to be able to distinguish them.
            if (diff == 0 && record1 != record2 &&
                table.recordManager[record1] != null && table.recordManager[record2] != null)
            {
                id1  = (int)table.recordManager[record1].GetRecordState(record1);
                id2  = (int)table.recordManager[record2].GetRecordState(record2);
                diff = id1 - id2;
            }

            return(diff);
        }
Exemple #3
0
        private int Evaluate(int record)
        {
            DataRow row = this.table.recordManager[record];

            if (row != null)
            {
                DataRowVersion original = DataRowVersion.Default;
                if (row.oldRecord == record)
                {
                    original = DataRowVersion.Original;
                }
                else if (row.newRecord == record)
                {
                    original = DataRowVersion.Current;
                }
                else if (row.tempRecord == record)
                {
                    original = DataRowVersion.Proposed;
                }
                int[] indexDesc = this.index.IndexDesc;
                for (int i = 0; i < this.matchedCandidates; i++)
                {
                    int num2 = this.Eval(this.candidateColumns[DataKey.ColumnOrder(indexDesc[i])].expr, row, original);
                    if (num2 != 0)
                    {
                        if (!DataKey.SortDecending(indexDesc[i]))
                        {
                            return(num2);
                        }
                        return(-num2);
                    }
                }
            }
            return(0);
        }
Exemple #4
0
        private bool CompareSortIndexDesc(int[] id)
        {
            if (id.Length < this.indexDesc.Length)
            {
                return(false);
            }
            int index = 0;

            for (int i = 0; (i < id.Length) && (index < this.indexDesc.Length); i++)
            {
                if (id[i] == this.indexDesc[index])
                {
                    index++;
                }
                else
                {
                    ColumnInfo info = this.candidateColumns[DataKey.ColumnOrder(id[i])];
                    if ((info == null) || !info.equalsOperator)
                    {
                        return(false);
                    }
                }
            }
            return(index == this.indexDesc.Length);
        }
Exemple #5
0
        private int CompareRecords(int record1, int record2)
        {
            int length = this.indexDesc.Length;

            for (int i = 0; i < length; i++)
            {
                int indexDesc = this.indexDesc[i];
                int num3      = this.table.Columns[DataKey.ColumnOrder(indexDesc)].Compare(record1, record2);
                if (num3 != 0)
                {
                    if (DataKey.SortDecending(indexDesc))
                    {
                        num3 = -num3;
                    }
                    return(num3);
                }
            }
            long recordState = (this.table.recordManager[record1] == null) ? 0L : this.table.recordManager[record1].rowID;
            long num         = (this.table.recordManager[record2] == null) ? 0L : this.table.recordManager[record2].rowID;
            int  num5        = (recordState < num) ? -1 : ((num < recordState) ? 1 : 0);

            if (((num5 == 0) && (record1 != record2)) && ((this.table.recordManager[record1] != null) && (this.table.recordManager[record2] != null)))
            {
                recordState = (long)this.table.recordManager[record1].GetRecordState(record1);
                num         = (long)this.table.recordManager[record2].GetRecordState(record2);
                num5        = (recordState < num) ? -1 : ((num < recordState) ? 1 : 0);
            }
            return(num5);
        }
Exemple #6
0
        private void BuildLinearExpression()
        {
            int num;

            int[] indexDesc = this.index.IndexDesc;
            for (num = 0; num < this.matchedCandidates; num++)
            {
                ColumnInfo info = this.candidateColumns[DataKey.ColumnOrder(indexDesc[num])];
                info.flag = true;
            }
            int length = this.candidateColumns.Length;

            for (num = 0; num < length; num++)
            {
                if (this.candidateColumns[num] != null)
                {
                    if (!this.candidateColumns[num].flag)
                    {
                        if (this.candidateColumns[num].expr != null)
                        {
                            this.linearExpression = (this.linearExpression == null) ? this.candidateColumns[num].expr : new BinaryNode(this.table, 0x1a, this.candidateColumns[num].expr, this.linearExpression);
                        }
                    }
                    else
                    {
                        this.candidateColumns[num].flag = false;
                    }
                }
            }
        }
Exemple #7
0
 public bool EqualKeys(int record1, int record2)
 {
     for (int i = 0; i < indexDesc.Length; i++)
     {
         int col = DataKey.ColumnOrder(indexDesc[i]);
         if (table.Columns[col].Compare(record1, record2) != 0)
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #8
0
        private int CompareRecordToKey(int record1, object val)
        {
            Debug.Assert(indexDesc.Length == 1, "Invalid ussage: CompareRecordToKey");
            Int32 d = indexDesc[0];
            int   c = table.Columns[DataKey.ColumnOrder(d)].CompareToValue(record1, val);

            if (c != 0)
            {
                if (DataKey.SortDecending(d))
                {
                    c = -c;
                }
                return(c);
            }
            return(0);
        }
Exemple #9
0
 private int CompareRecordToKey(int record1, object[] vals)
 {
     for (int i = 0; i < indexDesc.Length; i++)
     {
         Int32 d = indexDesc[i];
         int   c = table.Columns[DataKey.ColumnOrder(d)].CompareToValue(record1, vals[i]);
         if (c != 0)
         {
             if (DataKey.SortDecending(d))
             {
                 c = -c;
             }
             return(c);
         }
     }
     return(0);
 }
Exemple #10
0
        // Returns no. of columns that are matched
        private int CompareClosestCandidateIndexDesc(int[] id)
        {
            int count = (id.Length < nCandidates ? id.Length : nCandidates);
            int i     = 0;

            for (; i < count; i++)
            {
                ColumnInfo canColumn = candidateColumns[DataKey.ColumnOrder(id[i])];
                if (canColumn == null || canColumn.expr == null)
                {
                    break;
                }
                else
                if (!canColumn.equalsOperator)
                {
                    return(i + 1);
                }
            }
            return(i);
        }
Exemple #11
0
        private int CompareClosestCandidateIndexDesc(int[] id)
        {
            int num2  = (id.Length < this.nCandidates) ? id.Length : this.nCandidates;
            int index = 0;

            while (index < num2)
            {
                ColumnInfo info = this.candidateColumns[DataKey.ColumnOrder(id[index])];
                if ((info == null) || (info.expr == null))
                {
                    return(index);
                }
                if (!info.equalsOperator)
                {
                    return(index + 1);
                }
                index++;
            }
            return(index);
        }
Exemple #12
0
        private int Evaluate(int record)
        {
            DataRow row = table.recordManager[record];

            if (row == null)
            {
                return(0);
            }

            // UNDONE: perf switch to (row, version) internaly

            DataRowVersion version = DataRowVersion.Default;

            if (row.oldRecord == record)
            {
                version = DataRowVersion.Original;
            }
            else if (row.newRecord == record)
            {
                version = DataRowVersion.Current;
            }
            else if (row.tempRecord == record)
            {
                version = DataRowVersion.Proposed;
            }

            int[] id = index.IndexDesc;
            for (int i = 0; i < matchedCandidates; i++)
            {
                Debug.Assert(candidateColumns[DataKey.ColumnOrder(id[i])] != null, "How come this is not a candidate column");
                Debug.Assert(candidateColumns[DataKey.ColumnOrder(id[i])].expr != null, "How come there is no associated expression");
                int c = Eval(candidateColumns[DataKey.ColumnOrder(id[i])].expr, row, version);
                if (c != 0)
                {
                    return(DataKey.SortDecending(id[i]) ? -c : c);
                }
            }
            return(0);
        }
Exemple #13
0
        // Based on the current index and candidate columns settings, build the linear expression; Should be called only when there is atleast something for Binary Searching
        private void BuildLinearExpression()
        {
            int i;

            int[] id    = index.IndexDesc;
            int   lenId = id.Length;

            Debug.Assert(matchedCandidates > 0 && matchedCandidates <= lenId, "BuildLinearExpression : Invalid Index");
            for (i = 0; i < matchedCandidates; i++)
            {
                ColumnInfo canColumn = candidateColumns[DataKey.ColumnOrder(id[i])];
                Debug.Assert(canColumn != null && canColumn.expr != null, "BuildLinearExpression : Must be a matched candidate");
                canColumn.flag = true;
            }
            Debug.Assert(matchedCandidates == 1 || candidateColumns[matchedCandidates - 1].equalsOperator, "BuildLinearExpression : Invalid matched candidates");
            int lenCanColumns = candidateColumns.Length;

            for (i = 0; i < lenCanColumns; i++)
            {
                if (candidateColumns[i] != null)
                {
                    if (!candidateColumns[i].flag)
                    {
                        if (candidateColumns[i].expr != null)
                        {
                            this.linearExpression = (this.linearExpression == null ? candidateColumns[i].expr : new BinaryNode(Operators.And, candidateColumns[i].expr, this.linearExpression));
                        }
                    }
                    else
                    {
                        candidateColumns[i].flag = false;
                    }
                }
            }
            Debug.Assert(this.linearExpression != null, "BuildLinearExpression : How come there is nothing to search linearly");
        }
Exemple #14
0
        // Based on the required sorting and candidate columns settings, create a new index; Should be called only when there is no existing index to be reused
        private void CreateIndex()
        {
            if (index == null)
            {
                if (nCandidates == 0)
                {
                    index = new Index(table, indexDesc, recordStates, null);
                }
                else
                {
                    int  i;
                    int  lenCanColumns  = candidateColumns.Length;
                    int  lenIndexDesc   = indexDesc.Length;
                    bool equalsOperator = true;
                    for (i = 0; i < lenCanColumns; i++)
                    {
                        if (candidateColumns[i] != null)
                        {
                            if (!candidateColumns[i].equalsOperator)
                            {
                                equalsOperator = false;
                                break;
                            }
                        }
                    }

                    for (i = 0; i < lenIndexDesc; i++)
                    {
                        if (candidateColumns[DataKey.ColumnOrder(indexDesc[i])] == null)
                        {
                            break;
                        }
                    }
                    int   indexNotInCandidates = indexDesc.Length - i;
                    int   candidatesNotInIndex = nCandidates - i;
                    int[] ndxDesc = new int[nCandidates + indexNotInCandidates];

                    if (equalsOperator)
                    {
                        for (i = 0; i < lenIndexDesc; i++)
                        {
                            ndxDesc[candidatesNotInIndex + i] = indexDesc[i];
                            ColumnInfo canColumn = candidateColumns[DataKey.ColumnOrder(indexDesc[i])];
                            if (canColumn != null)
                            {
                                canColumn.flag = true;
                            }
                        }
                        int j = 0;
                        for (i = 0; i < lenCanColumns; i++)
                        {
                            if (candidateColumns[i] != null)
                            {
                                if (!candidateColumns[i].flag)
                                {
                                    ndxDesc[j++] = i;
                                }
                                else
                                {
                                    candidateColumns[i].flag = false;
                                }
                            }
                        }
                        Debug.Assert(j == candidatesNotInIndex, "Whole ndxDesc should be filled!");
                        index             = new Index(table, ndxDesc, recordStates, null);
                        matchedCandidates = nCandidates;
                    }
                    else
                    {
                        for (i = 0; i < lenIndexDesc; i++)
                        {
                            ndxDesc[i] = indexDesc[i];
                            ColumnInfo canColumn = candidateColumns[DataKey.ColumnOrder(indexDesc[i])];
                            if (canColumn != null)
                            {
                                canColumn.flag = true;
                            }
                        }
                        int j = i;
                        for (i = 0; i < lenCanColumns; i++)
                        {
                            if (candidateColumns[i] != null)
                            {
                                if (!candidateColumns[i].flag)
                                {
                                    ndxDesc[j++] = i;
                                }
                                else
                                {
                                    candidateColumns[i].flag = false;
                                }
                            }
                        }
                        Debug.Assert(j == nCandidates + indexNotInCandidates, "Whole ndxDesc should be filled!");
                        index             = new Index(table, ndxDesc, recordStates, null);
                        matchedCandidates = 0;
                        if (this.linearExpression != this.expression)
                        {
                            int[] id = index.IndexDesc;
                            while (matchedCandidates < j)   // haroona : j = index.IndexDesc.Length
                            {
                                ColumnInfo canColumn = candidateColumns[DataKey.ColumnOrder(id[matchedCandidates])];
                                if (canColumn == null || canColumn.expr == null)
                                {
                                    break;
                                }
                                matchedCandidates++;
                                if (!canColumn.equalsOperator)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #15
0
 private void CreateIndex()
 {
     if (this.index == null)
     {
         if (this.nCandidates == 0)
         {
             this.index = new Index(this.table, this.IndexFields, this.recordStates, null);
             this.index.AddRef();
         }
         else
         {
             int  num;
             int  length = this.candidateColumns.Length;
             int  num5   = this.indexDesc.Length;
             bool flag   = true;
             for (num = 0; num < length; num++)
             {
                 if ((this.candidateColumns[num] != null) && !this.candidateColumns[num].equalsOperator)
                 {
                     flag = false;
                     break;
                 }
             }
             int num2 = 0;
             for (num = 0; num < num5; num++)
             {
                 ColumnInfo info4 = this.candidateColumns[DataKey.ColumnOrder(this.indexDesc[num])];
                 if (info4 != null)
                 {
                     info4.flag = true;
                     num2++;
                 }
             }
             int   num7     = num5 - num2;
             int[] ndexDesc = new int[this.nCandidates + num7];
             if (flag)
             {
                 num2 = 0;
                 for (num = 0; num < length; num++)
                 {
                     if (this.candidateColumns[num] != null)
                     {
                         ndexDesc[num2++] = num;
                         this.candidateColumns[num].flag = false;
                     }
                 }
                 for (num = 0; num < num5; num++)
                 {
                     ColumnInfo info = this.candidateColumns[DataKey.ColumnOrder(this.indexDesc[num])];
                     if ((info == null) || info.flag)
                     {
                         ndexDesc[num2++] = this.indexDesc[num];
                         if (info != null)
                         {
                             info.flag = false;
                         }
                     }
                 }
                 for (num = 0; num < this.candidateColumns.Length; num++)
                 {
                     if (this.candidateColumns[num] != null)
                     {
                         this.candidateColumns[num].flag = false;
                     }
                 }
                 IndexField[] zeroIndexField = DataTable.zeroIndexField;
                 if (0 < ndexDesc.Length)
                 {
                     zeroIndexField = new IndexField[ndexDesc.Length];
                     for (int i = 0; i < ndexDesc.Length; i++)
                     {
                         DataColumn column2      = this.table.Columns[DataKey.ColumnOrder(ndexDesc[i])];
                         bool       isDescending = DataKey.SortDecending(ndexDesc[i]);
                         zeroIndexField[i] = new IndexField(column2, isDescending);
                     }
                 }
                 this.index = new Index(this.table, ndexDesc, zeroIndexField, this.recordStates, null);
                 if (!this.IsOperatorIn(this.expression))
                 {
                     this.index.AddRef();
                 }
                 this.matchedCandidates = this.nCandidates;
             }
             else
             {
                 num = 0;
                 while (num < num5)
                 {
                     ndexDesc[num] = this.indexDesc[num];
                     ColumnInfo info3 = this.candidateColumns[DataKey.ColumnOrder(this.indexDesc[num])];
                     if (info3 != null)
                     {
                         info3.flag = true;
                     }
                     num++;
                 }
                 num2 = num;
                 for (num = 0; num < length; num++)
                 {
                     if (this.candidateColumns[num] != null)
                     {
                         if (!this.candidateColumns[num].flag)
                         {
                             ndexDesc[num2++] = num;
                         }
                         else
                         {
                             this.candidateColumns[num].flag = false;
                         }
                     }
                 }
                 IndexField[] indexFields = DataTable.zeroIndexField;
                 if (0 < ndexDesc.Length)
                 {
                     indexFields = new IndexField[ndexDesc.Length];
                     for (int j = 0; j < ndexDesc.Length; j++)
                     {
                         DataColumn column = this.table.Columns[DataKey.ColumnOrder(ndexDesc[j])];
                         bool       flag2  = DataKey.SortDecending(ndexDesc[j]);
                         indexFields[j] = new IndexField(column, flag2);
                     }
                 }
                 this.index             = new Index(this.table, ndexDesc, indexFields, this.recordStates, null);
                 this.matchedCandidates = 0;
                 if (this.linearExpression != this.expression)
                 {
                     int[] indexDesc = this.index.IndexDesc;
                     while (this.matchedCandidates < num2)
                     {
                         ColumnInfo info2 = this.candidateColumns[DataKey.ColumnOrder(indexDesc[this.matchedCandidates])];
                         if ((info2 == null) || (info2.expr == null))
                         {
                             break;
                         }
                         this.matchedCandidates++;
                         if (!info2.equalsOperator)
                         {
                             break;
                         }
                     }
                 }
                 for (num = 0; num < this.candidateColumns.Length; num++)
                 {
                     if (this.candidateColumns[num] != null)
                     {
                         this.candidateColumns[num].flag = false;
                     }
                 }
             }
         }
     }
 }