COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/bits/erasable_graph_extender.h @ 1627:3fd1ba6e9872

Last change on this file since 1627:3fd1ba6e9872 was 1627:3fd1ba6e9872, checked in by Balazs Dezso, 14 years ago

Some modification on the undirected graph interface.
Doc improvments

File size: 1.7 KB
Line 
1// -*- c++ -*-
2
3#ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H
4#define LEMON_ERASABLE_GRAPH_EXTENDER_H
5
6#include <vector>
7
8#include <lemon/invalid.h>
9
10
11namespace lemon {
12
13  template <typename _Base>
14  class ErasableGraphExtender : public _Base {
15  public:
16
17    typedef ErasableGraphExtender Graph;
18    typedef _Base Parent;
19
20    typedef typename Parent::Node Node;
21    typedef typename Parent::Edge Edge;
22
23    void erase(const Node& node) {
24      Edge edge;
25      Parent::firstOut(edge, node);
26      while (edge != INVALID ) {
27        erase(edge);
28        Parent::firstOut(edge, node);
29      }
30
31      Parent::firstIn(edge, node);
32      while (edge != INVALID ) {
33        erase(edge);
34        Parent::firstIn(edge, node);
35      }
36
37      Parent::getNotifier(Node()).erase(node);
38      Parent::erase(node);
39    }
40   
41    void erase(const Edge& edge) {
42      Parent::getNotifier(Edge()).erase(edge);
43      Parent::erase(edge);
44    }
45
46  };
47
48  template <typename _Base>
49  class ErasableUndirGraphExtender : public _Base {
50  public:
51
52    typedef ErasableUndirGraphExtender Graph;
53    typedef _Base Parent;
54
55    typedef typename Parent::Node Node;
56    typedef typename Parent::UndirEdge UndirEdge;
57    typedef typename Parent::Edge Edge;
58
59    void erase(const Node& node) {
60      Edge edge;
61      Parent::firstOut(edge, node);
62      while (edge != INVALID ) {
63        erase(edge);
64        Parent::firstOut(edge, node);
65      }
66
67      Parent::getNotifier(Node()).erase(node);
68      Parent::erase(node);
69    }
70   
71    void erase(const UndirEdge& uedge) {
72      std::vector<Edge> edges;
73      edges.push_back(Parent::direct(uedge,true));
74      edges.push_back(Parent::direct(uedge,false));
75      Parent::getNotifier(Edge()).erase(edges);
76      Parent::getNotifier(UndirEdge()).erase(uedge);
77      Parent::erase(uedge);
78    }
79
80  };
81
82}
83
84#endif
Note: See TracBrowser for help on using the repository browser.