typename Paths<NodeType,F>::NodeListType Paths<NodeType,F>::_edgesFrom(NodeType a)const { NodeListType nodeList; for(typename DirectedGraphType::const_iterator i=_graph.begin();i!=_graph.end();i++) { if(i->first==a) nodeList.push_back(i->second); } return nodeList; }
// Union/Find Algorithm - The find routine. // // Implemented with Path Compression (inner loops are only // visited and collapsed once, however, deep nests would still // result in significant traversals). // UnionFindNode *FindSet() { typedef std::list<UnionFindNode *> NodeListType; NodeListType nodeList; UnionFindNode *node = this; while (node != node->parent()) { if (node->parent() != node->parent()->parent()) nodeList.push_back(node); node = node->parent(); } // Path Compression, all nodes' parents point to the 1st level parent. NodeListType::iterator iter = nodeList.begin(); NodeListType::iterator end = nodeList.end(); for (; iter != end; ++iter) (*iter)->set_parent(node->parent()); return node; }