30 #include <tulip/tulipconf.h> 31 #include <tulip/Node.h> 32 #include <tulip/Edge.h> 33 #include <tulip/IdManager.h> 34 #include <tulip/vectorgraphproperty.h> 38 template<
class itType >
61 class TLP_SCOPE VectorGraph {
82 edge existEdge(
const node src,
const node tgt,
const bool directed =
true)
const;
88 bool isElement(
const node n)
const {
89 assert(n.id < _nData.size());
90 return _nodes.isElement(n);
97 bool isElement(
const edge e)
const {
98 assert(e.id < _eData.size());
99 return _edges.isElement(e);
107 void setEdgeOrder(
const node n,
const std::vector<edge> &v );
114 void swapEdgeOrder(
const node n,
const edge e1,
const edge e2);
122 void reserveNodes(
const size_t nbNodes);
130 void reserveEdges(
const size_t nbEdges);
138 void reserveAdj(
const size_t nbEdges);
146 void reserveAdj(
const node n,
const size_t nbEdges);
152 node operator[](
const unsigned int id)
const {
153 assert(
id < _nodes.size());
161 edge operator()(
const unsigned int id)
const {
162 assert(
id < _edges.size());
170 node getOneNode()
const {
171 assert(numberOfNodes()>0);
236 unsigned int deg(
const node n)
const {
237 assert(isElement(n));
238 return _nData[n]._adjn.size();
245 unsigned int outdeg(
const node n)
const {
246 assert(isElement(n));
247 return _nData[n]._outdeg;
254 unsigned int indeg(
const node n)
const {
255 return deg(n) - _nData[n]._outdeg;
262 unsigned int numberOfEdges()
const {
263 return _edges.size();
270 unsigned int numberOfNodes()
const {
271 return _nodes.size();
290 void addNodes(
unsigned int nb, std::vector<node>* addedNodes = NULL);
301 void delNode(
const node n);
309 edge addEdge(
const node src,
const node tgt);
318 void addEdges(
const std::vector<std::pair<node, node> >& edges,
319 std::vector<edge>* addedEdges = NULL);
330 void delEdge(
const edge e);
342 void delEdges(
const node n);
364 node source(
const edge e)
const {
365 assert(isElement(e));
366 return _eData[e]._ends.first;
373 node target(
const edge e)
const {
374 assert(isElement(e));
375 return _eData[e]._ends.second;
382 node opposite(
const edge e,
const node n)
const;
388 void reverse(
const edge e);
397 void setSource(
const edge e,
const node n) {
398 assert(isElement(e));
399 assert(isElement(n));
400 setEnds(e, n, target(e));
410 void setTarget(
const edge e,
const node n) {
411 assert(isElement(e));
412 assert(isElement(n));
413 setEnds(e, source(e), n);
420 const std::pair<node, node>& ends(
const edge e)
const {
421 assert(isElement(e));
422 return _eData[e]._ends;
431 void setEnds(
const edge e,
const node src,
const node tgt);
458 template<
typename Compare>
459 void sortEdges(Compare cmp,
bool stable =
false) {
461 stable_sort(_edges.begin(), _edges.end(), cmp);
463 sort(_edges.begin(), _edges.end(), cmp);
482 template<
typename Compare >
483 void sortNodes(Compare cmp,
bool stable =
false) {
485 stable_sort(_nodes.begin(), _nodes.end(), cmp);
487 sort(_nodes.begin(), _nodes.end(), cmp);
498 unsigned int edgePos(
const edge e)
const {
499 assert(isElement(e));
500 return _edges.getPos(e);
508 unsigned int nodePos(
const node n)
const {
509 assert(isElement(n));
510 return _nodes.getPos(n);
518 void swap(
const node a,
const node b);
525 void swap(
const edge a,
const edge b);
534 template<
typename TYPE>
535 void alloc(NodeProperty<TYPE> &prop) {
536 ValArray<TYPE> *array =
new ValArray<TYPE>(_nodes.size() + _nodes.numberOfFree(), _nodes.capacity());
537 _nodeArrays.insert(array);
538 prop = NodeProperty<TYPE>(array,
this);
547 template<
typename TYPE>
548 void free(NodeProperty<TYPE> array) {
549 assert(_nodeArrays.find(array._array) != _nodeArrays.end());
551 _nodeArrays.erase(array._array);
561 template<
typename TYPE>
562 void alloc(EdgeProperty<TYPE> &prop) {
563 ValArray<TYPE> *array =
new ValArray<TYPE>(_edges.size() + _edges.numberOfFree(), _edges.capacity());
564 _edgeArrays.insert(array);
565 prop = EdgeProperty<TYPE>(array,
this);
574 template<
typename TYPE>
575 void free(EdgeProperty<TYPE> array) {
576 assert(_edgeArrays.find(array._array) != _edgeArrays.end());
578 _edgeArrays.erase(array._array);
592 const std::vector<node>& adj(
const node n)
const {
593 assert(isElement(n));
594 return _nData[n]._adjn;
608 const std::vector<edge>& star(
const node n)
const {
609 assert(isElement(n));
610 return _nData[n]._adje;
619 const std::vector<node>& nodes()
const {
629 const std::vector<edge>& edges()
const {
638 template<
typename TYPE>
639 bool isNodeAttr(ValArray<TYPE> *array) {
640 return (_nodeArrays.find(array) != _nodeArrays.end());
642 template<
typename TYPE>
643 bool isEdgeAttr(ValArray<TYPE> *array) {
644 return (_edgeArrays.find(array) != _edgeArrays.end());
656 void integrityTest();
661 _iNodes(): _outdeg(0) {
671 void addEdge(
bool t, node n, edge e) {
677 unsigned int _outdeg;
678 std::vector<bool> _adjt;
679 std::vector<node> _adjn;
680 std::vector<edge> _adje;
684 std::pair<node, node> _ends;
685 std::pair<unsigned int, unsigned int> _endsPos;
688 std::vector<_iNodes> _nData;
689 std::vector<_iEdges> _eData;
691 IdContainer<node> _nodes;
692 IdContainer<edge> _edges;
694 std::set<ValArrayInterface *> _nodeArrays;
695 std::set<ValArrayInterface *> _edgeArrays;
703 void testCond(std::string str,
bool b);
708 void addNodeToArray(node n);
713 void addEdgeToArray(edge e);
718 void addEdgeInternal(edge e, node src, node tgt);
723 void removeEdge(edge e);
728 void moveEdge(node n,
unsigned int a,
unsigned int b);
732 void partialDelEdge(node n, edge e);
737 #ifndef NDEBUG //these two function are used to insure that property has been allocated in debug mode 738 template <
typename TYPE>
739 bool NodeProperty<TYPE>::isValid()
const {
740 if (this->_graph == 0)
return false;
742 if (this->_array == 0)
return false;
744 return this->_graph->isNodeAttr(this->_array);
747 template <
typename TYPE>
748 bool EdgeProperty<TYPE>::isValid()
const {
749 if (this->_graph == 0)
return false;
751 if (this->_array == 0)
return false;
753 return this->_graph->isEdgeAttr(this->_array);
757 #endif // VECTORGRAPH_H
Interface for Tulip iterators. Allows basic iteration operations only.