// removes an edge from the graph void removeEdge(Graph *g, Edge *ep) { removeEndpoint(ep->endpoint1); removeEndpoint(ep->endpoint2); // put deleted edge at end of array, decrement numEdges by 1, rehookup // connectors int lastEdgeIndex = --g->numEdges; // if its not the last element, swap it with the last element if(g->edges+lastEdgeIndex != ep){ swap(ep, g->edges+lastEdgeIndex, sizeof(Edge)); ep->endpoint1->adjacentEdge = ep; ep->endpoint2->adjacentEdge = ep; } }
void EndpointState::clearEndpoints(shared_ptr<ConcurrentEndpointMap> m) { list<Identifier> endpoint_names; strict_lock<EndpointState> guard(*this); for (pair<Identifier, shared_ptr<Endpoint>> p: *(m->get(guard))) { endpoint_names.push_back(p.first); } for (Identifier i: endpoint_names) { removeEndpoint(i); } }