@@ -13,24 +13,43 @@ public class GraphUtils
1313 /**
1414 * @return the set of root nodes of the given graph.
1515 */
16- public static < V extends Vertex < E >, E extends Edge < V > > RefSet < V > getRoots ( ReadOnlyGraph < V , E > graph )
16+ public static < V extends Vertex < ? > > RefSet < V > getRoots ( ReadOnlyGraph < V , ? > graph )
1717 {
1818 Predicate < V > isRoot = spot -> spot .incomingEdges ().isEmpty ();
1919 return RefCollectionUtils .filterSet ( graph .vertices (), isRoot );
2020 }
2121
22- public static < V extends Vertex < E > & HasTimepoint , E extends Edge < V > > RefSet < V > getRoots ( ReadOnlyGraph < V , E > graph , int timepoint )
23- {
24- Predicate < V > isRoot = spot -> spot .getTimepoint () == timepoint || ( spot .incomingEdges ().isEmpty () && spot .getTimepoint () > timepoint );
25- return RefCollectionUtils .filterSet ( graph .vertices (), isRoot );
26- }
27-
2822 /**
29- * @return true if the given spot is part of a branch that divides.
23+ * Returns the vertices of the graph that would be roots if all vertices with
24+ * {@code vertex.getTimepoint() < timepoint} would be discarded.
3025 */
31- public static boolean doesBranchDivide ( final Spot spot , final Spot ref )
26+ public static < V extends Vertex < E > & HasTimepoint , E extends Edge < V > > RefSet < V > getRootsAfterTimepoint ( ReadOnlyGraph < V , E > graph , int timepoint )
3227 {
33- Spot branchEnd = BranchGraphUtils .getBranchEnd ( spot , ref );
34- return branchEnd .outgoingEdges ().size () > 1 ;
28+ V ref = graph .vertexRef ();
29+ try
30+ {
31+ Predicate < V > isRoot = spot -> {
32+
33+ if ( spot .getTimepoint () < timepoint )
34+ return false ;
35+
36+ if ( spot .incomingEdges ().isEmpty () )
37+ return true ;
38+
39+ for ( E edge : spot .incomingEdges () )
40+ {
41+ V source = edge .getSource ( ref );
42+ if ( source .getTimepoint () >= timepoint )
43+ return false ;
44+ }
45+
46+ return true ;
47+ };
48+ return RefCollectionUtils .filterSet ( graph .vertices (), isRoot );
49+ }
50+ finally
51+ {
52+ graph .releaseRef ( ref );
53+ }
3554 }
3655}
0 commit comments