// Copyright 2016, University of Freiburg, // Chair of Algorithms and Data Structures. // Authors: Patrick Brosi // _____________________________________________________________________________ template UndirNode::UndirNode() : _pl() { } // _____________________________________________________________________________ template UndirNode::UndirNode(const N& pl) : _pl(pl) { } // _____________________________________________________________________________ template UndirNode::~UndirNode() { // delete self edges for (auto e = _adjList.begin(); e != _adjList.end();) { Edge* eP = *e; if (eP->getTo() == this && eP->getFrom() == this) { e = _adjList.erase(e); delete eP; } else { e++; } } for (auto e = _adjList.begin(); e != _adjList.end(); e++) { Edge* eP = *e; if (eP->getTo() != this) { eP->getTo()->removeEdge(eP); } if (eP->getFrom() != this) { eP->getFrom()->removeEdge(eP); } delete eP; } } // _____________________________________________________________________________ template bool UndirNode::hasEdgeIn(const Edge* e) const { return hasEdge(e); } // _____________________________________________________________________________ template bool UndirNode::hasEdgeOut(const Edge* e) const { return hasEdge(e); } // _____________________________________________________________________________ template bool UndirNode::hasEdge(const Edge* e) const { return e->getFrom() == this || e->getTo() == this; } // _____________________________________________________________________________ template bool UndirNode::adjContains(const Edge* e) const { for (size_t i = 0; i < _adjList.size(); i++) if (_adjList[i] == e) return true; return false; } // _____________________________________________________________________________ template void UndirNode::addEdge(Edge* e) { if (adjContains(e)) return; _adjList.reserve(_adjList.size() + 1); _adjList.push_back(e); } // _____________________________________________________________________________ template void UndirNode::removeEdge(Edge* e) { auto p = std::find(_adjList.begin(), _adjList.end(), e); if (p != _adjList.end()) _adjList.erase(p); } // _____________________________________________________________________________ template const std::vector*>& UndirNode::getAdjList() const { return _adjList; } // _____________________________________________________________________________ template const std::vector*>& UndirNode::getAdjListOut() const { return _adjList; } // _____________________________________________________________________________ template const std::vector*>& UndirNode::getAdjListIn() const { return _adjList; } // _____________________________________________________________________________ template size_t UndirNode::getDeg() const { return _adjList.size(); } // _____________________________________________________________________________ template size_t UndirNode::getInDeg() const { return getDeg(); } // _____________________________________________________________________________ template size_t UndirNode::getOutDeg() const { return getDeg(); } // _____________________________________________________________________________ template N& UndirNode::pl() { return _pl; } // _____________________________________________________________________________ template const N& UndirNode::pl() const { return _pl; }