示例#1
0
文件: Table.cs 项目: zoukaifa/TriSQL
        void JoinThreadProc(object par)
        {
            JoinThreadObject p = (JoinThreadObject)par;
            int   start        = -1;
            int   end          = -1;
            Table another      = p.another;
            Table newtable     = p.newtable;
            int   c            = this.cellIds.Count;
            int   ele          = c / p.threadCount;

            if (p.threadCount != p.threadIndex + 1)
            {
                start = p.threadIndex * ele;
                end   = start + ele - 1;
            }
            else
            {
                start = p.threadIndex * ele;
                end   = c - 1;
            }


            for (int i = start; i <= end; i++)
            {
                foreach (var a in another.cellIds)
                {
                    List <long> row = new List <long>();
                    row.AddRange(cellIds[i]);
                    row.AddRange(a);
                    newtable.cellIds.Add(row);
                }
            }
        }
示例#2
0
文件: Table.cs 项目: zoukaifa/TriSQL
        public Table innerJoin(Table anotherTable, List <dint> cond = null, bool isLocal = true)
        {
            //first
            //cellids columnNames columntypes
            Table newtable = new Table();

            if (isLocal)
            {
                foreach (var a in this.columnNames)
                {
                    newtable.columnNames.Add(tableNames[0] + "." + a);
                }
                foreach (var a in this.columnTypes)
                {
                    newtable.columnTypes.Add(a);
                }
                foreach (var a in anotherTable.columnNames)
                {
                    newtable.columnNames.Add(anotherTable.tableNames[0] + "." + a);
                }
                foreach (var a in anotherTable.columnTypes)
                {
                    newtable.columnTypes.Add(a);
                }
                newtable.tableNames.Add(this.tableNames[0] + anotherTable.tableNames[0]);
            }
            //process
            if (cond == null)//使用默认条件,名字相同
            {
                cond = calcond(anotherTable.columnNames);
            }
            if (cond.Count != 0)//使用自定义条件
            {
                List <int> conda = new List <int>();
                List <int> condb = new List <int>();
                foreach (var a in cond)
                {
                    conda.Add(a.a);
                    condb.Add(a.b);
                }
                List <List <Element> > correspondA = getCorrespon(conda, this.cellIds);
                List <List <Element> > correspondB = getCorrespon(condb, anotherTable.cellIds);

                QuickSort(correspondA, 0, correspondA.Count - 1, this.cellIds);
                QuickSort(correspondB, 0, correspondB.Count - 1, anotherTable.cellIds);

                int         threadCount = Environment.ProcessorCount;
                Thread[]    threadNum   = new Thread[threadCount];
                List <dint> range       = distinct(correspondA);//get the range
                for (int threadIndex = 0; threadIndex < threadCount; threadIndex++)
                {
                    JoinJudgeThreadObject p = new JoinJudgeThreadObject(threadCount, threadIndex, anotherTable, newtable, correspondA, correspondB, range);
                    threadNum[threadIndex] = new Thread(JoinJudgeThreadProc);
                    threadNum[threadIndex].Start(p);
                }
                for (int inde = 0; inde < threadCount; inde++)
                {
                    threadNum[inde].Join();
                }
            }
            else//使用恒true条件
            {
                int      threadCount = Environment.ProcessorCount;
                Thread[] threadNum   = new Thread[threadCount];

                for (int threadIndex = 0; threadIndex < threadCount; threadIndex++)
                {
                    JoinThreadObject p = new JoinThreadObject(threadCount, threadIndex, anotherTable, newtable);
                    threadNum[threadIndex] = new Thread(JoinThreadProc);
                    threadNum[threadIndex].Start(p);
                }
                for (int inde = 0; inde < threadCount; inde++)
                {
                    threadNum[inde].Join();
                }
            }
            return(newtable);
        }