21 #ifndef GRAPHSTORAGE_H 22 #define GRAPHSTORAGE_H 27 #include <tulip/Node.h> 28 #include <tulip/Edge.h> 29 #include <tulip/IdManager.h> 41 class GraphStorageIdsMemento {
43 virtual ~GraphStorageIdsMemento() {}
60 inline bool isElement(
const node n)
const {
61 return nodeIds.isElement(n);
67 inline unsigned int numberOfNodes()
const {
68 return nodeIds.size();
74 inline bool isElement(
const edge e)
const {
75 return edgeIds.isElement(e);
81 inline unsigned int numberOfEdges()
const {
82 return edgeIds.size();
90 void reserveNodes(
const size_t nb);
97 void reserveEdges(
const size_t nb);
104 void reserveAdj(
const node n,
const size_t nb);
111 void reserveAdj(
const size_t nb);
116 void restoreAdj(
const node n,
const std::vector<edge>& edges);
121 inline const std::vector<edge>& adj(
const node n)
const {
122 assert(isElement(n));
123 return nodeData[n.id].edges;
129 inline node getOneNode()
const {
130 return numberOfNodes() ? nodeIds[0] : node();
139 return nodeIds.getElts();
147 const GraphStorageIdsMemento* getIdsMemento()
const;
152 void restoreIdsMemento(
const GraphStorageIdsMemento*);
159 return edgeIds.getElts();
191 bool getEdges(
const node src,
const node tgt,
bool directed,
192 std::vector<edge>& edges,
const Graph* sg = NULL,
193 bool onlyFirst =
false)
const;
217 inline unsigned int deg(
const node n)
const {
218 assert(isElement(n));
219 return nodeData[n.id].edges.size();
225 inline unsigned int outdeg(
const node n)
const {
226 assert(isElement(n));
227 return nodeData[n.id].outDegree;
233 inline unsigned int indeg(
const node n)
const {
234 assert(isElement(n));
235 const NodeData& ctnr = nodeData[n.id];
236 return ctnr.edges.size() - ctnr.outDegree;
242 inline const std::vector<edge>& edges()
const {
249 inline unsigned int edgePos(
const edge e)
const {
250 return edgeIds.getPos(e);
256 inline const std::vector<node>& nodes()
const {
263 inline unsigned int nodePos(
const node n)
const {
264 return nodeIds.getPos(n);
270 inline const std::pair<node, node>& ends(
const edge e)
const {
271 assert(isElement(e));
272 return edgeEnds[e.id];
278 inline node source(
const edge e)
const {
279 assert(isElement(e));
280 return edgeEnds[e.id].first;
286 inline node target(
const edge e)
const {
287 assert(isElement(e));
288 return edgeEnds[e.id].second;
294 inline node opposite(
const edge e,
const node n)
const {
295 assert(isElement(e));
296 const std::pair<node, node>& eEnds = edgeEnds[e.id];
297 assert((eEnds.first == n) || (eEnds.second == n));
298 return (eEnds.first == n) ? eEnds.second : eEnds.first;
307 void setEnds(
const edge e,
const node newSrc,
const node newTgt);
315 inline void setSource(
const edge e,
const node n) {
316 setEnds(e, n, node());
325 inline void setTarget(
const edge e,
const node n) {
326 setEnds(e, node(), n);
332 void reverse(
const edge e);
337 void setEdgeOrder(
const node n,
const std::vector<edge> &v );
343 void swapEdgeOrder(
const node n,
const edge e1,
const edge e2);
351 void restoreNode(
const node n);
369 void addNodes(
unsigned int nb, std::vector<node>* addedNodes = NULL);
377 void removeFromNodes(
const node n);
388 void delNode(
const node n);
398 void restoreEdge(
const node src,
const node tgt,
const edge e);
406 edge addEdge(
const node src,
const node tgt);
415 void addEdges(
const std::vector<std::pair<node, node> >& edges,
416 std::vector<edge>* addedEdges = NULL);
426 void delEdge(
const edge e);
447 inline void sortElts() {
455 std::vector<edge> edges;
456 unsigned int outDegree;
459 NodeData(
unsigned int pos = UINT_MAX): outDegree(0), pos(pos) {}
463 mutable std::vector<std::pair<node, node> > edgeEnds;
464 mutable std::vector<NodeData> nodeData;
465 IdContainer<node> nodeIds;
466 IdContainer<edge> edgeIds;
476 static void removeFromNodeData(NodeData &c,
const edge e);
485 void removeFromEdges(
const edge e, node end = node());
488 #endif // GRAPHSTORAGE_H
Interface for Tulip iterators. Allows basic iteration operations only.