public class DirectedEdgeGraph implements EdgeGraph {
- public DirectedEdgeGraph() {
- // nodes = Collections.synchronizedSet(new HashSet());
- // nodes = new HashSet();
+ // jjenista - we need this set to find all nodes in a graph
+ // (as hard a problem as keeping a reference to one node that
+ // is in the graph from which to do a traversal and find all
+ // nodes currently in the graph).
+ //
+ // Problem: when you add or remove one node, the obvious update
+ // is to add or remove it to this set as well. That is a conflict
+ // for concurrent add and remove ops that don't collide in terms of
+ // modifying the graph elements though.
+ //
+ // SOLUTION: let add and remove ops to the true graph happen in
+ // parallel, then use a special update method to keep the set of
+ // all nodes maintained. It is up the user to invoke a traversal
+ // of the set of all nodes only at points where the set is valid.
+ protected HashSet nodes;
+
+ // only use when the nodes set is up-to-date
+ public DirectedEdgeGraph() { nodes = new HashSet(); }
+ public Iterator iterator() { return nodes.iterator(); }
+ public int getNumNodes() { return nodes.size(); }
+ public Node getRandom() { return (Node) nodes.iterator().next(); }
+
+ // keep the nodes set up-to-date, but use AFTER...
+ public void addNodeToAllNodesSet( Node n ) {
+ if( !n.inGraph ) {
+ System.out.println( "Error: adding a node NOT IN the graph to the all-nodes set!" );
+ System.exit( -1 );
+ }
+ nodes.add( n );
+ }
+
+ public void removeNodeFromAllNodesSet( Node n ) {
+ if( n.inGraph ) {
+ System.out.println( "Error: removing a node IN the graph to the all-nodes set!" );
+ System.exit( -1 );
+ }
+ nodes.add( n );
+ }
+
+ // these are the normal methods for truly adding and removing nodes
+ // from the graph, nodes know locally if they are in and out but they
+ // haven't been added or removed from the nodes set until ABOVE methods
+ public boolean addNode(Node n) {
+ boolean notInAlready = !n.inGraph;
+ n.inGraph = true;
+ return notInAlready;
+ }
+
+ public boolean removeNode(Node n) {
+ boolean wasIn = n.inGraph;
+ removeConnectingEdges((EdgeGraphNode) n);
+ return wasIn;
}
+ public boolean containsNode(Node n) {
+ return n.inGraph;
+ }
+
+
+
+
+
public boolean addEdge(Edge_d e) {
GraphEdge ge = (GraphEdge) e;
EdgeGraphNode src = ge.getSrc();
return retval;
}
- //public Iterator iterator() {
- // return nodes.iterator();
- //}
-
- public boolean addNode(Node n) {
- boolean notInAlready = !n.inGraph;
- n.inGraph = true;
- return notInAlready;
- }
-
- public boolean containsNode(Node n) {
- return n.inGraph;
- }
-
public Object getNodeData(Node n) {
EdgeGraphNode egn = (EdgeGraphNode) n;
return egn.data;
}
- //public int getNumNodes() {
- // return nodes.size();
- //}
-
- //public Node getRandom() {
- // // return (Node)Sets.getAny(nodes);
- // return (Node) nodes.iterator().next();
- //}
-
public boolean hasNeighbor(Node src, Node dest) {
EdgeGraphNode esrc = (EdgeGraphNode) src;
EdgeGraphNode edest = (EdgeGraphNode) dest;
return esrc.hasOutNeighbor(edest);
}
- public boolean removeNode(Node n) {
- boolean wasIn = n.inGraph;
- removeConnectingEdges((EdgeGraphNode) n);
- return wasIn;
- }
-
protected void removeConnectingEdges(EdgeGraphNode n) {
EdgeGraphNode g;
for (Iterator iterator1 = n.getOutNeighborsCopy(); iterator1.hasNext();) {
public class DirectedGraph implements Graph {
- protected HashSet nodes;
-
+ //protected HashSet nodes;
+
public DirectedGraph() {
// nodes = Collections.synchronizedSet(new HashSet());
- nodes = new HashSet();
+ //nodes = new HashSet();
}
public boolean addNeighbor(Node src, Node dest) {
}
public boolean addNode(Node n) {
- return nodes.add((GraphNode) n);
+ boolean notInAlready = !n.inGraph;
+ n.inGraph = true;
+ return notInAlready;
}
public boolean containsNode(Node n) {
- return nodes.contains(n);
+ n.inGraph;
}
public Node createNode(Object n) {
return ((GraphNode)node).inNeighbors.size();
}
- public int getNumNodes() {
- return nodes.size();
- }
+ //public int getNumNodes() {
+ // return nodes.size();
+ //}
public Iterator getOutNeighbors(Node src) {
GraphNode src_c = (GraphNode) src;
}
public boolean removeNode(Node n) {
+ boolean wasIn = n.inGraph;
removeConnectingEdges((GraphNode) n);
- return nodes.remove(n);
+ return wasIn;
}
protected void removeConnectingEdges(GraphNode n) {
return retval;
}
- public Iterator iterator() {
- return nodes.iterator();
- }
+ //public Iterator iterator() {
+ // return nodes.iterator();
+ //}
public boolean isDirected() {
return true;
}
} else {
- // otherwise we did apply the cavity, but we
- // may have introduced new bad triangles
+ // otherwise we did apply the cavity, so repair the all-nodes set of the mesh
+ Iterator itrPreNodes = cavity.getPre().getNodes().iterator();
+ while( itrPreNodes.hasNext() ) {
+ mesh.removeNodeFromAllNodesSet( (Node)itrPreNodes.next() );
+ }
+ Iterator itrPostNodes = cavity.getPost().getNodes().iterator();
+ while( itrPostNodes.hasNext() ) {
+ mesh.addNodeToAllNodesSet( (Node)itrPostNodes.next() );
+ }
+
+ // and we may have introduced new bad triangles
HashMapIterator it2 = cavity.getPost().newBad(mesh).iterator();
while (it2.hasNext()) {
worklist.push((Node)it2.next());