Skip to content
Snippets Groups Projects
Commit e13622c1 authored by Carlos Galindo's avatar Carlos Galindo
Browse files

EdgeList: optimize find loop operation.

- Moved from Work#getTraversedLoop
parent 498f9ea7
No related branches found
No related tags found
No related merge requests found
/*
* EDG, a library to generate and slice Expression Dependence Graphs.
* Copyright (c) 2021-2023. David Insa, Carlos Galindo, Sergio Pérez, Josep Silva, Salvador Tamarit.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package edg.slicing;
import edg.graph.Edge;
......@@ -37,6 +55,24 @@ public class EdgeList implements List<Edge> {
return EMPTY_LIST;
}
/**
* <b>Precondition</b>: the argument must be contained in this list.
*
* @param start The start of the iterable
* @return An iterable from the argument until the end of the list.
*/
public List<Edge> loopIterable(Edge start) {
List<Edge> list = new LinkedList<>();
buildStream(list, start);
return list;
}
private void buildStream(List<Edge> builder, Edge start) {
if (prev != EMPTY_LIST && !start.equals(data))
prev.buildStream(builder, start);
builder.add(data);
}
/* ================================== List interface ============================= */
@Override
......
......@@ -149,9 +149,9 @@ public class OnePassConstrainedAlgorithm implements SlicingAlgorithm
final List<Constraints> newConstraintsList = constraint.resolve(phase, edg, currentEdge, constraintsClone, topConstraint, 0);
for (Constraints newConstraints : newConstraintsList) {
if (traversedEdges.contains(currentEdge)) { // IF WE TRAVERSE THE SAME EDGE TWICE WHILE TRAVERSING FLOW AND VALUE EDGES...
List<Edge> loopEdges = work.getTraversedLoop(currentEdge); // 1) WE EXTRACT THE EDGES OF THE LOOP
boolean isIncreasingLoop = PDA.isIncreasingLoop(loopEdges); // 2) WE CALL THE PDA TO EVALUATE THE LOOP
if (isIncreasingLoop) { // 3) IF THE LOOP IS INCREASING...
List<Edge> loopEdges = traversedEdges.loopIterable(currentEdge); // 1) WE EXTRACT THE EDGES OF THE LOOP
boolean isIncreasingLoop = PDA.isIncreasingLoop(loopEdges); // 2) WE CALL THE PDA TO EVALUATE THE LOOP
if (isIncreasingLoop) { // 3) IF THE LOOP IS INCREASING...
// REMOVE STACK (ASTERISK CONSTRAINT) AND CONTINUE TRAVERSAL ADDING THE EDGE TO traversedEdges
// ACTS AS AN ASTERISK BUT DOES NOT REPLACE THE CONSTRAINT IN THE ARC
// currentEdge.setVisibleConstraint(AsteriskConstraint.getConstraint());
......
......@@ -19,13 +19,9 @@
package edg.work;
import edg.constraint.Constraints;
import edg.graph.Edge;
import edg.graph.Node;
import edg.slicing.EdgeList;
import java.util.LinkedList;
import java.util.List;
public abstract class Work
{
protected final String id;
......@@ -58,18 +54,6 @@ public abstract class Work
return this.traversedEdges;
}
// Returns the sequence of edges that forms a loop
public List<Edge> getTraversedLoop(Edge repeated){
List<Edge> lastLoop = new LinkedList<>();
for (int i = traversedEdges.size()-1; i >= 0; i--){
Edge e = traversedEdges.get(i);
lastLoop.add(0, e);
if (e.equals(repeated))
break;
}
return lastLoop;
}
public boolean equals(Object object) {
return object instanceof Work && this.constraints.equals(((Work) object).constraints);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment