private Tuple <int, int> TranslateClosestForwardWithoutMidpoints(ReaderWorkItem workItem, int pos, int startIndex, int endIndex) { PosMap res = ReadPosMap(workItem, endIndex); if (pos > res.LogPos) { return(Tuple.Create(_actualDataSize, endIndex + 1)); // to allow backward reading of the last record, forward read will decline anyway } int low = startIndex; int high = endIndex; while (low < high) { var mid = low + (high - low) / 2; var v = ReadPosMap(workItem, mid); if (v.LogPos < pos) { low = mid + 1; } else { high = mid; res = v; } } return(Tuple.Create(res.ActualPos, high)); }
// private int TranslateClosestWithMidpoints(ReaderWorkItem workItem, Midpoint[] midpoints, int prevPos) // { // if (prevPos < midpoints[0].LogPos || prevPos >= midpoints[midpoints.Length - 1].LogPos) // return -1; // // var recordRange = LocateClosestPosRange(midpoints, prevPos); // return TranslateClosestWithoutMidpoints(workItem, prevPos, recordRange.Item1, recordRange.Item2); // } private Tuple <PosMap, int> TranslateSameOrClosestWithoutMidpoints(ReaderWorkItem workItem, int pos, int startIndex, int endIndex) { PosMap res = ReadPosMap(workItem, endIndex); if (pos > res.LogPos) { return(Tuple.Create(new PosMap(-1, -1), -1)); } int low = startIndex; int high = endIndex; while (low < high) { var mid = low + (high - low) / 2; var v = ReadPosMap(workItem, mid); if (v.LogPos < pos) { low = mid + 1; } else { high = mid; res = v; } } return(Tuple.Create(res, high)); }
public Midpoint(int itemIndex, PosMap posmap) { ItemIndex = itemIndex; LogPos = posmap.LogPos; }