Beispiel #1
0
        void JoinJudgeThreadProc(object par)
        {
            JoinJudgeThreadObject p = (JoinJudgeThreadObject)par;
            int   start             = -1;
            int   end      = -1;
            Table another  = p.another;
            Table newtable = p.newtable;
            List <List <Element> > correspondA = p.correspondA;
            List <List <Element> > correspondB = p.correspondB;
            List <dint>            range       = p.range;
            int c   = another.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;
            }
            int i   = start;
            int low = 0;

            while (i <= end)
            {
                int s, e;
                s = i;
                e = i;
                while (e <= end - 1 && Equal(correspondB[s], correspondB[e + 1]) > 0)
                {
                    e++;
                }
                int pos = BinSearch(correspondA, correspondB[i], low);
                if (pos == -1)//no match
                {
                    i = e + 1;
                    continue;
                }
                else//match
                {
                    int s1, e1;
                    s1 = range[pos].a;
                    e1 = range[pos].b;
                    for (int j = s1; j <= e1; j++)      //this
                    {
                        for (int ii = s; ii <= e; ii++) //another
                        {
                            List <long> row = new List <long>();
                            row.AddRange(this.cellIds[j]);
                            row.AddRange(another.cellIds[ii]);
                            newtable.cellIds.Add(row);
                        }
                    }
                    i   = e + 1;
                    low = e1 + 1;
                }
            }
        }
Beispiel #2
0
        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);
        }