Changeset 1037:3eaff8d04171 in lemon-0.x for src/work/deba/map_utils.h
- Timestamp:
- 12/15/04 20:56:55 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1427
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/deba/map_utils.h
r1032 r1037 36 36 template < 37 37 typename _Graph, 38 typename _Map, 39 template <typename, typename> class _InvMap = std::Map 38 typename _Map 40 39 > 41 40 class InversableMap : protected _Map { 42 41 43 42 public: 43 typedef _Graph Graph; 44 44 45 typename _Map Map; 46 typename _InvMap<Map::Value, Map::Key> InverseMap; 45 typedef _Map Map; 46 typedef typename _Map::Key Key; 47 typedef typename _Map::Value Value; 48 typedef std::map<Value, Key> InverseMap; 47 49 48 typename _Map::Key Key; 49 typename _Map::Value Value; 50 typename _Map::ConstReference ConstReference; 50 typedef typename _Map::ConstReference ConstReference; 51 51 52 52 /// Constructor. … … 61 61 void set(const Key& key, const Value& val) { 62 62 Value oldval = Map::operator[](key); 63 InverseMap::iterator it = invMap.find(oldval);64 if (it != inv Map.end() && it->second == key) {65 inv Map.erase(it);63 typename InverseMap::iterator it = inv_map.find(oldval); 64 if (it != inv_map.end() && it->second == key) { 65 inv_map.erase(it); 66 66 } 67 inv Map.insert(make_pair(val, key));67 inv_map.insert(make_pair(val, key)); 68 68 Map::set(key, val); 69 69 } … … 79 79 virtual void erase(const Key&) { 80 80 Value val = Map::operator[](key); 81 InverseMap::iterator it = invMap.find(val);82 if (it != inv Map.end() && it->second == key) {81 typename InverseMap::iterator it = inv_map.find(val); 82 if (it != inv_map.end() && it->second == key) { 83 83 invMap.erase(it); 84 84 } … … 87 87 88 88 const InverseMap& inverse() const { 89 return inv Map;89 return inv_map; 90 90 } 91 91 92 92 93 93 private: 94 InverseMap inv Map;94 InverseMap inv_map; 95 95 }; 96 97 98 // unique, continous, mutable 99 100 template < 101 typename _Graph, 102 typename _Item, 103 typename _ItemIt, 104 typename _Map 105 > 106 class DescriptorMap : protected _Map { 107 public: 108 typedef _Graph Graph; 109 typedef _Item Item; 110 typedef _ItemIt ItemIt; 111 typedef _Map Map; 112 113 114 typedef typename _Map::Key Key; 115 typedef typename _Map::Value Value; 116 117 typedef vector<Item> InverseMap; 118 119 DescriptorMap(const Graph& _graph) : Map(_graph) { 120 build(); 121 } 122 123 virtual void add(const Item& item) { 124 Map::add(item); 125 Map::set(item, inv_map.size()); 126 inv_map.push_back(item); 127 } 128 129 virtual void erase(const Item& item) { 130 Map::set(inv_map.back(), Map::operator[](item)); 131 inv_map[Map::operator[](item)] = inv_map.back(); 132 Map::erase(item); 133 } 134 135 virtual void build() { 136 Map::build(); 137 for (ItemIt it(*Map::getGraph()); it != INVALID; ++it) { 138 Map::set(it, inv_map.size()); 139 inv_map.push_back(it); 140 } 141 } 142 143 virtual void clear() { 144 inv_map.clear(); 145 Map::clear(); 146 } 147 148 int operator[](const Item& item) const { 149 return Map::operator[](item); 150 } 151 152 153 const InverseMap inverse() const { 154 return inv_map; 155 } 156 157 private: 158 vector<Item> inv_map; 159 }; 160 161 // unique, immutable => IDMap 162 163 96 164 97 165 }
Note: See TracChangeset
for help on using the changeset viewer.