Exemplo n.º 1
0
        internal void LocateAndInsert(NdxEntry newEntry)
        {
            var ndxFile     = (NdxFile)mHolder.mFile;
            int originalPos = FindInsertPos(newEntry, ndxFile);
            int pos         = originalPos;

            if (pos == EntriesCount)
            {
                pos--;
            }

            bool hasLowerPage = (pos >= 0 && GetEntry(pos).LowerPageRecordNo != UInt32.MaxValue);

            if (hasLowerPage)
            {
                var ndxPage2 = ndxFile.InternalGetPage(this,
                                                       GetEntry(pos).LowerPageRecordNo,
                                                       /* returnNullIfNotInCache */ false) as NdxPage;
                ndxPage2.LocateAndInsert(newEntry);
            }
            else
            {
                InsertInThisPage(newEntry, originalPos);
            }
        }
Exemplo n.º 2
0
        private void SetEntry(int pos, NdxEntry newEntry)
        {
#if DUMP_INSERTS
            System.Diagnostics.Trace.WriteLine("Setting entry #" + pos + ":" + newEntry.Fields.ToString() + " #" + newEntry.DbfRecordNo + " in page #" + this.RecordNo);
#endif
            mEntries[pos] = newEntry;
        }
Exemplo n.º 3
0
        internal void OnReadRecord(byte[] buffer)
        {
            var ndxFile = (NdxFile)mHolder.mFile;

#if DUMP_READ_RECORD
            System.Diagnostics.Trace.WriteLine("NdxPage.OnReadRecord Page#" + this.RecordNo);
            System.Diagnostics.Trace.WriteLine(Utils.HexDump(buffer));
#endif
            EntriesClear();
            int    nbEntries    = BitConverter.ToInt32(buffer, 0);
            int    pos          = 4;
            Byte[] fieldsBuffer = ndxFile.mSortFieldsReadBuffer;
            for (int i = 0; i < nbEntries; i++)
            {
                var ndxEntry = new NdxEntry();
                ndxEntry.mNdxNativeLowerPageNo = BitConverter.ToUInt32(buffer, pos);
                pos += 4;
                ndxEntry.DbfRecordNo = BitConverter.ToUInt32(buffer, pos);
                pos += 4;
                object fields = ndxFile.mSortFieldsConstructor.Invoke(null);
                Array.Copy(buffer, pos, fieldsBuffer, 0, fieldsBuffer.Length);
                ndxFile.mSortFieldsWriter.mQuickReadMethod(ndxFile, fieldsBuffer, fields);
                pos            += fieldsBuffer.Length;
                ndxEntry.Fields = (SortFields)fields;
#if DUMP_READ_RECORD
                System.Diagnostics.Trace.WriteLine("  Entry " + i + " (Page #" + this.RecordNo + ") " + fields.ToString() + " " + ndxEntry.Fields.ToString() + " " + ndxEntry.DbfRecordNo);
#endif

                EntriesInsert(i, ndxEntry);
            }
        }
Exemplo n.º 4
0
        internal void Dump()
        {
            System.Diagnostics.Debug.WriteLine("-- Dump index:" + this.mOriginalFile + "------------------------");
            System.Diagnostics.Debug.WriteLine("Root: " + this.mNdxHeader.StartingPageRecordNo);

            System.Diagnostics.Debug.WriteLine(this.mRecordCount + " records");

            NdxPage  page     = InternalGetPage((NdxPage)null, (uint)this.mNdxHeader.StartingPageRecordNo, false);
            NdxEntry lastNode = null;

            page.Dump("", null, null, true, ref lastNode);
            System.Diagnostics.Debug.WriteLine("-----------------------------------------------------------------------------------");
        }
Exemplo n.º 5
0
        private void InsertInThisPage(NdxEntry newEntry, int pos)
        {
#if DUMP_INSERTS
            working++;
            System.Diagnostics.Trace.WriteLine("Inserting entry " + newEntry.Fields.ToString() + " #" + newEntry.DbfRecordNo + " in page #" + this.RecordNo);
#endif
            System.Diagnostics.Debug.Assert(this.RecordNo != UInt32.MaxValue, "RecordNo should be set.");
            var ndxFile = (NdxFile)mHolder.mFile;
            // find the
            EntriesInsert(pos, newEntry);

            if (pos == EntriesCount - 1) // we inserted in the last entry
            {
                PropagateLastEntryChanged(newEntry);
            }
            if (EntriesCount > ndxFile.mNdxHeader.NoOfKeysPerPage)
            {
                SplitPage();
            }
            mIsModified = true;
        }
Exemplo n.º 6
0
        private void DeleteInThisPage(NdxEntry newEntry, int pos)
        {
#if DUMP_INSERTS
            working++;
            System.Diagnostics.Trace.WriteLine("Inserting entry " + newEntry.Fields.ToString() + " #" + newEntry.DbfRecordNo + " in page #" + this.RecordNo);
#endif
            System.Diagnostics.Debug.Assert(this.RecordNo != UInt32.MaxValue, "RecordNo should be set.");
            var ndxFile = (NdxFile)mHolder.mFile;
            // find the
            EntriesRemove(pos);

            if (EntriesCount == 0)
            {
                Utils.Nop();
            }
            else if (pos == EntriesCount) // we delete the last entry
            {
                var lastEntry = GetEntry(pos - 1);
                PropagateLastEntryChanged(lastEntry);
            }
            mIsModified = true;
        }
Exemplo n.º 7
0
 public int ChainCompare(int[] cmp, NdxFile index, NdxEntry other)
 {
     this.Fields.ChainCompare(other.Fields, cmp);
     // to do check for ascending descending
     for (int i = 0; i < cmp.Length; i++)
     {
         if (cmp[i] != 0)
         {
             return(cmp[i]);
         }
     }
     // if we're here the fields are identical
     // we compare RecordNo when the index is NOT unique
     if (index.mNdxHeader.UniqueFlag)
     {
         return(0);
     }
     else
     {
         return(DbfRecordNo.CompareTo(other.DbfRecordNo));
     }
 }