COIN-OR::LEMON - Graph Library

Changeset 595:e10b5e9419ef in lemon-0.x for src/work/deba


Ignore:
Timestamp:
05/10/04 15:49:35 (20 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@775
Message:
 
Location:
src/work/deba
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/work/deba/main.cpp

    r571 r595  
    11#include <iostream>
     2#include <cstdlib>
    23#include "test_graph.h"
    34
     
    89int main() {
    910        ListGraph g;
    10         ListGraph::NodeMapFactory::VectorMap<int> map(g, g.node_maps);
    11         ListGraph::Node node = g.addNode();
    12         map[node] = 12;
     11        for (int i = 0; i < 3; ++i) {
     12                ListGraph::Node node = g.addNode();
     13        }
     14        ListGraph::NodeMapFactory::Map<int> map(g, g.node_maps);
     15        for (int i = 0; i < 10; ++i) {
     16                ListGraph::Node node = g.addNode();
     17                map[node] = rand()%100;
     18        }
     19        for (ListGraph::NodeIt it(g); g.valid(it); g.next(it)) {
     20                cout << map[it] << endl;
     21        }
    1322        return 0;
    1423}
  • src/work/deba/map_base.h

    r571 r595  
    22#define MAP_BASE_H
    33
     4using namespace std;
     5
    46/**
    5         Template base class for implementing mapping on nodes.
    6         \param The first template parameter is the Graph class. The Graph
    7                 must have an \emp node_maps member with \emp MapRegistry class.
    8         \param The second template parameter is the  type of the class.
    9        
     7        Template base class for implementing mapping on nodes and edges.
     8        \param The first template parameter is the Graph class.
     9        \param The second template parameter is the key type.
     10        \param The third template parameter is an iterator on
     11                the keys.
    1012*/
    1113
     
    2527                typedef G Graph;
    2628                typedef MapRegistry<G, K, KIt> Registry;
    27                 typedef K KeyType;
     29                typedef K Key;
    2830                typedef KIt KeyIt;
    2931       
     
    3436                */     
    3537               
    36                 MapBase() : registry(0) {}
     38                MapBase() : graph(0), registry(0) {}
    3739
    3840                /**
     
    4143       
    4244                MapBase(Graph& g, Registry& r) : graph(&g), registry(0) {
    43                         registry->attach(*this);
     45                        r.attach(*this);
    4446                }
    4547
     
    8183        protected:
    8284               
     85                Graph* graph;
    8386                Registry* registry;
    84                 Graph* graph;
    8587
    8688                int registry_index;
    8789       
    8890                /**
    89                         Helper function to implement the default constructor in the subclasses.
     91                        Helper function to implement constructors in the subclasses.
    9092                */
    9193       
    9294                virtual void init() {
    93 
    9495                        for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
    9596                                add(it);
     
    112113                */
    113114       
    114                 virtual void add(const KeyType&) = 0;
    115        
     115                virtual void add(const Key&) = 0;       
    116116                /**
    117117                        The erase member function should be overloaded in the subclasses.
     
    119119                */
    120120       
    121                 virtual void erase(const KeyType&) = 0;
     121                virtual void erase(const Key&) = 0;
    122122       
    123123                /**
  • src/work/deba/map_registry.h

    r571 r595  
    33
    44#include <vector>
     5
     6using namespace std;
    57
    68
     
    6365                        map.registry = this;
    6466                        map.registry_index = container.size()-1;
    65                         map.init();
    6667                }
    6768       
    68                 void detach(Map& map_base) {
    69                         map_base.destroy();
    70                         container.back()->registry_index = map_base.registry_index;
    71                         container[map_base.registry_index] = container.back();
     69                void detach(Map& map) {
     70                        container.back()->registry_index = map.registry_index;
     71                        container[map.registry_index] = container.back();
    7272                        container.pop_back();
    73                         map_base.registry = 0;
    74                         map_base.graph = 0;
     73                        map.registry = 0;
     74                        map.graph = 0;
    7575                }
    7676       
    7777               
    78                 void add(Key& key) {
     78                virtual void add(Key& key) {
    7979                        typename Container::iterator it;
    8080                        for (it = container.begin(); it != container.end(); ++it) {
     
    8383                }       
    8484               
    85                 void erase(Key& key) {
     85                virtual void erase(Key& key) {
    8686                        typename Container::iterator it;
    8787                        for (it = container.begin(); it != container.end(); ++it) {
  • src/work/deba/test_graph.h

    r571 r595  
    4242        public:
    4343       
     44                typedef MapBase<ListGraph, Node, NodeIt> NodeMapBase;
    4445                typedef MapRegistry<ListGraph, Node, NodeIt> NodeMapRegistry;
     46                typedef VectorMapFactory<ListGraph, Node, NodeIt> NodeMapFactory;
    4547                NodeMapRegistry node_maps;
    46                
    47                
     48
     49
     50
     51                typedef MapBase<ListGraph, Edge, EdgeIt> EdgeMapBase;
    4852                typedef MapRegistry<ListGraph, Edge, EdgeIt> EdgeMapRegistry;
     53                typedef VectorMapFactory<ListGraph, Edge, EdgeIt> EdgeMapFactory;
    4954                EdgeMapRegistry edge_maps;
    50 
    51                 typedef VectorMapFactory<ListGraph, Edge, EdgeIt> EdgeMapFactory;
    52                 typedef VectorMapFactory<ListGraph, Node, NodeIt> NodeMapFactory;
    5355 
    5456
  • src/work/deba/vector_map_factory.h

    r571 r595  
    33
    44#include <vector>
    5 #include <iostream>
    65
    76#include "map_base.h"
     
    2019               
    2120                template <typename V>
    22                 class VectorMap : public MapBase<G, K, KIt> {
     21                class Map : public MapBase<G, K, KIt> {
    2322                public:
    24                         typedef V ValueType;
     23                        typedef V Value;
    2524       
    26                         VectorMap() {}
     25                        Map() {}
    2726                       
    28                         VectorMap(Graph& g, MapRegistry<G, K, KIt>& r)
    29                                 : MapBase<G, K, KIt>(g, r) {}
     27                        Map(Graph& g, MapRegistry<G, K, KIt>& r)
     28                                : MapBase<G, K, KIt>(g, r) {
     29                                init();
     30                        }
     31                               
     32                        virtual ~Map() {
     33                                destroy();
     34                        }
    3035       
    3136       
    32                         ValueType& operator[](const K& key) {
     37                        Value& operator[](const K& key) {
    3338                                int id = graph->id(key);
    3439                                return container[id];
    3540                        }
    3641               
    37                         const ValueType& operator[](const K& key) const {
     42                        const Value& operator[](const K& key) const {
    3843                                int id = graph->id(key);
    3944                                return container[id];
    4045                        }
    4146       
    42                         const ValueType& get(const K& key) const {
     47                        const Value& get(const K& key) const {
    4348                                int id = graph->id(key);
    4449                                return container[id];
    4550                        }
    4651               
    47                         void set(const K& key, const ValueType& val) {
     52                        void set(const K& key, const Value& val) {
    4853                                int id = graph->id(key);
    4954                                container[id] = val;
     
    5257                        void add(const K& key) {
    5358                                int id = graph->id(key);
    54                                 std::cerr << id << std::endl;
    5559                                if (id >= container.size()) {
    5660                                        container.resize(id + 1);
     
    6165       
    6266                private:
    63                         typedef std::vector<ValueType> Container;
     67                        typedef std::vector<Value> Container;
    6468               
    6569                        Container container;
Note: See TracChangeset for help on using the changeset viewer.