Skip to content

Commit a6d1776

Browse files
committed
'minor'
1 parent 97643dd commit a6d1776

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

engine/src/main/java/com/github/s4ke/moar/moa/edgegraph/EdgeGraph.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ public final class EdgeGraph {
3636

3737
private boolean frozen = false;
3838

39+
public EdgeGraph copy() {
40+
EdgeGraph edgeGraph = new EdgeGraph();
41+
for ( State state : this.getStates() ) {
42+
edgeGraph.addState( state );
43+
}
44+
for ( State state : this.getStates() ) {
45+
for ( EdgeGraph.Edge edge : this.getEdges( state ) ) {
46+
EdgeGraph.Edge edgeCpy = new EdgeGraph.Edge( new HashSet<>( edge.memoryAction ), edge.destination );
47+
edgeGraph.addEdge( state, edgeCpy );
48+
}
49+
}
50+
return edgeGraph;
51+
}
52+
3953
public void freeze() {
4054
this.frozen = true;
4155
for ( Map.Entry<Integer, Set<Edge>> entry : this.edges.entrySet() ) {
@@ -48,6 +62,7 @@ public void freeze() {
4862
this.boundEdges.put( src, boundEdges );
4963
entry.getValue().forEach(
5064
(edge) -> {
65+
edge.freeze();
5166
State state = this.states.get( edge.destination );
5267
if ( state.isStatic() ) {
5368
//only called for terminals so null is fine
@@ -88,9 +103,13 @@ public Edge(Set<MemoryAction> memoryAction, Integer destination) {
88103
this.destination = destination;
89104
}
90105

91-
public final Set<MemoryAction> memoryAction;
106+
public Set<MemoryAction> memoryAction;
92107
public final Integer destination;
93108

109+
public void freeze() {
110+
this.memoryAction = Collections.unmodifiableSet( this.memoryAction );
111+
}
112+
94113
@Override
95114
public String toString() {
96115
return "Edge{" +

0 commit comments

Comments
 (0)