Skip to content

Commit 8096610

Browse files
committed
Do the same for joins
1 parent 58b61ad commit 8096610

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public final void updateLeft(LeftTuple_ leftTuple) {
8484
} else {
8585
indexerLeft.remove(oldIndexKeys, leftTuple);
8686
IndexedSet<OutTuple_> outTupleSetLeft = leftTuple.getStore(inputStoreIndexLeftOutTupleSet);
87-
outTupleSetLeft.forEach(this::retractOutTuple);
87+
outTupleSetLeft.clear(this::retractOutTupleByLeft);
8888
// outTupleSetLeft is now empty, no need for leftTuple.setStore(...);
8989
indexAndPropagateLeft(leftTuple, newIndexKeys);
9090
}
@@ -105,7 +105,7 @@ public final void retractLeft(LeftTuple_ leftTuple) {
105105
}
106106
IndexedSet<OutTuple_> outTupleSetLeft = leftTuple.removeStore(inputStoreIndexLeftOutTupleSet);
107107
indexerLeft.remove(indexKeys, leftTuple);
108-
outTupleSetLeft.forEach(this::retractOutTuple);
108+
outTupleSetLeft.clear(this::retractOutTupleByLeft);
109109
}
110110

111111
@Override
@@ -137,7 +137,7 @@ public final void updateRight(UniTuple<Right_> rightTuple) {
137137
} else {
138138
IndexedSet<OutTuple_> outTupleSetRight = rightTuple.getStore(inputStoreIndexRightOutTupleSet);
139139
indexerRight.remove(oldIndexKeys, rightTuple);
140-
outTupleSetRight.forEach(this::retractOutTuple);
140+
outTupleSetRight.clear(this::retractOutTupleByRight);
141141
// outTupleSetRight is now empty, no need for rightTuple.setStore(...);
142142
indexAndPropagateRight(rightTuple, newIndexKeys);
143143
}
@@ -158,7 +158,7 @@ public final void retractRight(UniTuple<Right_> rightTuple) {
158158
}
159159
IndexedSet<OutTuple_> outTupleSetRight = rightTuple.removeStore(inputStoreIndexRightOutTupleSet);
160160
indexerRight.remove(indexKeys, rightTuple);
161-
outTupleSetRight.forEach(this::retractOutTuple);
161+
outTupleSetRight.clear(this::retractOutTupleByRight);
162162
}
163163

164164
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,14 @@ protected final void innerUpdateRight(UniTuple<Right_> rightTuple, Consumer<Cons
184184
}
185185
}
186186

187-
protected final void retractOutTuple(OutTuple_ outTuple) {
188-
IndexedSet<OutTuple_> outSetLeft = outTuple.removeStore(outputStoreIndexLeftOutSet);
189-
outSetLeft.remove(outTuple);
187+
protected final void retractOutTupleByLeft(OutTuple_ outTuple) {
188+
outTuple.removeStore(outputStoreIndexLeftOutSet);
190189
IndexedSet<OutTuple_> outSetRight = outTuple.removeStore(outputStoreIndexRightOutSet);
191190
outSetRight.remove(outTuple);
191+
retractOutTuple(outTuple);
192+
}
193+
194+
private void retractOutTuple(OutTuple_ outTuple) {
192195
var state = outTuple.state;
193196
if (!state.isActive()) { // Impossible because they shouldn't linger in the indexes.
194197
throw new IllegalStateException("Impossible state: The tuple (%s) in node (%s) is in an unexpected state (%s)."
@@ -197,6 +200,13 @@ protected final void retractOutTuple(OutTuple_ outTuple) {
197200
propagationQueue.retract(outTuple, state == TupleState.CREATING ? TupleState.ABORTING : TupleState.DYING);
198201
}
199202

203+
protected final void retractOutTupleByRight(OutTuple_ outTuple) {
204+
IndexedSet<OutTuple_> outSetLeft = outTuple.removeStore(outputStoreIndexLeftOutSet);
205+
outSetLeft.remove(outTuple);
206+
outTuple.removeStore(outputStoreIndexRightOutSet);
207+
retractOutTuple(outTuple);
208+
}
209+
200210
@Override
201211
public Propagator getPropagator() {
202212
return propagationQueue;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public final void retractLeft(LeftTuple_ leftTuple) {
7171
}
7272
IndexedSet<OutTuple_> outTupleSetLeft = leftTuple.removeStore(inputStoreIndexLeftOutTupleSet);
7373
leftTupleSet.remove(leftTuple);
74-
outTupleSetLeft.forEach(this::retractOutTuple);
74+
outTupleSetLeft.clear(this::retractOutTupleByLeft);
7575
}
7676

7777
@Override
@@ -105,7 +105,7 @@ public final void retractRight(UniTuple<Right_> rightTuple) {
105105
}
106106
IndexedSet<OutTuple_> outTupleSetRight = rightTuple.removeStore(inputStoreIndexRightOutTupleSet);
107107
rightTupleSet.remove(rightTuple);
108-
outTupleSetRight.forEach(this::retractOutTuple);
108+
outTupleSetRight.clear(this::retractOutTupleByRight);
109109
}
110110

111111
}

0 commit comments

Comments
 (0)