Пример #1
0
        private void EntriesInsert(int pos, NdxEntry newEntry)
        {
#if DEBUG
            var   ndxFile  = (NdxFile)mHolder.mFile;
            int[] cmpArray = new int[ndxFile.mSortFieldsCount];
            int   cmp;
            if (pos > 0)
            {
                NdxEntry previousEntry = GetEntry(pos - 1);
                cmp = newEntry.ChainCompare(cmpArray, ndxFile, previousEntry);
                if (cmp < 0)
                {
                    Dump("NdxPage.EntriesInsert:", "");
                    System.Diagnostics.Debug.Assert(false, "Node should be bigger than previous node.");
                }
            }
            if (pos < mEntries.Count)
            {
                NdxEntry nextEntry = GetEntry(pos);
                cmp = newEntry.ChainCompare(cmpArray, ndxFile, nextEntry);
                if (cmp > 0)
                {
                    Dump("NdxPage.EntriesInsert:", "");
                    System.Diagnostics.Debug.Assert(false, "Node should be less than previous node.");
                }
            }
#endif
            mEntries.Insert(pos, newEntry);
#if DUMP_INSERTS
            System.Diagnostics.Trace.WriteLine("Entries.Insert @" + pos + ":" + newEntry.Fields.ToString() + " #" + newEntry.DbfRecordNo
                                               + " in page #" + this.RecordNo);
            Dump("      ");
#endif
        }
Пример #2
0
        private void FindPos(NdxEntry newEntry, NdxFile ndxFile, out bool equal, out int pos)
        {
            int min = 0;
            int max = EntriesCount - 1;

            int[] cmpArray = new int[ndxFile.mSortFieldsCount];
#if DUMP_INSERTS
            System.Diagnostics.Trace.WriteLine("Searching entry '" + newEntry.Fields.ToString() + " #" + newEntry.DbfRecordNo + "' position in page #" + this.RecordNo);
            Dump("      ");
#endif

            while (max >= min)
            {
                int      mid   = (min + max) / 2;
                NdxEntry other = GetEntry(mid);
                int      cmp   = newEntry.ChainCompare(cmpArray, ndxFile, other);
                if (cmp > 0)
                {
                    min = mid + 1;
                }
                else if (cmp < 0)
                {
                    max = mid - 1;
                }
                else
                {
                    equal = true;
                    pos   = mid;
                    return;
                }
            }
#if DUMP_INSERTS
            System.Diagnostics.Trace.WriteLine("   Result:" + min);
#endif
            equal = false;
            pos   = min;
        }