# HG changeset patch # User deba # Date 1132760556 0 # Node ID 183b4cbf973305708d48f225e09dbf9b956d01c0 # Parent fd3771591a5c33d1392793f0c055f2cd32e0490b Correcting alteration notifing diff -r fd3771591a5c -r 183b4cbf9733 lemon/graph_utils.h --- a/lemon/graph_utils.h Wed Nov 23 11:20:14 2005 +0000 +++ b/lemon/graph_utils.h Wed Nov 23 15:42:36 2005 +0000 @@ -110,8 +110,7 @@ // Node counting: template - inline - typename enable_if::type + inline typename enable_if::type _countNodes(const Graph &g) { return g.nodeNum(); } @@ -137,8 +136,7 @@ // Edge counting: template - inline - typename enable_if::type + inline typename enable_if::type _countEdges(const Graph &g) { return g.edgeNum(); } @@ -420,7 +418,7 @@ /// It increments the iterator and gives back the next edge. ConUndirEdgeIt& operator++() { Parent::operator=(findUndirEdge(graph, graph.source(*this), - graph.target(*this), *this)); + graph.target(*this), *this)); return *this; } private: @@ -938,14 +936,6 @@ protected: - /// \brief Add a new key to the map. - /// - /// Add a new key to the map. It is called by the - /// \c AlterationNotifier. - virtual void add(const Key& key) { - Map::add(key); - } - /// \brief Erase the key from the map. /// /// Erase the key to the map. It is called by the @@ -959,6 +949,21 @@ Map::erase(key); } + /// \brief Erase more keys from the map. + /// + /// Erase more keys from the map. It is called by the + /// \c AlterationNotifier. + virtual void erase(const std::vector& keys) { + for (int i = 0; i < (int)keys.size(); ++i) { + Value val = Map::operator[](keys[i]); + typename Container::iterator it = invMap.find(val); + if (it != invMap.end() && it->second == keys[i]) { + invMap.erase(it); + } + } + Map::erase(keys); + } + /// \brief Clear the keys from the map and inverse map. /// /// Clear the keys from the map and inverse map. It is called by the @@ -1070,9 +1075,21 @@ invMap.push_back(item); } + /// \brief Add more new keys to the map. + /// + /// Add more new keys to the map. It is called by the + /// \c AlterationNotifier. + virtual void add(const std::vector& items) { + Map::add(items); + for (int i = 0; i < (int)items.size(); ++i) { + Map::set(items[i], invMap.size()); + invMap.push_back(items[i]); + } + } + /// \brief Erase the key from the map. /// - /// Erase the key to the map. It is called by the + /// Erase the key from the map. It is called by the /// \c AlterationNotifier. virtual void erase(const Item& item) { Map::set(invMap.back(), Map::operator[](item)); @@ -1081,6 +1098,19 @@ Map::erase(item); } + /// \brief Erase more keys from the map. + /// + /// Erase more keys from the map. It is called by the + /// \c AlterationNotifier. + virtual void erase(const std::vector& items) { + for (int i = 0; i < (int)items.size(); ++i) { + Map::set(invMap.back(), Map::operator[](items[i])); + invMap[Map::operator[](items[i])] = invMap.back(); + invMap.pop_back(); + } + Map::erase(items); + } + /// \brief Build the unique map. /// /// Build the unique map. It is called by the @@ -1379,8 +1409,8 @@ /// /// \warning Besides addNode() and addEdge(), a graph structure may provide /// alternative ways to modify the graph. The correct behavior of InDegMap - /// is not guarantied if these additional featureas are used. For example - /// the funstions \ref ListGraph::changeSource() "changeSource()", + /// is not guarantied if these additional features are used. For example + /// the functions \ref ListGraph::changeSource() "changeSource()", /// \ref ListGraph::changeTarget() "changeTarget()" and /// \ref ListGraph::reverseEdge() "reverseEdge()" /// of \ref ListGraph will \e not update the degree values correctly. @@ -1409,10 +1439,16 @@ AutoNodeMap(const Graph& graph) : Parent(graph, 0) {} - void add(const Key& key) { + virtual void add(const Key& key) { Parent::add(key); Parent::set(key, 0); } + virtual void add(const std::vector& keys) { + Parent::add(keys); + for (int i = 0; i < (int)keys.size(); ++i) { + Parent::set(keys[i], 0); + } + } }; public: @@ -1451,14 +1487,6 @@ --deg[graph.target(edge)]; } - virtual void signalChange(const Edge& edge) { - erase(edge); - } - - virtual void commitChange(const Edge& edge) { - add(edge); - } - virtual void build() { for(typename _Graph::NodeIt it(graph); it != INVALID; ++it) { deg[it] = countInEdges(graph, it); @@ -1485,8 +1513,8 @@ /// /// \warning Besides addNode() and addEdge(), a graph structure may provide /// alternative ways to modify the graph. The correct behavior of OutDegMap - /// is not guarantied if these additional featureas are used. For example - /// the funstions \ref ListGraph::changeSource() "changeSource()", + /// is not guarantied if these additional features are used. For example + /// the functions \ref ListGraph::changeSource() "changeSource()", /// \ref ListGraph::changeTarget() "changeTarget()" and /// \ref ListGraph::reverseEdge() "reverseEdge()" /// of \ref ListGraph will \e not update the degree values correctly. @@ -1515,10 +1543,16 @@ AutoNodeMap(const Graph& graph) : Parent(graph, 0) {} - void add(const Key& key) { + virtual void add(const Key& key) { Parent::add(key); Parent::set(key, 0); } + virtual void add(const std::vector& keys) { + Parent::add(keys); + for (int i = 0; i < (int)keys.size(); ++i) { + Parent::set(keys[i], 0); + } + } }; public: @@ -1557,15 +1591,6 @@ --deg[graph.source(edge)]; } - virtual void signalChange(const Edge& edge) { - erase(edge); - } - - virtual void commitChange(const Edge& edge) { - add(edge); - } - - virtual void build() { for(typename _Graph::NodeIt it(graph); it != INVALID; ++it) { deg[it] = countOutEdges(graph, it);