internal virtual int ForwardBinarySearch(int target) { // advance forward and double the window at each step int indexSize = (int)DocIDs.Size(); int lo = Math.Max(BlockIdx / IndexInterval, 0), hi = lo + 1; Debug.Assert(BlockIdx == -1 || DocIDs.Get(lo) <= DocID_Renamed); Debug.Assert(lo + 1 == DocIDs.Size() || DocIDs.Get(lo + 1) > DocID_Renamed); while (true) { if (hi >= indexSize) { hi = indexSize - 1; break; } else if (DocIDs.Get(hi) >= target) { break; } int newLo = hi; hi += (hi - lo) << 1; lo = newLo; } // we found a window containing our target, let's binary search now while (lo <= hi) { int mid = (int)((uint)(lo + hi) >> 1); int midDocID = (int)DocIDs.Get(mid); if (midDocID <= target) { lo = mid + 1; } else { hi = mid - 1; } } Debug.Assert(DocIDs.Get(hi) <= target); Debug.Assert(hi + 1 == DocIDs.Size() || DocIDs.Get(hi + 1) > target); return(hi); }
public static DocMap Build(int maxDoc, Bits liveDocs) { Debug.Assert(liveDocs != null); MonotonicAppendingLongBuffer docMap = new MonotonicAppendingLongBuffer(); int del = 0; for (int i = 0; i < maxDoc; ++i) { docMap.Add(i - del); if (!liveDocs.Get(i)) { ++del; } } docMap.Freeze(); int numDeletedDocs = del; Debug.Assert(docMap.Size() == maxDoc); return(new DocMapAnonymousInnerClassHelper(maxDoc, liveDocs, docMap, numDeletedDocs)); }
public static DocMap Build(int maxDoc, Bits liveDocs) { Debug.Assert(liveDocs != null); MonotonicAppendingLongBuffer docMap = new MonotonicAppendingLongBuffer(); int del = 0; for (int i = 0; i < maxDoc; ++i) { docMap.Add(i - del); if (!liveDocs.Get(i)) { ++del; } } docMap.Freeze(); int numDeletedDocs = del; Debug.Assert(docMap.Size() == maxDoc); return new DocMapAnonymousInnerClassHelper(maxDoc, liveDocs, docMap, numDeletedDocs); }