Changeset 1931:6abf67b02ff5 in lemon-0.x for lemon/graph_utils.h
- Timestamp:
- 01/31/06 20:33:48 (18 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2506
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/graph_utils.h
r1909 r1931 887 887 /// and if a key is set to a new value then store it 888 888 /// in the inverse map. 889 /// 890 /// The values of the map can be accessed 891 /// with stl compatible forward iterator. 892 /// 889 893 /// \param _Graph The graph type. 890 894 /// \param _Item The item type of the graph. 891 895 /// \param _Value The value type of the map. 896 /// 897 /// \see IterableValueMap 892 898 #ifndef DOXYGEN 893 899 /// \param _Map A ReadWriteMap mapping from the item type to integer. … … 900 906 #endif 901 907 class InvertableMap : protected _Map { 902 903 public: 904 905 typedef _Map Map; 906 typedef _Graph Graph; 908 public: 907 909 908 910 /// The key type of InvertableMap (Node, Edge, UEdge). … … 911 913 typedef typename _Map::Value Value; 912 914 915 private: 916 917 typedef _Map Map; 918 typedef _Graph Graph; 919 920 typedef std::map<Value, Key> Container; 921 Container invMap; 922 923 public: 924 925 926 913 927 /// \brief Constructor. 914 928 /// … … 916 930 /// 917 931 InvertableMap(const Graph& graph) : Map(graph) {} 932 933 /// \brief Forward iterator for values. 934 /// 935 /// This iterator is an stl compatible forward 936 /// iterator on the values of the map. The values can 937 /// be accessed in the [beginValue, endValue) range. 938 /// 939 class ValueIterator 940 : public std::iterator<std::forward_iterator_tag, Value> { 941 friend class InvertableMap; 942 private: 943 ValueIterator(typename Container::const_iterator _it) 944 : it(_it) {} 945 public: 946 947 ValueIterator() {} 948 949 ValueIterator& operator++() { ++it; return *this; } 950 ValueIterator operator++(int) { 951 ValueIterator tmp(*this); 952 operator++(); 953 return tmp; 954 } 955 956 const Value& operator*() const { return it->first; } 957 const Value* operator->() const { return &(it->first); } 958 959 bool operator==(ValueIterator jt) const { return it == jt.it; } 960 bool operator!=(ValueIterator jt) const { return it != jt.it; } 961 962 private: 963 typename Container::const_iterator it; 964 }; 965 966 /// \brief Returns an iterator to the first value. 967 /// 968 /// Returns an stl compatible iterator to the 969 /// first value of the map. The values of the 970 /// map can be accessed in the [beginValue, endValue) 971 /// range. 972 ValueIterator beginValue() const { 973 return ValueIterator(invMap.begin()); 974 } 975 976 /// \brief Returns an iterator after the last value. 977 /// 978 /// Returns an stl compatible iterator after the 979 /// last value of the map. The values of the 980 /// map can be accessed in the [beginValue, endValue) 981 /// range. 982 ValueIterator endValue() const { 983 return ValueIterator(invMap.end()); 984 } 918 985 919 986 /// \brief The setter function of the map. … … 933 1000 /// 934 1001 /// It gives back the value associated with the key. 935 Value operator[](const Key& key) const { 1002 typename MapTraits<Map>::ConstReturnValue 1003 operator[](const Key& key) const { 936 1004 return Map::operator[](key); 937 1005 } … … 975 1043 Map::clear(); 976 1044 } 977 978 private:979 980 typedef std::map<Value, Key> Container;981 Container invMap;982 1045 983 1046 public: … … 1141 1204 public: 1142 1205 1206 /// \brief Returns the maximal value plus one. 1207 /// 1208 /// Returns the maximal value plus one in the map. 1209 unsigned int size() const { 1210 return invMap.size(); 1211 } 1212 1143 1213 /// \brief Swaps the position of the two items in the map. 1144 1214 /// … … 1194 1264 /// 1195 1265 /// Returns the size of the map. 1196 int size() const {1266 unsigned int size() const { 1197 1267 return inverted.invMap.size(); 1198 1268 } … … 1448 1518 Parent::set(key, 0); 1449 1519 } 1520 1450 1521 virtual void add(const std::vector<Key>& keys) { 1451 1522 Parent::add(keys); … … 1488 1559 } 1489 1560 1561 virtual void add(const std::vector<Edge>& edges) { 1562 for (int i = 0; i < (int)edges.size(); ++i) { 1563 ++deg[graph.target(edges[i])]; 1564 } 1565 } 1566 1490 1567 virtual void erase(const Edge& edge) { 1491 1568 --deg[graph.target(edge)]; 1569 } 1570 1571 virtual void erase(const std::vector<Edge>& edges) { 1572 for (int i = 0; i < (int)edges.size(); ++i) { 1573 --deg[graph.target(edges[i])]; 1574 } 1492 1575 } 1493 1576 … … 1592 1675 } 1593 1676 1677 virtual void add(const std::vector<Edge>& edges) { 1678 for (int i = 0; i < (int)edges.size(); ++i) { 1679 ++deg[graph.source(edges[i])]; 1680 } 1681 } 1682 1594 1683 virtual void erase(const Edge& edge) { 1595 1684 --deg[graph.source(edge)]; 1685 } 1686 1687 virtual void erase(const std::vector<Edge>& edges) { 1688 for (int i = 0; i < (int)edges.size(); ++i) { 1689 --deg[graph.source(edges[i])]; 1690 } 1596 1691 } 1597 1692
Note: See TracChangeset
for help on using the changeset viewer.