private static void Merge(Page A, Page B, RecordMatcher Comparer) { List <Record> x = new List <Record>(); int ptrA = 0, ptrB = 0; while (ptrA < A.Count && ptrB < B.Count) { if (Comparer.Compare(A.Cache[ptrA], B.Cache[ptrB]) < 0) { x.Add(A.Cache[ptrA]); ptrA++; } else { x.Add(B.Cache[ptrB]); ptrB++; } } while (ptrA < A.Count) { x.Add(A.Cache[ptrA]); ptrA++; } while (ptrB < B.Count) { x.Add(B.Cache[ptrB]); ptrB++; } A.Cache = x.GetRange(0, A.Count); B.Cache = x.GetRange(A.Count, B.Count); }
// Distinct Support // public static void Distinct(Table Element, RecordWriter Writer, RecordMatcher Comparer) { // Check if the table is a heap // if (!(Element is HeapTable)) { throw new Exception("Can only sort a HeapTable"); } if (Element.Header.IndexHeaders.Count != 0) { throw new Exception("Can not sort a table with indexes"); } // Step 1: sort table // Sort(Element, Comparer); // Step 2: create a shell // //Table t = Element.Host.CreateTempTable(Element.Columns); // Step 3: open a reader // RecordReader rr = Element.OpenReader(); // Step 4: write to the shell // Record lag = null; while (rr.CanAdvance) { Record current = rr.ReadNext(); if (lag == null) { Writer.Insert(current); } else if (Comparer.Compare(lag, current) != 0) { Writer.Insert(current); } lag = current; } }