src/hugo/sym_map.h
changeset 857 4e948fd205f7
parent 822 88226d9fe821
child 891 74589d20dbc3
equal deleted inserted replaced
0:7e3edaee188a 1:eb79dca0b453
    15   /** The SymEdgeIt is wrapper class for the EdgeIt. It can be used to
    15   /** The SymEdgeIt is wrapper class for the EdgeIt. It can be used to
    16    *  iterate on the symmetric maps when all of the edge - reverse edge pair
    16    *  iterate on the symmetric maps when all of the edge - reverse edge pair
    17    *  has different parity.
    17    *  has different parity.
    18    */
    18    */
    19 
    19 
       
    20 
    20   template <typename Graph, typename Edge, typename EdgeIt>
    21   template <typename Graph, typename Edge, typename EdgeIt>
    21   class SymEdgeIt : public EdgeIt {
    22   class SymEdgeIt : public EdgeIt {
    22   public:
    23   public:
    23 
    24 
    24     /** Default constructor.
    25     /** Default constructor.
    28 
    29 
    29     /** Graph initialized constructor.
    30     /** Graph initialized constructor.
    30      */
    31      */
    31     SymEdgeIt(const Graph& graph) 
    32     SymEdgeIt(const Graph& graph) 
    32       : EdgeIt(graph) {
    33       : EdgeIt(graph) {
    33       while ( (n & 1) && n != -1) {
    34       while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
    34 	EdgeIt::operator++();
    35 	EdgeIt::operator++();
    35       }
    36       }
    36     }
    37     }
    37 
    38 
    38     /** Creating invelid SymEdgeIt.
    39     /** Creating invelid SymEdgeIt.
    42 
    43 
    43     /** SymEdgeIt from the given Edge.
    44     /** SymEdgeIt from the given Edge.
    44      */
    45      */
    45     SymEdgeIt(const Graph& graph, const Edge& edge)
    46     SymEdgeIt(const Graph& graph, const Edge& edge)
    46       : EdgeIt(graph, edge) {
    47       : EdgeIt(graph, edge) {
    47       while ( (n & 1) && n != -1) {
    48       while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
    48 	EdgeIt::operator++();
    49 	EdgeIt::operator++();
    49       }
    50       }
    50     }
    51     }
    51 
    52 
    52     /** Increase operator.
    53     /** Increase operator.
    53      */
    54      */
    54     SymEdgeIt& operator++() {
    55     SymEdgeIt& operator++() {
    55       EdgeIt::operator++();
    56       EdgeIt::operator++();
    56       while ( (n & 1) && n != -1) {
    57       while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
    57 	EdgeIt::operator++();
    58 	EdgeIt::operator++();
    58       }
    59       }
    59       return *this;
    60       return *this;
    60     }
    61     }
    61   };
    62   };
   119     template <typename CMap> SymMap& operator=(const CMap& copy) {
   120     template <typename CMap> SymMap& operator=(const CMap& copy) {
   120       MapImpl::operator=(copy);
   121       MapImpl::operator=(copy);
   121       return *this;
   122       return *this;
   122     }
   123     }
   123    
   124    
   124     /**
       
   125      * The subscript operator. The map can be subscripted by the
       
   126      * actual keys of the graph. 
       
   127      */
       
   128     typename MapImpl::ReferenceType operator[](const KeyType& key) {
       
   129       int id = MapImpl::getGraph()->id(key);	
       
   130       return MapImpl::operator[](id >> 1);
       
   131     } 
       
   132 		
       
   133     /**
       
   134      * The const subscript operator. The map can be subscripted by the
       
   135      * actual keys of the graph. 
       
   136      */
       
   137     typename MapImpl::ConstReferenceType operator[](const KeyType& key) const {
       
   138       int id = MapImpl::getGraph()->id(key);
       
   139       return MapImpl::operator[](id >> 1);
       
   140     }
       
   141 	
       
   142     /** Setter function of the map. Equivalent with map[key] = val.
       
   143      *  This is a compatibility feature with the not dereferable maps.
       
   144      */
       
   145     void set(const KeyType& key, const typename MapImpl::ValueType& val) {
       
   146       int id = MapImpl::getGraph()->id(key);
       
   147       MapImpl::operator[](id >> 1) = val;
       
   148     }
       
   149 		
       
   150     /** Add a new key to the map. It called by the map registry.
   125     /** Add a new key to the map. It called by the map registry.
   151      */
   126      */
   152     void add(const KeyType& key) {
   127     void add(const KeyType& key) {
   153       int id = MapImpl::getGraph()->id(key);
   128       int id = MapImpl::getGraph()->id(key);
   154       if (id & 1) return;
   129       if (id & 1) return;