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); }
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; }
private int FindInsertPos(NdxEntry newEntry, NdxFile ndxFile) { int pos; bool equal; FindPos(newEntry, ndxFile, out equal, out pos); if (equal) throw new Exception("Duplicated entries in the Index file."); return pos; }