00001 /* 00002 * Copyright 2007 Martin von Gagern 00003 * 00004 * 00005 * This file is part of mqn2mps. 00006 * 00007 * mqn2mps is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * mqn2mps is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 00022 #ifndef TRIPLET_HH 00023 #define TRIPLET_HH 00024 00025 /** 00026 * @file 00027 * Interface and implementation of class triplet. 00028 */ 00029 00030 /** 00031 * Verbose description of a matrix element. 00032 * 00033 * A triplet consists of row and column indices in a matrix together 00034 * with the value of the corresponding matrix cell. As the full 00035 * position information is part of the object, a triplet can describe 00036 * a matrix element all by itself, and an unordered collection of 00037 * triplets with unique addresses can describe all nonzero entries of 00038 * a matrix. 00039 * 00040 * @see make_triplet() 00041 */ 00042 template<class T> class triplet { 00043 public: 00044 00045 /** 00046 * The row index inside the matrix. 00047 */ 00048 int row; 00049 00050 /** 00051 * The column index inside the matrix. 00052 */ 00053 int col; 00054 00055 /** 00056 * The value of the matrix element at the specified position. 00057 */ 00058 T val; 00059 00060 /** 00061 * Default constructor. 00062 */ 00063 triplet() : row(0), col(0), val(0) { } 00064 00065 /** 00066 * Full constructor. 00067 * 00068 * @param r the row index. 00069 * @param c the column index. 00070 * @param v the value. 00071 */ 00072 triplet(int r, int c, T v) : row(r), col(c), val(v) { } 00073 00074 /** 00075 * Lexicographical comparison of triplets. 00076 * @param t the second triplet with which this one is to be 00077 * compared. 00078 * @return whether this triplet is lexicographically less than 00079 * @e t. 00080 */ 00081 bool operator<(const triplet& t) const { 00082 if (row != t.row) return row < t.row; 00083 if (col != t.col) return col < t.col; 00084 return val < t.val; 00085 } 00086 00087 }; 00088 00089 /** 00090 * Templated generation of triplet objects. 00091 * 00092 * Using this method instead of the constructor triplet::triplet, the 00093 * type of the triplet to be created can be derived from the type of 00094 * the value argument. Therefore no template types have to be given, 00095 * which leads to shorter code. This is similar to std::make_pair(). 00096 * 00097 * @param row the row index. 00098 * @param col the column index. 00099 * @param val the value. 00100 */ 00101 template<class T> inline triplet<T> make_triplet(int row, int col, T val) { 00102 return triplet<T>(row, col, val); 00103 } 00104 00105 #endif // ifndef TRIPLET_HH
1.6.0