jpountz commented on code in PR #14273: URL: https://github.com/apache/lucene/pull/14273#discussion_r2017544601
########## lucene/core/src/java/org/apache/lucene/search/DocIdStream.java: ########## @@ -34,12 +33,34 @@ protected DocIdStream() {} * Iterate over doc IDs contained in this stream in order, calling the given {@link * CheckedIntConsumer} on them. This is a terminal operation. */ - public abstract void forEach(CheckedIntConsumer<IOException> consumer) throws IOException; + public void forEach(CheckedIntConsumer<IOException> consumer) throws IOException { + forEach(DocIdSetIterator.NO_MORE_DOCS, consumer); + } + + /** + * Iterate over doc IDs contained in this doc ID stream up to the given {@code upTo} exclusive, + * calling the given {@link CheckedIntConsumer} on them. It is not possible to iterate these doc + * IDs again later on. + */ + public abstract void forEach(int upTo, CheckedIntConsumer<IOException> consumer) + throws IOException; /** Count the number of entries in this stream. This is a terminal operation. */ public int count() throws IOException { - int[] count = new int[1]; - forEach(_ -> count[0]++); - return count[0]; + return count(DocIdSetIterator.NO_MORE_DOCS); } + + /** + * Count the number of doc IDs in this stream that are below the given {@code upTo}. These doc IDs + * may not be consumed again later. + */ + // Note: it's abstract rather than having a default impl that delegates to #forEach because doing Review Comment: Ah right, it was based on your previous feedback. :) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org