Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
unsorted_sparse_vector.h
Go to the documentation of this file.
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 UNSORTED_VECTOR_H_
34#define UNSORTED_VECTOR_H_
35
36#include <vector>
37#include "connection.h"
38
39namespace ug{
40
58template<typename TValue>
60{
61public:
62 typedef TValue value_type;
64
65 typedef typename std::vector<connection>::iterator iterator;
66 typedef typename std::vector<connection>::const_iterator const_iterator;
67
68private:
69 std::vector<int> posInConnections;
70 std::vector<connection > con;
71 size_t m_size;
72public:
73
75 {
76 con.reserve(32);
77 }
79 {
80 return con.begin();
81 }
83 {
84 return con.end();
85 }
87 {
88 return con.begin();
89 }
91 {
92 return con.end();
93 }
94
95 size_t num_connections() const
96 {
97 return con.size();
98 }
99
100 size_t size() const
101 {
102 return m_size;
103 }
104
106 {
107 return &con[0];
108 }
109
110
111 void clear()
112 {
113 for(size_t i=0; i<con.size(); i++)
114 posInConnections[con[i].iIndex] = -1;
115 con.clear();
116 }
117
118 const value_type &operator()(size_t c) const
119 {
120 assert(c < m_size);
121 int p = posInConnections[c];
122 if(p != -1)
123 return con[p].value();
124 else
125 assert(0 && "const_and_not_available");
126 }
128 {
129 assert(c < m_size);
130 int p = posInConnections[c];
131 if(p != -1)
132 return con[p].value();
133 else
134 {
135 p = posInConnections[c] = con.size();
136 con.push_back(connection(c, TValue(0)));
137 return con[p].value();
138 }
139 }
140 bool has_connection(size_t c) const
141 {
142 assert(c < m_size);
143 return posInConnections[c] != -1;
144 }
145};
146
147
148}
149#endif /* UNSORTED_VECTOR_H_ */
parameterString p
parameterString s
Definition connection.h:40
Definition unsorted_sparse_vector.h:60
size_t num_connections() const
Definition unsorted_sparse_vector.h:95
void clear()
Definition unsorted_sparse_vector.h:111
std::vector< connection >::const_iterator const_iterator
Definition unsorted_sparse_vector.h:66
AlgebraicConnection< TValue > connection
Definition unsorted_sparse_vector.h:63
const_iterator end() const
Definition unsorted_sparse_vector.h:90
value_type & operator()(size_t c)
Definition unsorted_sparse_vector.h:127
UnsortedSparseVector(size_t s)
Definition unsorted_sparse_vector.h:74
std::vector< connection >::iterator iterator
Definition unsorted_sparse_vector.h:65
iterator end()
Definition unsorted_sparse_vector.h:82
std::vector< int > posInConnections
Definition unsorted_sparse_vector.h:69
std::vector< connection > con
Definition unsorted_sparse_vector.h:70
size_t m_size
Definition unsorted_sparse_vector.h:71
size_t size() const
Definition unsorted_sparse_vector.h:100
const_iterator begin() const
Definition unsorted_sparse_vector.h:86
bool has_connection(size_t c) const
Definition unsorted_sparse_vector.h:140
iterator begin()
Definition unsorted_sparse_vector.h:78
connection * unsorted_raw_ptr()
Definition unsorted_sparse_vector.h:105
const value_type & operator()(size_t c) const
Definition unsorted_sparse_vector.h:118
TValue value_type
Definition unsorted_sparse_vector.h:62
the ug namespace