public NearSpansUnordered(final List<Spans> spans, final int slop) throws IOException { super(spans, slop); queue = new SpansQueue(spans.size()); }
@Override public boolean nextPosition() throws IOException { if (firstTime) { if (!this.initialiseSpansPosition()) { matchStart = matchEnd = PositionsIterator.NO_MORE_POS; return false; } firstTime = false; } else { if (!this.advanceMinToNextPosition()) { matchStart = matchEnd = PositionsIterator.NO_MORE_POS; return false; } } boolean isMatching; do { // while it is not matching, advance the min to the next position, and try again if (!(isMatching = isMatching())) { if (!this.advanceMinToNextPosition()) { matchStart = matchEnd = PositionsIterator.NO_MORE_POS; return false; } } } while (!isMatching); matchStart = queue.top().start(); matchEnd = max.end(); return isMatching; }
/** * Advance the min to its next position, update the total length and the max. */ private boolean advanceMinToNextPosition() throws IOException { // retrieve the min Spans min = queue.top(); // cache length before advancing to the next position int oldLength = min.end() - min.start(); // we advance the min to its next position if (!min.nextPosition()) { return false; } // update total length this.updateTotalLength(oldLength, min.end() - min.start()); // update max reference this.updateMax(min); // update queue queue.updateTop(); return true; }
@Override protected int getSlop() { // retrieve the min Spans min = queue.top(); return (max.end() - min.start()) - totalLength; }