Changeset 1703:eb90e3d6bddc in lemon-0.x
- Timestamp:
- 10/05/05 15:15:47 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2230
- Location:
- lemon
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/array_map.h
r1669 r1703 49 49 typedef _Item Item; 50 50 public: 51 typedef True AdaptibleTag; 51 52 52 53 /// The graph type of the maps. … … 70 71 public: 71 72 73 /// \brief Graph and Registry initialized map constructor. 74 /// 72 75 /// Graph and Registry initialized map constructor. 73 76 ArrayMap(const Graph& _g) : graph(&_g) { … … 81 84 } 82 85 83 /// Constructor to use default value to initialize the map. 84 85 /// It constrates a map and initialize all of the the map. 86 86 /// \brief Constructor to use default value to initialize the map. 87 /// 88 /// It constructs a map and initialize all of the the map. 87 89 ArrayMap(const Graph& _g, const Value& _v) : graph(&_g) { 88 90 Item it; … … 95 97 } 96 98 97 /// Constructor to copy a map of the same map type. 98 99 /// \brief Constructor to copy a map of the same map type. 100 /// 101 /// Constructor to copy a map of the same map type. 99 102 ArrayMap(const ArrayMap& copy) : Parent(), graph(copy.graph) { 100 103 if (copy.attached()) { … … 138 141 public: 139 142 140 ///The subscript operator. The map can be subscripted by the 141 ///actual keys of the graph. 142 143 /// \brief The subscript operator. 144 /// 145 /// The subscript operator. The map can be subscripted by the 146 /// actual keys of the graph. 143 147 Value& operator[](const Key& key) { 144 148 int id = graph->id(key); … … 146 150 } 147 151 148 149 /// The const subscript operator. The map can be subscripted by the150 /// actual keys of the graph.151 152 /// \brief The const subscript operator. 153 /// 154 /// The const subscript operator. The map can be subscripted by the 155 /// actual keys of the graph. 152 156 const Value& operator[](const Key& key) const { 153 157 int id = graph->id(key); 154 158 return values[id]; 155 159 } 156 160 161 /// \brief Setter function of the map. 162 /// 157 163 /// Setter function of the map. Equivalent with map[key] = val. 158 164 /// This is a compatibility feature with the not dereferable maps. 159 160 165 void set(const Key& key, const Value& val) { 161 166 (*this)[key] = val; … … 163 168 164 169 protected: 165 170 166 171 /// Add a new key to the map. It called by the map registry. 167 168 v oid add(const Key& key) {172 173 virtual void add(const Key& key) { 169 174 int id = graph->id(key); 170 175 if (id >= capacity) { … … 189 194 } 190 195 191 v oid add(const std::vector<Key>& keys) {196 virtual void add(const std::vector<Key>& keys) { 192 197 int max_id = -1; 193 198 for (int i = 0; i < (int)keys.size(); ++i) { … … 230 235 /// Erase a key from the map. It called by the map registry. 231 236 232 v oid erase(const Key& key) {237 virtual void erase(const Key& key) { 233 238 int id = graph->id(key); 234 239 allocator.destroy(&(values[id])); 235 240 } 236 241 237 v oid erase(const std::vector<Key>& keys) {242 virtual void erase(const std::vector<Key>& keys) { 238 243 for (int i = 0; i < (int)keys.size(); ++i) { 239 244 int id = graph->id(keys[i]); … … 242 247 } 243 248 244 v oid build() {249 virtual void build() { 245 250 allocate_memory(); 246 251 Item it; … … 251 256 } 252 257 253 v oid clear() {258 virtual void clear() { 254 259 if (capacity != 0) { 255 260 Item it; -
lemon/bits/default_map.h
r1672 r1703 29 29 namespace lemon { 30 30 31 /// \addtogroup graphmapfactory32 /// @{33 31 34 32 template <typename _Graph, typename _Item, typename _Value> … … 269 267 }; 270 268 271 /// @}272 269 } 273 270 -
lemon/bits/vector_map.h
r1669 r1703 45 45 /// 46 46 /// \param Registry The AlterationNotifier that will notify this map. 47 /// \param I dMap The IdMaptype of the graph items.47 /// \param Item The item type of the graph items. 48 48 /// \param Value The value type of the map. 49 49 /// 50 50 /// \author Balazs Dezso 51 51 52 53 52 template < 54 53 typename _Graph, … … 58 57 class VectorMap : public AlterationNotifier<_Item>::ObserverBase { 59 58 public: 59 60 typedef True AdaptibleTag; 60 61 61 62 /// The graph type of the map. … … 94 95 typedef True FullTypeTag; 95 96 96 /// Constructor to attach the new map into the registry.97 98 /// It constru ates a map and attachs it into the registry.97 /// \brief Constructor to attach the new map into the registry. 98 /// 99 /// It constructs a map and attachs it into the registry. 99 100 /// It adds all the items of the graph to the map. 100 101 101 VectorMap(const Graph& _g) : graph(&_g) { 102 102 attach(_g.getNotifier(_Item())); … … 104 104 } 105 105 106 /// Constructor uses given value to initialize the map.107 108 /// It constru ates a map uses a given value to initialize the map.106 /// \brief Constructor uses given value to initialize the map. 107 /// 108 /// It constructs a map uses a given value to initialize the map. 109 109 /// It adds all the items of the graph to the map. 110 111 110 VectorMap(const Graph& _g, const Value& _v) : graph(&_g) { 112 111 attach(_g.getNotifier(_Item())); … … 114 113 } 115 114 115 /// \brief Copy constructor 116 /// 117 /// Copy constructor. 116 118 VectorMap(const VectorMap& _copy) 117 119 : Parent(), graph(_copy.getGraph()) { … … 122 124 } 123 125 126 /// \brief Destrcutor 127 /// 128 /// Destructor. 124 129 virtual ~VectorMap() { 125 130 if (attached()) { … … 145 150 public: 146 151 147 /// The subcript operator.148 152 /// \brief The subcript operator. 153 /// 149 154 /// The subscript operator. The map can be subscripted by the 150 /// actual items of the graph. 151 155 /// actual items of the graph. 152 156 Reference operator[](const Key& key) { 153 157 return container[graph->id(key)]; 154 158 } 155 159 156 /// The const subcript operator.157 160 /// \brief The const subcript operator. 161 /// 158 162 /// The const subscript operator. The map can be subscripted by the 159 163 /// actual items of the graph. 160 161 164 ConstReference operator[](const Key& key) const { 162 165 return container[graph->id(key)]; … … 164 167 165 168 166 /// The setter function of the map.167 169 /// \brief The setter function of the map. 170 /// 168 171 /// It the same as operator[](key) = value expression. 169 ///170 172 void set(const Key& key, const Value& value) { 171 173 (*this)[key] = value; … … 177 179 /// 178 180 /// It adds a new key to the map. It called by the observer registry 179 /// and it overrides the add() member function of the observer base. 180 181 void add(const Key& key) { 181 /// and it overrides the add() member function of the observer base. 182 virtual void add(const Key& key) { 182 183 int id = graph->id(key); 183 184 if (id >= (int)container.size()) { … … 186 187 } 187 188 188 /// Erasesa key from the map.189 189 /// \brief Erase a key from the map. 190 /// 190 191 /// Erase a key from the map. It called by the observer registry 191 192 /// and it overrides the erase() member function of the observer base. 192 v oid erase(const Key&) {}193 194 /// Buildes the map.195 193 virtual void erase(const Key&) {} 194 195 /// \brief Buildes the map. 196 /// 196 197 /// It buildes the map. It called by the observer registry 197 198 /// and it overrides the build() member function of the observer base. 198 199 void build() { 199 virtual void build() { 200 200 container.resize(graph->maxId(_Item()) + 1); 201 201 } 202 202 203 /// Clear the map.204 203 /// \brief Clear the map. 204 /// 205 205 /// It erase all items from the map. It called by the observer registry 206 206 /// and it overrides the clear() member function of the observer base. 207 v oid clear() {207 virtual void clear() { 208 208 container.clear(); 209 209 } -
lemon/full_graph.h
r1692 r1703 23 23 #include <lemon/bits/iterable_graph_extender.h> 24 24 #include <lemon/bits/alteration_notifier.h> 25 #include <lemon/bits/ default_map.h>25 #include <lemon/bits/static_map.h> 26 26 27 27 #include <lemon/bits/undir_graph_extender.h> … … 196 196 typedef IterableGraphExtender<AlterableFullGraphBase> 197 197 IterableFullGraphBase; 198 typedef MappableGraphExtender<198 typedef StaticMappableGraphExtender< 199 199 IterableGraphExtender< 200 200 AlterableGraphExtender<FullGraphBase> > > ExtendedFullGraphBase; … … 299 299 /// the next edge from \c u to \c v after \c prev. 300 300 /// \return The found edge or INVALID if there is no such an edge. 301 Edge findEdge(Node u,Node v, Edge prev = INVALID) 302 { 303 return prev.id == -1 ? Edge(*this, u.id, v.id) : INVALID; 304 } 301 Edge findEdge(Node u, Node v, Edge prev = INVALID) const { 302 if (prev.id != -1 || u.id <= v.id) return -1; 303 return Edge(u.id * (u.id - 1) / 2 + v.id); 304 } 305 306 typedef True FindEdgeTag; 305 307 306 308 … … 329 331 Edge(int _id) : id(_id) {} 330 332 331 Edge(const UndirFullGraphBase& _graph, int source, int target)332 : id(_graph._nodeNum * target+source) {}333 333 public: 334 334 Edge() { } … … 340 340 341 341 void first(Node& node) const { 342 node.id = _nodeNum -1;342 node.id = _nodeNum - 1; 343 343 } 344 344 … … 348 348 349 349 void first(Edge& edge) const { 350 edge.id = _edgeNum -1;350 edge.id = _edgeNum - 1; 351 351 } 352 352 … … 356 356 357 357 void firstOut(Edge& edge, const Node& node) const { 358 edge.id = node.id != 0 ? node.id * (node.id - 1) / 2 : -1; 358 int src = node.id; 359 int trg = 0; 360 edge.id = (trg < src ? src * (src - 1) / 2 + trg : -1); 359 361 } 360 362 361 363 /// \todo with specialized iterators we can make faster iterating 362 void nextOut(Edge& e ) const {363 int s ource = ((int)sqrt((double)(1 + 8 * e.id)) + 1) / 2;;364 int t arget = e.id - (source) * (source - 1) / 2;365 ++t arget;366 e .id = target < source ? source * (source - 1) / 2 + target : -1;364 void nextOut(Edge& edge) const { 365 int src = source(edge).id; 366 int trg = target(edge).id; 367 ++trg; 368 edge.id = (trg < src ? src * (src - 1) / 2 + trg : -1); 367 369 } 368 370 369 371 void firstIn(Edge& edge, const Node& node) const { 370 edge.id = node.id * (node.id + 1) / 2 - 1; 371 } 372 373 void nextIn(Edge& e) const { 374 int source = ((int)sqrt((double)(1 + 8 * e.id)) + 1) / 2;; 375 int target = e.id - (source) * (source - 1) / 2; ++target; 376 ++source; 377 e.id = source < _nodeNum ? source * (source - 1) / 2 + target : -1; 372 int src = node.id + 1; 373 int trg = node.id; 374 edge.id = (src < _nodeNum ? src * (src - 1) / 2 + trg : -1); 375 } 376 377 void nextIn(Edge& edge) const { 378 int src = source(edge).id; 379 int trg = target(edge).id; 380 ++src; 381 edge.id = (src < _nodeNum ? src * (src - 1) / 2 + trg : -1); 378 382 } 379 383 380 384 }; 381 385 382 typedef MappableUndirGraphExtender<386 typedef StaticMappableUndirGraphExtender< 383 387 IterableUndirGraphExtender< 384 388 AlterableUndirGraphExtender< -
lemon/grid_graph.h
r1693 r1703 24 24 #include <lemon/bits/iterable_graph_extender.h> 25 25 #include <lemon/bits/alteration_notifier.h> 26 #include <lemon/bits/ default_map.h>26 #include <lemon/bits/static_map.h> 27 27 28 28 #include <lemon/bits/undir_graph_extender.h> … … 340 340 341 341 342 typedef MappableUndirGraphExtender<342 typedef StaticMappableUndirGraphExtender< 343 343 IterableUndirGraphExtender< 344 344 AlterableUndirGraphExtender< -
lemon/hypercube_graph.h
r1693 r1703 233 233 234 234 235 typedef MappableGraphExtender<235 typedef StaticMappableGraphExtender< 236 236 IterableGraphExtender< 237 237 AlterableGraphExtender<
Note: See TracChangeset
for help on using the changeset viewer.