lemon/matrix_maps.h
changeset 1751 a2a454f1232d
parent 1720 578d8b2b76c6
child 1757 bd4199049036
equal deleted inserted replaced
0:09d18a73361d 1:6b982be77b3e
    33 
    33 
    34   /// \brief Map for the coloumn view of the matrix
    34   /// \brief Map for the coloumn view of the matrix
    35   ///
    35   ///
    36   /// Map for the coloumn view of the matrix.
    36   /// Map for the coloumn view of the matrix.
    37   template <typename _MatrixMap>
    37   template <typename _MatrixMap>
    38   class MatrixColMap : public MapTraits<_MatrixMap> {
    38   class MatrixRowMap : public MapTraits<_MatrixMap> {
    39   public:
    39   public:
    40     typedef _MatrixMap MatrixMap;
    40     typedef _MatrixMap MatrixMap;
    41     typedef typename MatrixMap::SecondKey Key;
    41     typedef typename MatrixMap::SecondKey Key;
    42     typedef typename MatrixMap::Value Value;
    42     typedef typename MatrixMap::Value Value;
    43 
    43 
    44 
    44 
    45     MatrixColMap(MatrixMap& _matrix, typename MatrixMap::FirstKey _col) 
    45     MatrixRowMap(MatrixMap& _matrix, typename MatrixMap::FirstKey _row) 
    46       : matrix(_matrix), col(_col) {}
    46       : matrix(_matrix), row(_row) {}
    47 
    47 
    48     /// \brief Subscription operator
    48     /// \brief Subscription operator
    49     ///
    49     ///
    50     /// Subscription operator.
    50     /// Subscription operator.
    51     typename MapTraits<MatrixMap>::ReturnValue
    51     typename MapTraits<MatrixMap>::ReturnValue
    52     operator[](Key row) {
    52     operator[](Key col) {
    53       return matrix(col, row);
    53       return matrix(row, col);
    54     }
    54     }
    55 
    55 
    56     /// \brief Setter function
    56     /// \brief Setter function
    57     ///
    57     ///
    58     /// Setter function.
    58     /// Setter function.
    59     void set(Key row, const Value& val) {
    59     void set(Key col, const Value& val) {
    60       matrix.set(col, row, val);
    60       matrix.set(row, col, val);
    61     }
    61     }
    62       
    62       
    63     /// \brief Subscription operator
    63     /// \brief Subscription operator
    64     ///
    64     ///
    65     /// Subscription operator.
    65     /// Subscription operator.
    66     typename MapTraits<MatrixMap>::ConstReturnValue
    66     typename MapTraits<MatrixMap>::ConstReturnValue
    67     operator[](Key row) const {
    67     operator[](Key col) const {
    68       return matrix(col, row);
    68       return matrix(row, col);
    69     }
    69     }
    70 
    70 
    71   private:
    71   private:
    72     MatrixMap& matrix;
    72     MatrixMap& matrix;
    73     typename MatrixMap::FirstKey col;
    73     typename MatrixMap::FirstKey row;
    74   };
    74   };
    75 
    75 
    76   /// \brief Map for the coloumn view of the matrix
    76   /// \brief Map for the row view of the matrix
    77   ///
    77   ///
    78   /// Map for the coloumn view of the matrix.
    78   /// Map for the row view of the matrix.
    79   template <typename _MatrixMap>
    79   template <typename _MatrixMap>
    80   class ConstMatrixColMap : public MapTraits<_MatrixMap> {
    80   class ConstMatrixRowMap : public MapTraits<_MatrixMap> {
    81   public:
    81   public:
    82     typedef _MatrixMap MatrixMap;
    82     typedef _MatrixMap MatrixMap;
    83     typedef typename MatrixMap::SecondKey Key;
    83     typedef typename MatrixMap::SecondKey Key;
    84     typedef typename MatrixMap::Value Value;
    84     typedef typename MatrixMap::Value Value;
    85 
    85 
    86 
    86 
    87     ConstMatrixColMap(const MatrixMap& _matrix, 
    87     ConstMatrixRowMap(const MatrixMap& _matrix, 
    88 		      typename MatrixMap::FirstKey _col) 
    88 		      typename MatrixMap::FirstKey _row) 
    89       : matrix(_matrix), col(_col) {}
    89       : matrix(_matrix), row(_row) {}
    90 
    90 
    91     /// \brief Subscription operator
    91     /// \brief Subscription operator
    92     ///
    92     ///
    93     /// Subscription operator.
    93     /// Subscription operator.
    94     typename MapTraits<MatrixMap>::ConstReturnValue
    94     typename MapTraits<MatrixMap>::ConstReturnValue
    95     operator[](Key row) const {
    95     operator[](Key col) const {
    96       return matrix(col, row);
    96       return matrix(row, col);
    97     }
    97     }
    98 
    98 
    99   private:
    99   private:
   100     const MatrixMap& matrix;
   100     const MatrixMap& matrix;
   101     typename MatrixMap::FirstKey col;
   101     typename MatrixMap::FirstKey row;
   102   };
   102   };
   103 
   103 
   104   /// \brief Gives back a coloumn view of the matrix map
   104   /// \brief Gives back a row view of the matrix map
   105   ///
   105   ///
   106   /// Gives back a coloumn view of the matrix map.
   106   /// Gives back a row view of the matrix map.
   107   template <typename MatrixMap>
   107   template <typename MatrixMap>
   108   MatrixColMap<MatrixMap> matrixColMap(MatrixMap& matrixMap,
   108   MatrixRowMap<MatrixMap> matrixRowMap(MatrixMap& matrixMap,
   109 				       typename MatrixMap::FirstKey col) {
   109 				       typename MatrixMap::FirstKey row) {
   110     return MatrixColMap<MatrixMap>(matrixMap, col);
   110     return MatrixRowMap<MatrixMap>(matrixMap, row);
   111   }
   111   }
   112 
   112 
   113   template <typename MatrixMap>
   113   template <typename MatrixMap>
   114   ConstMatrixColMap<MatrixMap>
   114   ConstMatrixRowMap<MatrixMap>
   115   matrixColMap(const MatrixMap& matrixMap, typename MatrixMap::FirstKey col) {
   115   matrixRowMap(const MatrixMap& matrixMap, typename MatrixMap::FirstKey row) {
   116     return ConstMatrixColMap<MatrixMap>(matrixMap, col);
   116     return ConstMatrixRowMap<MatrixMap>(matrixMap, row);
   117   }
   117   }
   118 
   118 
   119   /// \brief Map for the row view of the matrix
   119   /// \brief Map for the row view of the matrix
   120   ///
   120   ///
   121   /// Map for the row view of the matrix.
   121   /// Map for the row view of the matrix.
   122   template <typename _MatrixMap>
   122   template <typename _MatrixMap>
   123   class MatrixRowMap : public MapTraits<_MatrixMap> {
   123   class MatrixColMap : public MapTraits<_MatrixMap> {
   124   public:
   124   public:
   125     typedef _MatrixMap MatrixMap;
   125     typedef _MatrixMap MatrixMap;
   126     typedef typename MatrixMap::FirstKey Key;
   126     typedef typename MatrixMap::FirstKey Key;
   127     typedef typename MatrixMap::Value Value;
   127     typedef typename MatrixMap::Value Value;
   128 
   128 
   129     MatrixRowMap(MatrixMap& _matrix, typename MatrixMap::SecondKey _row) 
   129     MatrixColMap(MatrixMap& _matrix, typename MatrixMap::SecondKey _col) 
   130       : matrix(_matrix), row(_row) {}
   130       : matrix(_matrix), col(_col) {}
   131 
   131 
   132     /// \brief Subscription operator
   132     /// \brief Subscription operator
   133     ///
   133     ///
   134     /// Subscription operator.
   134     /// Subscription operator.
   135     typename MapTraits<MatrixMap>::ReturnValue
   135     typename MapTraits<MatrixMap>::ReturnValue
   136     operator[](Key col) {
   136     operator[](Key row) {
   137       return matrix(col, row);
   137       return matrix(row, col);
   138     }
   138     }
   139 
   139 
   140     /// \brief Setter function
   140     /// \brief Setter function
   141     ///
   141     ///
   142     /// Setter function.
   142     /// Setter function.
   143     void set(Key col, const Value& val) {
   143     void set(Key row, const Value& val) {
   144       matrix.set(col, row, val);
   144       matrix.set(row, col, val);
   145     }
   145     }
   146       
   146       
   147     /// \brief Subscription operator
   147     /// \brief Subscription operator
   148     ///
   148     ///
   149     /// Subscription operator.
   149     /// Subscription operator.
   150     typename MapTraits<MatrixMap>::ConstReturnValue
   150     typename MapTraits<MatrixMap>::ConstReturnValue
   151     operator[](Key col) const {
   151     operator[](Key row) const {
   152       return matrix(col, row);
   152       return matrix(row, col);
   153     }
   153     }
   154 
   154 
   155   private:
   155   private:
   156     MatrixMap& matrix;
   156     MatrixMap& matrix;
   157     typename MatrixMap::SecondKey row;
   157     typename MatrixMap::SecondKey col;
   158   };
   158   };
   159 
   159 
   160   /// \brief Map for the row view of the matrix
   160   /// \brief Map for the col view of the matrix
   161   ///
   161   ///
   162   /// Map for the row view of the matrix.
   162   /// Map for the col view of the matrix.
   163   template <typename _MatrixMap>
   163   template <typename _MatrixMap>
   164   class ConstMatrixRowMap : public MapTraits<_MatrixMap> {
   164   class ConstMatrixColMap : public MapTraits<_MatrixMap> {
   165   public:
   165   public:
   166     typedef _MatrixMap MatrixMap;
   166     typedef _MatrixMap MatrixMap;
   167     typedef typename MatrixMap::FirstKey Key;
   167     typedef typename MatrixMap::FirstKey Key;
   168     typedef typename MatrixMap::Value Value;
   168     typedef typename MatrixMap::Value Value;
   169 
   169 
   170     ConstMatrixRowMap(const MatrixMap& _matrix, 
   170     ConstMatrixColMap(const MatrixMap& _matrix, 
   171 		      typename MatrixMap::SecondKey _row) 
   171 		      typename MatrixMap::SecondKey _col) 
   172       : matrix(_matrix), row(_row) {}
   172       : matrix(_matrix), col(_col) {}
   173 
   173 
   174     /// \brief Subscription operator
   174     /// \brief Subscription operator
   175     ///
   175     ///
   176     /// Subscription operator.
   176     /// Subscription operator.
   177     typename MapTraits<MatrixMap>::ConstReturnValue
   177     typename MapTraits<MatrixMap>::ConstReturnValue
   178     operator[](Key col) const {
   178     operator[](Key row) const {
   179       return matrix(col, row);
   179       return matrix(row, col);
   180     }
   180     }
   181 
   181 
   182   private:
   182   private:
   183     const MatrixMap& matrix;
   183     const MatrixMap& matrix;
   184     typename MatrixMap::SecondKey row;
   184     typename MatrixMap::SecondKey col;
   185   };
   185   };
   186 
   186 
   187   /// \brief Gives back a row view of the matrix map
   187   /// \brief Gives back a col view of the matrix map
   188   ///
   188   ///
   189   /// Gives back a row view of the matrix map.
   189   /// Gives back a col view of the matrix map.
   190   template <typename MatrixMap>
   190   template <typename MatrixMap>
   191   MatrixRowMap<MatrixMap> matrixRowMap(MatrixMap& matrixMap,
   191   MatrixColMap<MatrixMap> matrixColMap(MatrixMap& matrixMap,
   192 				       typename MatrixMap::SecondKey row) {
   192 				       typename MatrixMap::SecondKey col) {
   193     return MatrixRowMap<MatrixMap>(matrixMap, row);
   193     return MatrixColMap<MatrixMap>(matrixMap, col);
   194   }
   194   }
   195 
   195 
   196   template <typename MatrixMap>
   196   template <typename MatrixMap>
   197   ConstMatrixRowMap<MatrixMap> 
   197   ConstMatrixColMap<MatrixMap> 
   198   matrixRowMap(const MatrixMap& matrixMap, typename MatrixMap::SecondKey row) {
   198   matrixColMap(const MatrixMap& matrixMap, typename MatrixMap::SecondKey col) {
   199     return ConstMatrixRowMap<MatrixMap>(matrixMap, row);
   199     return ConstMatrixColMap<MatrixMap>(matrixMap, col);
   200   }
   200   }
   201 
   201 
   202   /// \brief Container for store values for each ordered pair of graph items
   202   /// \brief Container for store values for each ordered pair of graph items
   203   ///
   203   ///
   204   /// This data structure can strore for each pairs of the same item
   204   /// This data structure can strore for each pairs of the same item