Changeset 1751:a2a454f1232d in lemon0.x
 Timestamp:
 11/02/05 16:24:38 (14 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@2280
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

lemon/matrix_maps.h
r1720 r1751 36 36 /// Map for the coloumn view of the matrix. 37 37 template <typename _MatrixMap> 38 class Matrix ColMap : public MapTraits<_MatrixMap> {38 class MatrixRowMap : public MapTraits<_MatrixMap> { 39 39 public: 40 40 typedef _MatrixMap MatrixMap; … … 43 43 44 44 45 Matrix ColMap(MatrixMap& _matrix, typename MatrixMap::FirstKey _col)46 : matrix(_matrix), col(_col) {}45 MatrixRowMap(MatrixMap& _matrix, typename MatrixMap::FirstKey _row) 46 : matrix(_matrix), row(_row) {} 47 47 48 48 /// \brief Subscription operator … … 50 50 /// Subscription operator. 51 51 typename MapTraits<MatrixMap>::ReturnValue 52 operator[](Key row) {53 return matrix( col, row);52 operator[](Key col) { 53 return matrix(row, col); 54 54 } 55 55 … … 57 57 /// 58 58 /// Setter function. 59 void set(Key row, const Value& val) {60 matrix.set( col, row, val);59 void set(Key col, const Value& val) { 60 matrix.set(row, col, val); 61 61 } 62 62 … … 65 65 /// Subscription operator. 66 66 typename MapTraits<MatrixMap>::ConstReturnValue 67 operator[](Key row) const {68 return matrix( col, row);67 operator[](Key col) const { 68 return matrix(row, col); 69 69 } 70 70 71 71 private: 72 72 MatrixMap& matrix; 73 typename MatrixMap::FirstKey col;74 }; 75 76 /// \brief Map for the coloumnview of the matrix77 /// 78 /// Map for the coloumnview of the matrix.73 typename MatrixMap::FirstKey row; 74 }; 75 76 /// \brief Map for the row view of the matrix 77 /// 78 /// Map for the row view of the matrix. 79 79 template <typename _MatrixMap> 80 class ConstMatrix ColMap : public MapTraits<_MatrixMap> {80 class ConstMatrixRowMap : public MapTraits<_MatrixMap> { 81 81 public: 82 82 typedef _MatrixMap MatrixMap; … … 85 85 86 86 87 ConstMatrix ColMap(const MatrixMap& _matrix,88 typename MatrixMap::FirstKey _ col)89 : matrix(_matrix), col(_col) {}87 ConstMatrixRowMap(const MatrixMap& _matrix, 88 typename MatrixMap::FirstKey _row) 89 : matrix(_matrix), row(_row) {} 90 90 91 91 /// \brief Subscription operator … … 93 93 /// Subscription operator. 94 94 typename MapTraits<MatrixMap>::ConstReturnValue 95 operator[](Key row) const {96 return matrix( col, row);95 operator[](Key col) const { 96 return matrix(row, col); 97 97 } 98 98 99 99 private: 100 100 const MatrixMap& matrix; 101 typename MatrixMap::FirstKey col;102 }; 103 104 /// \brief Gives back a coloumnview of the matrix map105 /// 106 /// Gives back a coloumnview of the matrix map.101 typename MatrixMap::FirstKey row; 102 }; 103 104 /// \brief Gives back a row view of the matrix map 105 /// 106 /// Gives back a row view of the matrix map. 107 107 template <typename MatrixMap> 108 Matrix ColMap<MatrixMap> matrixColMap(MatrixMap& matrixMap,109 typename MatrixMap::FirstKey col) {110 return Matrix ColMap<MatrixMap>(matrixMap, col);108 MatrixRowMap<MatrixMap> matrixRowMap(MatrixMap& matrixMap, 109 typename MatrixMap::FirstKey row) { 110 return MatrixRowMap<MatrixMap>(matrixMap, row); 111 111 } 112 112 113 113 template <typename MatrixMap> 114 ConstMatrix ColMap<MatrixMap>115 matrix ColMap(const MatrixMap& matrixMap, typename MatrixMap::FirstKey col) {116 return ConstMatrix ColMap<MatrixMap>(matrixMap, col);114 ConstMatrixRowMap<MatrixMap> 115 matrixRowMap(const MatrixMap& matrixMap, typename MatrixMap::FirstKey row) { 116 return ConstMatrixRowMap<MatrixMap>(matrixMap, row); 117 117 } 118 118 … … 121 121 /// Map for the row view of the matrix. 122 122 template <typename _MatrixMap> 123 class Matrix RowMap : public MapTraits<_MatrixMap> {123 class MatrixColMap : public MapTraits<_MatrixMap> { 124 124 public: 125 125 typedef _MatrixMap MatrixMap; … … 127 127 typedef typename MatrixMap::Value Value; 128 128 129 Matrix RowMap(MatrixMap& _matrix, typename MatrixMap::SecondKey _row)130 : matrix(_matrix), row(_row) {}129 MatrixColMap(MatrixMap& _matrix, typename MatrixMap::SecondKey _col) 130 : matrix(_matrix), col(_col) {} 131 131 132 132 /// \brief Subscription operator … … 134 134 /// Subscription operator. 135 135 typename MapTraits<MatrixMap>::ReturnValue 136 operator[](Key col) {137 return matrix( col, row);136 operator[](Key row) { 137 return matrix(row, col); 138 138 } 139 139 … … 141 141 /// 142 142 /// Setter function. 143 void set(Key col, const Value& val) {144 matrix.set( col, row, val);143 void set(Key row, const Value& val) { 144 matrix.set(row, col, val); 145 145 } 146 146 … … 149 149 /// Subscription operator. 150 150 typename MapTraits<MatrixMap>::ConstReturnValue 151 operator[](Key col) const {152 return matrix( col, row);151 operator[](Key row) const { 152 return matrix(row, col); 153 153 } 154 154 155 155 private: 156 156 MatrixMap& matrix; 157 typename MatrixMap::SecondKey row;158 }; 159 160 /// \brief Map for the rowview of the matrix161 /// 162 /// Map for the rowview of the matrix.157 typename MatrixMap::SecondKey col; 158 }; 159 160 /// \brief Map for the col view of the matrix 161 /// 162 /// Map for the col view of the matrix. 163 163 template <typename _MatrixMap> 164 class ConstMatrix RowMap : public MapTraits<_MatrixMap> {164 class ConstMatrixColMap : public MapTraits<_MatrixMap> { 165 165 public: 166 166 typedef _MatrixMap MatrixMap; … … 168 168 typedef typename MatrixMap::Value Value; 169 169 170 ConstMatrix RowMap(const MatrixMap& _matrix,171 typename MatrixMap::SecondKey _ row)172 : matrix(_matrix), row(_row) {}170 ConstMatrixColMap(const MatrixMap& _matrix, 171 typename MatrixMap::SecondKey _col) 172 : matrix(_matrix), col(_col) {} 173 173 174 174 /// \brief Subscription operator … … 176 176 /// Subscription operator. 177 177 typename MapTraits<MatrixMap>::ConstReturnValue 178 operator[](Key col) const {179 return matrix( col, row);178 operator[](Key row) const { 179 return matrix(row, col); 180 180 } 181 181 182 182 private: 183 183 const MatrixMap& matrix; 184 typename MatrixMap::SecondKey row;185 }; 186 187 /// \brief Gives back a rowview of the matrix map188 /// 189 /// Gives back a rowview of the matrix map.184 typename MatrixMap::SecondKey col; 185 }; 186 187 /// \brief Gives back a col view of the matrix map 188 /// 189 /// Gives back a col view of the matrix map. 190 190 template <typename MatrixMap> 191 Matrix RowMap<MatrixMap> matrixRowMap(MatrixMap& matrixMap,192 typename MatrixMap::SecondKey row) {193 return Matrix RowMap<MatrixMap>(matrixMap, row);191 MatrixColMap<MatrixMap> matrixColMap(MatrixMap& matrixMap, 192 typename MatrixMap::SecondKey col) { 193 return MatrixColMap<MatrixMap>(matrixMap, col); 194 194 } 195 195 196 196 template <typename MatrixMap> 197 ConstMatrix RowMap<MatrixMap>198 matrix RowMap(const MatrixMap& matrixMap, typename MatrixMap::SecondKey row) {199 return ConstMatrix RowMap<MatrixMap>(matrixMap, row);197 ConstMatrixColMap<MatrixMap> 198 matrixColMap(const MatrixMap& matrixMap, typename MatrixMap::SecondKey col) { 199 return ConstMatrixColMap<MatrixMap>(matrixMap, col); 200 200 } 201 201 
test/matrix_maps_test.cc
r1728 r1751 54 54 matrix.set(it, jt, val); 55 55 check(matrix(it, jt) == val, "Wrong assign"); 56 check(matrix(it, jt) == matrix ColMap(matrix, it)[jt], "Wrong colMap");57 check(matrix(it, jt) == matrix RowMap(matrix, jt)[it], "Wrong rowMap");56 check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap"); 57 check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap"); 58 58 } 59 59 } … … 61 61 for (Graph::NodeIt it(graph); it != INVALID; ++it) { 62 62 for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { 63 check(cm(it, jt) == matrix ColMap(cm, it)[jt], "Wrong colMap");64 check(cm(it, jt) == matrix RowMap(cm, jt)[it], "Wrong rowMap");63 check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap"); 64 check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap"); 65 65 } 66 66 } … … 96 96 check(matrix(it, jt) == val, "Wrong assign"); 97 97 check(matrix(jt, it) == val, "Wrong assign"); 98 check(matrix(it, jt) == matrix ColMap(matrix, it)[jt], "Wrong colMap");99 check(matrix(it, jt) == matrix RowMap(matrix, jt)[it], "Wrong rowMap");98 check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap"); 99 check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap"); 100 100 } 101 101 } … … 103 103 for (Graph::NodeIt it(graph); it != INVALID; ++it) { 104 104 for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { 105 check(cm(it, jt) == matrix ColMap(cm, it)[jt], "Wrong colMap");106 check(cm(it, jt) == matrix RowMap(cm, jt)[it], "Wrong rowMap");105 check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap"); 106 check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap"); 107 107 } 108 108 }
Note: See TracChangeset
for help on using the changeset viewer.