Skip to content

Commit bd4f47e

Browse files
committed
Experiment with a different approach
1 parent 29e6a54 commit bd4f47e

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

core/src/main/java/ai/timefold/solver/core/impl/bavet/common/AbstractJoinNode.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,7 @@ private void processOutTupleUpdate(LeftTuple_ leftTuple, UniTuple<Right_> rightT
169169
private static <Tuple_ extends AbstractTuple> @Nullable Tuple_ findOutTuple(IndexedSet<Tuple_> outTupleSet,
170170
IndexedSet<Tuple_> referenceOutTupleSet, int outputStoreIndexOutSet) {
171171
// Hack: the outTuple has no left/right input tuple reference, use the left/right outSet reference instead.
172-
var list = outTupleSet.asList();
173-
for (var i = 0; i < list.size(); i++) { // Avoid allocating iterators.
174-
var outTuple = list.get(i);
175-
if (referenceOutTupleSet == outTuple.getStore(outputStoreIndexOutSet)) {
176-
return outTuple;
177-
}
178-
}
179-
return null;
172+
return outTupleSet.findFirst(outTuple -> referenceOutTupleSet == outTuple.getStore(outputStoreIndexOutSet));
180173
}
181174

182175
protected final void retractOutTuple(OutTuple_ outTuple) {

core/src/main/java/ai/timefold/solver/core/impl/bavet/common/index/IndexedSet.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.List;
1111
import java.util.Objects;
1212
import java.util.function.Consumer;
13+
import java.util.function.Predicate;
1314

1415
/**
1516
* {@link ArrayList}-backed set which allows to {@link #remove(Object)} an element
@@ -139,6 +140,19 @@ public void forEach(Consumer<T> tupleConsumer) {
139140
}
140141
}
141142

143+
public @Nullable T findFirst(Predicate<T> tupleConsumer) {
144+
if (elementList == null) {
145+
return null;
146+
}
147+
for (var i = 0; i < elementList.size(); i++) {
148+
var element = elementList.get(i);
149+
if (element != null && tupleConsumer.test(element)) {
150+
return element;
151+
}
152+
}
153+
return null;
154+
}
155+
142156
public boolean isEmpty() {
143157
return size() == 0;
144158
}

0 commit comments

Comments
 (0)