@@ -70,8 +70,24 @@ private void init() {
7070 }
7171
7272
73- public void propagate (AndActivation act ) {
74- apply (act );
73+ @ Override
74+ protected void propagate (AndActivation act ) {
75+ if (andChildren != null ) {
76+ for (Link fl : act .inputs ) {
77+ if (fl == null ) continue ;
78+
79+ NodeActivation <?> pAct = fl .input ;
80+
81+ for (Link sl : pAct .outputsToAndNode .values ()) {
82+ NodeActivation secondAct = sl .output ;
83+ if (act != secondAct ) {
84+ applyIntern (act , fl .refAct , fl .ref , fl .rv , secondAct , sl .refAct , sl .ref , sl .rv );
85+ }
86+ }
87+ }
88+ }
89+
90+ propagateToOrNode (act );
7591 }
7692
7793
@@ -95,26 +111,6 @@ void processActivation(AndActivation act) {
95111 }
96112
97113
98- @ Override
99- void apply (AndActivation act ) {
100- if (andChildren != null ) {
101- for (Link fl : act .inputs ) {
102- if (fl == null ) continue ;
103-
104- NodeActivation <?> pAct = fl .input ;
105-
106- for (Link sl : pAct .outputsToAndNode .values ()) {
107- NodeActivation secondAct = sl .output ;
108- if (act != secondAct ) {
109- applyIntern (act , fl .refAct , fl .ref , fl .rv , secondAct , sl .refAct , sl .ref , sl .rv );
110- }
111- }
112- }
113- }
114-
115- OrNode .processCandidate (this , act , false );
116- }
117-
118114
119115 private void applyIntern (AndActivation act , InputActivation refAct , Refinement ref , RefValue rv , NodeActivation secondAct , InputActivation secondRefAct , Refinement secondRef , RefValue secondRv ) {
120116 Document doc = act .getDocument ();
@@ -159,7 +155,7 @@ private AndActivation lookupAndActivation(NodeActivation<?> input, Refinement re
159155 }
160156
161157
162- public RefValue extend (int threadId , Document doc , Refinement firstRef ) {
158+ RefValue expand (int threadId , Document doc , Refinement firstRef ) {
163159 if (!firstRef .isConvertible ()) return null ;
164160
165161 RefValue firstRV = getAndChild (firstRef );
@@ -178,45 +174,17 @@ public RefValue extend(int threadId, Document doc, Refinement firstRef) {
178174 for (Entry firstParent : parents ) {
179175 Node parentNode = firstParent .rv .parent .get (doc );
180176
181- Relation [] secondParentRelations = new Relation [firstRef .relations .length () - 1 ];
182- for (int i = 0 ; i < firstRef .relations .length (); i ++) {
183- Integer j = firstParent .rv .reverseOffsets [i ];
184- if (j != null ) {
185- secondParentRelations [j ] = firstRef .relations .get (i );
186- }
187- }
188-
189- Refinement secondParentRef = new Refinement (new RelationsMap (secondParentRelations ), firstRef .input );
190-
191- RefValue secondParentRV = parentNode .extend (threadId , doc , secondParentRef );
177+ Refinement secondParentRef = new Refinement (getParentRelations (firstRef , firstParent ), firstRef .input );
178+ RefValue secondParentRV = parentNode .expand (threadId , doc , secondParentRef );
192179
193180 if (secondParentRV == null ) {
194181 continue ;
195182 }
196183
197- Relation [] secondRelations = new Relation [firstParent .ref .relations .length () + 1 ];
198- for (int i = 0 ; i < firstParent .ref .relations .length (); i ++) {
199- int j = secondParentRV .offsets [i ];
200- secondRelations [j ] = firstParent .ref .relations .get (i );
201- }
202-
203- Relation rel = firstRef .relations .get (firstParent .rv .refOffset );
204- if (rel != null ) {
205- secondRelations [secondParentRV .refOffset ] = rel .invert ();
206- }
207-
208- Refinement secondRef = new Refinement (new RelationsMap (secondRelations ), firstParent .ref .input );
209-
210- Integer [] secondOffsets = new Integer [secondParentRV .offsets .length + 1 ];
211- for (int i = 0 ; i < firstParent .rv .reverseOffsets .length ; i ++) {
212- Integer j = firstParent .rv .reverseOffsets [i ];
213- if (j != null ) {
214- secondOffsets [secondParentRV .offsets [j ]] = i ;
215- }
216- }
217- secondOffsets [secondParentRV .refOffset ] = firstRefOffset ;
184+ Refinement secondRef = new Refinement (getRelations (firstRef , firstParent , secondParentRV ), firstParent .ref .input );
185+ RefValue secondRV = new RefValue (getOffsets (firstRefOffset , firstParent , secondParentRV ), firstOffsets [firstParent .rv .refOffset ], secondParentRV .child );
218186
219- nextLevelParents .add (new Entry (secondRef , new RefValue ( secondOffsets , firstOffsets [ firstParent . rv . refOffset ], secondParentRV . child ) ));
187+ nextLevelParents .add (new Entry (secondRef , secondRV ));
220188 }
221189
222190 firstRV = new RefValue (firstOffsets , firstRefOffset , provider );
@@ -226,6 +194,45 @@ public RefValue extend(int threadId, Document doc, Refinement firstRef) {
226194 }
227195
228196
197+ private RelationsMap getParentRelations (Refinement firstRef , Entry firstParent ) {
198+ Relation [] secondParentRelations = new Relation [firstRef .relations .length () - 1 ];
199+ for (int i = 0 ; i < firstRef .relations .length (); i ++) {
200+ Integer j = firstParent .rv .reverseOffsets [i ];
201+ if (j != null ) {
202+ secondParentRelations [j ] = firstRef .relations .get (i );
203+ }
204+ }
205+ return new RelationsMap (secondParentRelations );
206+ }
207+
208+
209+ private static RelationsMap getRelations (Refinement firstRef , Entry firstParent , RefValue secondParentRV ) {
210+ Relation [] secondRelations = new Relation [firstParent .ref .relations .length () + 1 ];
211+ for (int i = 0 ; i < firstParent .ref .relations .length (); i ++) {
212+ int j = secondParentRV .offsets [i ];
213+ secondRelations [j ] = firstParent .ref .relations .get (i );
214+ }
215+
216+ Relation rel = firstRef .relations .get (firstParent .rv .refOffset );
217+ if (rel != null ) {
218+ secondRelations [secondParentRV .refOffset ] = rel .invert ();
219+ }
220+ return new RelationsMap (secondRelations );
221+ }
222+
223+
224+ private static Integer [] getOffsets (int firstRefOffset , Entry firstParent , RefValue secondParentRV ) {
225+ Integer [] secondOffsets = new Integer [secondParentRV .offsets .length + 1 ];
226+ for (int i = 0 ; i < firstParent .rv .reverseOffsets .length ; i ++) {
227+ Integer j = firstParent .rv .reverseOffsets [i ];
228+ if (j != null ) {
229+ secondOffsets [secondParentRV .offsets [j ]] = i ;
230+ }
231+ }
232+ secondOffsets [secondParentRV .refOffset ] = firstRefOffset ;
233+ return secondOffsets ;
234+ }
235+
229236
230237 static boolean createAndNode (Model m , Document doc , List <Entry > parents , int level ) {
231238 if (parents != null ) {
0 commit comments