LCOV - code coverage report
Current view: top level - ugbase/lib_algebra/algebra_common - sparse_vector.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 5 0
Test Date: 2025-09-21 23:31:46 Functions: - 0 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2013-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Martin Rupp
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #ifndef SPARSE_VECTOR_H_
      34              : #define SPARSE_VECTOR_H_
      35              : 
      36              : #include <map>
      37              : namespace ug{
      38              : 
      39              : template<typename T>
      40            0 : class SparseVector
      41              : {
      42              :         size_t m_size;
      43              :         typedef std::map<size_t, T> container;
      44              :         container data;
      45              : public:
      46              :         typedef T value_type;
      47              :         class const_iterator : public container::const_iterator
      48              :         {
      49              :                 using container::const_iterator::operator *;
      50              :         public:
      51              :                 const_iterator(typename container::const_iterator it) : container::const_iterator(it) {}
      52            0 :                 const T &value() const { return (operator *()).second; }
      53            0 :                 size_t index() const { return (operator *()).first; }
      54              :         };
      55              : 
      56              :         class iterator : public container::iterator
      57              :         {
      58              :                 using container::iterator::operator *;
      59              :         public:
      60              :                 iterator(typename container::iterator it) : container::iterator(it) {}
      61              :                 const T &value() const { return (operator *()).second; }
      62              :                 T &value() { return (operator *())->second; }
      63              :                 size_t index() const { return (operator *()).first; }
      64              :         };
      65              : 
      66            0 :         SparseVector(size_t s) : m_size(s)
      67              :         {
      68              :         }
      69              :         const_iterator begin() const
      70              :         {
      71              :                 const_iterator c(data.begin());
      72              :                 return c;
      73              :         }
      74              :         const_iterator end() const
      75              :         {
      76              :                 return const_iterator(data.end());
      77              :         }
      78              : 
      79              :         const T &operator()(size_t c) const
      80              :         {
      81              :                 assert(c < m_size);
      82              :                 return data[c];
      83              :         }
      84              :         T &operator()(size_t c)
      85              :         {
      86              :                 assert(c < m_size);
      87            0 :                 return data[c];
      88              :         }
      89              :         bool has_connection(size_t c) const
      90              :         {
      91              :                 return data.find(c) != data.end();
      92              :         }
      93              : 
      94              :         size_t size()
      95              :         {
      96              :                 return m_size;
      97              :         }
      98              :         size_t num_connections() const
      99              :         {
     100              :                 return data.size();
     101              :         }
     102              : 
     103              :         void print() const
     104              :         {
     105              :                 for(const_iterator it=begin(); it != end(); ++it)
     106              :                 {
     107              :                         //if(BlockNorm(it.value()) == 0.0) continue;
     108              :                         UG_LOG("(" << it.index() << " -> " << it.value() << ")");
     109              :                 }
     110              : 
     111              :                 UG_LOG("\n");
     112              :         }
     113              : 
     114              : };
     115              : 
     116              : }
     117              : #endif /* SPARSE_VECTOR_H_ */
        

Generated by: LCOV version 2.0-1