COIN-OR::LEMON - Graph Library

Changeset 1829:183b4cbf9733 in lemon-0.x


Ignore:
Timestamp:
11/23/05 16:42:36 (19 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2379
Message:

Correcting alteration notifing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/graph_utils.h

    r1811 r1829  
    111111
    112112  template <typename Graph>
    113   inline
    114   typename enable_if<typename Graph::NodeNumTag, int>::type
     113  inline typename enable_if<typename Graph::NodeNumTag, int>::type
    115114  _countNodes(const Graph &g) {
    116115    return g.nodeNum();
     
    138137
    139138  template <typename Graph>
    140   inline
    141   typename enable_if<typename Graph::EdgeNumTag, int>::type
     139  inline typename enable_if<typename Graph::EdgeNumTag, int>::type
    142140  _countEdges(const Graph &g) {
    143141    return g.edgeNum();
     
    421419    ConUndirEdgeIt& operator++() {
    422420      Parent::operator=(findUndirEdge(graph, graph.source(*this),
    423                                  graph.target(*this), *this));
     421                                      graph.target(*this), *this));
    424422      return *this;
    425423    }
     
    939937  protected:
    940938
    941     /// \brief Add a new key to the map.
    942     ///
    943     /// Add a new key to the map. It is called by the
    944     /// \c AlterationNotifier.
    945     virtual void add(const Key& key) {
    946       Map::add(key);
    947     }
    948 
    949939    /// \brief Erase the key from the map.
    950940    ///
     
    958948      }
    959949      Map::erase(key);
     950    }
     951
     952    /// \brief Erase more keys from the map.
     953    ///
     954    /// Erase more keys from the map. It is called by the
     955    /// \c AlterationNotifier.
     956    virtual void erase(const std::vector<Key>& keys) {
     957      for (int i = 0; i < (int)keys.size(); ++i) {
     958        Value val = Map::operator[](keys[i]);
     959        typename Container::iterator it = invMap.find(val);
     960        if (it != invMap.end() && it->second == keys[i]) {
     961          invMap.erase(it);
     962        }
     963      }
     964      Map::erase(keys);
    960965    }
    961966
     
    10711076    }
    10721077
     1078    /// \brief Add more new keys to the map.
     1079    ///
     1080    /// Add more new keys to the map. It is called by the
     1081    /// \c AlterationNotifier.
     1082    virtual void add(const std::vector<Item>& items) {
     1083      Map::add(items);
     1084      for (int i = 0; i < (int)items.size(); ++i) {
     1085        Map::set(items[i], invMap.size());
     1086        invMap.push_back(items[i]);
     1087      }
     1088    }
     1089
    10731090    /// \brief Erase the key from the map.
    10741091    ///
    1075     /// Erase the key to the map. It is called by the
     1092    /// Erase the key from the map. It is called by the
    10761093    /// \c AlterationNotifier.
    10771094    virtual void erase(const Item& item) {
     
    10801097      invMap.pop_back();
    10811098      Map::erase(item);
     1099    }
     1100
     1101    /// \brief Erase more keys from the map.
     1102    ///
     1103    /// Erase more keys from the map. It is called by the
     1104    /// \c AlterationNotifier.
     1105    virtual void erase(const std::vector<Item>& items) {
     1106      for (int i = 0; i < (int)items.size(); ++i) {
     1107        Map::set(invMap.back(), Map::operator[](items[i]));
     1108        invMap[Map::operator[](items[i])] = invMap.back();
     1109        invMap.pop_back();
     1110      }
     1111      Map::erase(items);
    10821112    }
    10831113
     
    13801410  /// \warning Besides addNode() and addEdge(), a graph structure may provide
    13811411  /// alternative ways to modify the graph. The correct behavior of InDegMap
    1382   /// is not guarantied if these additional featureas are used. For example
    1383   /// the funstions \ref ListGraph::changeSource() "changeSource()",
     1412  /// is not guarantied if these additional features are used. For example
     1413  /// the functions \ref ListGraph::changeSource() "changeSource()",
    13841414  /// \ref ListGraph::changeTarget() "changeTarget()" and
    13851415  /// \ref ListGraph::reverseEdge() "reverseEdge()"
     
    14101440      AutoNodeMap(const Graph& graph) : Parent(graph, 0) {}
    14111441     
    1412       void add(const Key& key) {
     1442      virtual void add(const Key& key) {
    14131443        Parent::add(key);
    14141444        Parent::set(key, 0);
     1445      }
     1446      virtual void add(const std::vector<Key>& keys) {
     1447        Parent::add(keys);
     1448        for (int i = 0; i < (int)keys.size(); ++i) {
     1449          Parent::set(keys[i], 0);
     1450        }
    14151451      }
    14161452    };
     
    14521488    }
    14531489
    1454     virtual void signalChange(const Edge& edge) {
    1455       erase(edge);
    1456     }
    1457 
    1458     virtual void commitChange(const Edge& edge) {
    1459       add(edge);
    1460     }
    1461 
    14621490    virtual void build() {
    14631491      for(typename _Graph::NodeIt it(graph); it != INVALID; ++it) {
     
    14861514  /// \warning Besides addNode() and addEdge(), a graph structure may provide
    14871515  /// alternative ways to modify the graph. The correct behavior of OutDegMap
    1488   /// is not guarantied if these additional featureas are used. For example
    1489   /// the funstions \ref ListGraph::changeSource() "changeSource()",
     1516  /// is not guarantied if these additional features are used. For example
     1517  /// the functions \ref ListGraph::changeSource() "changeSource()",
    14901518  /// \ref ListGraph::changeTarget() "changeTarget()" and
    14911519  /// \ref ListGraph::reverseEdge() "reverseEdge()"
     
    15161544      AutoNodeMap(const Graph& graph) : Parent(graph, 0) {}
    15171545     
    1518       void add(const Key& key) {
     1546      virtual void add(const Key& key) {
    15191547        Parent::add(key);
    15201548        Parent::set(key, 0);
     1549      }
     1550      virtual void add(const std::vector<Key>& keys) {
     1551        Parent::add(keys);
     1552        for (int i = 0; i < (int)keys.size(); ++i) {
     1553          Parent::set(keys[i], 0);
     1554        }
    15211555      }
    15221556    };
     
    15581592    }
    15591593
    1560     virtual void signalChange(const Edge& edge) {
    1561       erase(edge);
    1562     }
    1563 
    1564     virtual void commitChange(const Edge& edge) {
    1565       add(edge);
    1566     }
    1567 
    1568 
    15691594    virtual void build() {
    15701595      for(typename _Graph::NodeIt it(graph); it != INVALID; ++it) {
Note: See TracChangeset for help on using the changeset viewer.