vsop-479 commented on code in PR #15823:
URL: https://github.com/apache/lucene/pull/15823#discussion_r2964463209
##########
lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java:
##########
@@ -174,6 +179,32 @@ public void addAll(Collection<T> elements) {
}
}
+ /**
+ * Similar to {@link #addAll(Collection)}, but supply an {@link
ElementSupplier} to convert origin
+ * element to target element. This is useful when source elements does not
fit target elements.
+ */
+ public <S> void addAll(Collection<S> elements, ElementSupplier<T, S>
elementSupplier) {
Review Comment:
I use Guava's `Iterables` implemented it, it works too (transform in
iterating). Here is the code(haven't committed):
````
public <S> void addAll(
Collection<S> elements, com.google.common.base.Function<S, T>
elementConverter) {
if (this.size + elements.size() > this.maxSize) {
throw new ArrayIndexOutOfBoundsException(
"Cannot add "
+ elements.size()
+ " elements to a queue with remaining capacity: "
+ (maxSize - size));
}
Iterable<T> transform = Iterables.transform(elements, elementConverter);
// Heap with size S always takes first S elements of the array,
// and thus it's safe to fill array further - no actual non-sentinel
value will be overwritten.
for (T element : transform) {
this.heap[size + 1] = element;
this.size++;
}
// The loop goes down to 1 as heap is 1-based not 0-based.
for (int i = (size >>> 1); i >= 1; i--) {
downHeap(i);
}
}
````
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]