Objects: simplify merging iterator even more

no need for the hashmap step of iterator construction
This commit is contained in:
2025-04-03 22:23:23 +02:00
parent 6bcec4a260
commit 4c5cbfb5bf

View File

@@ -5,6 +5,7 @@ import org.apache.commons.lang3.tuple.Pair;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class MergingKvIterator<K extends Comparable<K>, V> extends ReversibleKvIterator<K, V> { public class MergingKvIterator<K extends Comparable<K>, V> extends ReversibleKvIterator<K, V> {
private final NavigableMap<K, CloseableKvIterator<K, V>> _sortedIterators = new TreeMap<>(); private final NavigableMap<K, CloseableKvIterator<K, V>> _sortedIterators = new TreeMap<>();
@@ -15,13 +16,11 @@ public class MergingKvIterator<K extends Comparable<K>, V> extends ReversibleKvI
_goingForward = true; _goingForward = true;
_name = name; _name = name;
int counter = 0; _iterators = Map.ofEntries(
var iteratorsTmp = new HashMap<CloseableKvIterator<K, V>, Integer>(); IntStream.range(0, iterators.size())
for (var iteratorFn : iterators) { .mapToObj(i -> Pair.of(iterators.get(i).get(startType, startKey), i))
var iterator = iteratorFn.get(startType, startKey); .toArray(Pair[]::new)
iteratorsTmp.put(iterator, counter++); );
}
_iterators = Map.copyOf(iteratorsTmp);
if (startType == IteratorStart.LT || startType == IteratorStart.LE) { if (startType == IteratorStart.LT || startType == IteratorStart.LE) {
// Starting at a greatest key less than/less or equal than: // Starting at a greatest key less than/less or equal than: