diff options
Diffstat (limited to 'subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/IntermediateNode.java')
-rw-r--r-- | subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/IntermediateNode.java | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/IntermediateNode.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/IntermediateNode.java index 7165197c..a7486ecb 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/IntermediateNode.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/IntermediateNode.java | |||
@@ -62,19 +62,43 @@ final class IntermediateNode extends DecisionTreeNode { | |||
62 | } | 62 | } |
63 | 63 | ||
64 | @Override | 64 | @Override |
65 | public void overwriteValues(DecisionTreeNode values) { | 65 | protected void doSetIfMissing(int key, int nextLevel, Tuple tuple, TruthValue value) { |
66 | if (values instanceof IntermediateNode intermediateValues) { | 66 | var child = children.get(key); |
67 | otherwise.overwriteValues(intermediateValues.otherwise); | 67 | if (child == null) { |
68 | for (var pair : children.keyValuesView()) { | 68 | var otherwiseReducedValue = getOtherwiseReducedValue(); |
69 | pair.getTwo().overwriteValues(intermediateValues.getChild(pair.getOne())); | 69 | if (otherwiseReducedValue != null && otherwiseReducedValue != DecisionTreeValue.UNSET) { |
70 | } | 70 | // Value already set. |
71 | for (var pair : intermediateValues.children.keyValuesView()) { | 71 | return; |
72 | children.getIfAbsentPut(pair.getOne(), () -> otherwise.withOverwrittenValues(pair.getTwo())); | ||
73 | } | 72 | } |
74 | reduceChildren(); | 73 | var newChild = otherwise.withValueSetIfMissing(nextLevel, tuple, value); |
75 | } else { | 74 | children.put(key, newChild); |
75 | return; | ||
76 | } | ||
77 | child.setIfMissing(nextLevel, tuple, value); | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public void setAllMissing(TruthValue value) { | ||
82 | otherwise.setAllMissing(value); | ||
83 | for (var child : children) { | ||
84 | child.setAllMissing(value); | ||
85 | } | ||
86 | reduceChildren(); | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public void overwriteValues(DecisionTreeNode values) { | ||
91 | if (!(values instanceof IntermediateNode intermediateValues)) { | ||
76 | throw new IllegalArgumentException("Level mismatch"); | 92 | throw new IllegalArgumentException("Level mismatch"); |
77 | } | 93 | } |
94 | otherwise.overwriteValues(intermediateValues.otherwise); | ||
95 | for (var pair : children.keyValuesView()) { | ||
96 | pair.getTwo().overwriteValues(intermediateValues.getChild(pair.getOne())); | ||
97 | } | ||
98 | for (var pair : intermediateValues.children.keyValuesView()) { | ||
99 | children.getIfAbsentPut(pair.getOne(), () -> otherwise.withOverwrittenValues(pair.getTwo())); | ||
100 | } | ||
101 | reduceChildren(); | ||
78 | } | 102 | } |
79 | 103 | ||
80 | private void reduceChildren() { | 104 | private void reduceChildren() { |