00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Robot Group Leipzig * 00003 * martius@informatik.uni-leipzig.de * 00004 * fhesse@informatik.uni-leipzig.de * 00005 * der@informatik.uni-leipzig.de * 00006 * guettler@informatik.uni-leipzig.de * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the * 00020 * Free Software Foundation, Inc., * 00021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00022 *************************************************************************** 00023 * * 00024 * DESCRIPTION * 00025 * sparse matrix: Elements are stored in a HashTable 00026 * * 00027 * * 00028 * $Log: sparsematrix.h,v $ 00029 * Revision 1.1 2009/08/03 08:33:36 guettler 00030 * SparseMatrix as a subclass of SparseArray. 00031 * Uses a hashmap for matrix elements. 00032 * first (and fast) implemented version. 00033 * * 00034 * * 00035 **************************************************************************/ 00036 #ifndef __SPARSEMATRIX_H_ 00037 #define __SPARSEMATRIX_H_ 00038 00039 #include "sparsearray.h" 00040 00041 namespace matrix 00042 { 00043 00044 /** 00045 * sparse matrix which uses an HashTable 00046 * first (fast implemented) version 00047 * @author guettler 00048 */ 00049 template<typename I, typename D> class SparseMatrix : public matrix::SparseArray<I, D> 00050 { 00051 public: 00052 SparseMatrix(I m, I n) : SparseArray<I, D>(m*n), m(m), n(n) {} 00053 00054 virtual ~SparseMatrix() {} 00055 00056 virtual inline D val(I row, I column) const { return (*this)[row*m+column]; } 00057 00058 virtual inline D& val(I row, I column) { return (*this)[row*m+column]; } 00059 00060 virtual inline I getM() { return m; } 00061 virtual inline I getN() { return n; } 00062 00063 protected: 00064 I m; 00065 I n; 00066 }; 00067 00068 } 00069 00070 #ifdef UNITTEST 00071 #include "sparsematrix.tests.hpp" 00072 #endif 00073 00074 #endif /* __SPARSEMATRIX_H_ */