30 #include <tulip/tulipconf.h>
31 #include <tulip/Node.h>
32 #include <tulip/Edge.h>
33 #include <tulip/vectorgraphproperty.h>
37 template<
class itType >
60 class TLP_SCOPE VectorGraph {
81 edge existEdge(
const node src,
const node tgt,
const bool directed =
true)
const;
87 bool isElement(
const node n)
const;
93 bool isElement(
const edge e)
const;
100 void setEdgeOrder(
const node n,
const std::vector<edge> &v );
107 void swapEdgeOrder(
const node n,
const edge e1,
const edge e2);
115 void reserveNodes(
const size_t nbNodes);
123 void reserveEdges(
const size_t nbEdges);
131 void reserveAdj(
const size_t nbEdges);
139 void reserveAdj(
const node n,
const size_t nbEdges);
145 node operator[](
const unsigned int id)
const;
151 edge operator()(
const unsigned int id)
const;
157 node getOneNode()
const;
164 Iterator<node> * getNodes()
const;
171 Iterator<edge> * getEdges()
const;
178 Iterator<edge> * getInOutEdges(
const node n)
const;
185 Iterator<edge> * getOutEdges(
const node n)
const;
192 Iterator<edge> * getInEdges(
const node n)
const;
199 Iterator<node> * getInOutNodes(
const node n)
const;
207 Iterator<node> * getInNodes(
const node n)
const;
214 Iterator<node> * getOutNodes(
const node n)
const;
220 unsigned int deg(
const node n)
const;
226 unsigned int outdeg(
const node n)
const;
232 unsigned int indeg(
const node n)
const;
238 unsigned int numberOfEdges()
const;
244 unsigned int numberOfNodes()
const;
263 void delNode(
const node n);
271 edge addEdge(
const node src,
const node tgt);
282 void delEdge(
const edge e);
294 void delEdges(
const node n);
316 node source(
const edge e)
const;
322 node target(
const edge e)
const;
328 node opposite(
const edge e,
const node n)
const;
334 void reverse(
const edge e);
343 void setSource(
const edge e,
const node n);
352 void setTarget(
const edge e,
const node n);
358 std::pair<node, node> ends(
const edge e)
const;
366 void setEnds(
const edge e,
const node src,
const node tgt);
393 template<
typename Compare>
394 void sortEdges(Compare cmp,
bool stable =
false) {
396 stable_sort(_edges.begin(), _edges.end(), cmp);
398 sort(_edges.begin(), _edges.end(), cmp);
401 for (
unsigned int i = 0; i < _edges.size(); ++i) {
402 _eData[_edges[i]]._edgesId = i;
419 template<
typename Compare >
420 void sortNodes(Compare cmp,
bool stable =
false) {
422 stable_sort(_nodes.begin(), _nodes.end(), cmp);
424 sort(_nodes.begin(), _nodes.end(), cmp);
427 for (
unsigned int i = 0; i < _nodes.size(); ++i) {
428 _nData[_nodes[i]]._nodesId = i;
437 unsigned int edgePos(
const edge e)
const;
444 unsigned int nodePos(
const node n)
const;
451 void swap(
const node a,
const node b);
458 void swap(
const edge a,
const edge b);
467 template<
typename TYPE>
468 void alloc(NodeProperty<TYPE> &prop) {
469 ValArray<TYPE> *array =
new ValArray<TYPE>(_nodes.size() + _freeNodes.size(), _nodes.capacity());
470 _nodeArrays.insert(array);
471 prop = NodeProperty<TYPE>(array,
this);
480 template<
typename TYPE>
481 void free(NodeProperty<TYPE> array) {
482 assert(_nodeArrays.find(array._array) != _nodeArrays.end());
484 _nodeArrays.erase(array._array);
494 template<
typename TYPE>
495 void alloc(EdgeProperty<TYPE> &prop) {
496 ValArray<TYPE> *array =
new ValArray<TYPE>(_edges.size() + _freeEdges.size(), _edges.capacity());
497 _edgeArrays.insert(array);
498 prop = EdgeProperty<TYPE>(array,
this);
507 template<
typename TYPE>
508 void free(EdgeProperty<TYPE> array) {
509 assert(_edgeArrays.find(array._array) != _edgeArrays.end());
511 _edgeArrays.erase(array._array);
525 const std::vector<node>& adj(
const node n)
const;
538 const std::vector<edge>& star(
const node n)
const;
546 const std::vector<node>& nodes()
const;
554 const std::vector<edge>& edges()
const;
561 template<
typename TYPE>
562 bool isNodeAttr(ValArray<TYPE> *array) {
563 return (_nodeArrays.find(array) != _nodeArrays.end());
565 template<
typename TYPE>
566 bool isEdgeAttr(ValArray<TYPE> *array) {
567 return (_edgeArrays.find(array) != _edgeArrays.end());
579 void integrityTest();
584 _iNodes(
unsigned int id = UINT_MAX): _nodesId(id), _outdeg(0) {
594 void addEdge(
bool t, node n, edge e) {
600 unsigned int _nodesId;
601 unsigned int _outdeg;
602 std::vector<bool> _adjt;
603 std::vector<node> _adjn;
604 std::vector<edge> _adje;
608 unsigned int _edgesId;
609 std::pair<node, node> _edgeExtremities;
610 std::pair<unsigned int, unsigned int> _edgeExtremitiesPos;
613 std::vector<_iNodes> _nData;
614 std::vector<_iEdges> _eData;
616 std::vector< node > _nodes;
617 std::vector< edge > _edges;
619 std::vector<node> _freeNodes;
620 std::vector<edge> _freeEdges;
622 std::set<ValArrayInterface *> _nodeArrays;
623 std::set<ValArrayInterface *> _edgeArrays;
631 void testCond(std::string str,
bool b);
636 void addNodeToArray(node n);
641 void addEdgeToArray(edge e);
646 void removeEdge(edge e);
651 void moveEdge(node n,
unsigned int a,
unsigned int b);
655 void partialDelEdge(node n, edge e);
660 #ifndef NDEBUG //these two function are used to insure that property has been allocated in debug mode
661 template <
typename TYPE>
662 bool NodeProperty<TYPE>::isValid()
const {
663 if (this->_graph == 0)
return false;
665 if (this->_array == 0)
return false;
667 return this->_graph->isNodeAttr(this->_array);
670 template <
typename TYPE>
671 bool EdgeProperty<TYPE>::isValid()
const {
672 if (this->_graph == 0)
return false;
674 if (this->_array == 0)
return false;
676 return this->_graph->isEdgeAttr(this->_array);
680 #endif // VECTORGRAPH_H