-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrixcoo.cpp
109 lines (83 loc) · 1.87 KB
/
matrixcoo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "matrixcoo.hpp"
#include <cassert>
#include <iostream>
template<class T>
// Standardkonstruktor
MatrixCOO<T>::MatrixCOO():
zeilen(0u), spalten(0u), data(nullptr) { };
template<class T>
// Benuterdefinierter Konstruktor
MatrixCOO<T>::MatrixCOO(unsigned long _zeilen, unsigned long _spalten) :
zeilen(_zeilen), spalten(_spalten), data(nullptr)
{
if(_zeilen > 0u && _spalten >0u)
{
k=0;
zeilenindex = new unsigned long[_zeilen*_spalten];
spaltenindex = new unsigned long[_zeilen*_spalten];
data = new T[_zeilen*_spalten];
}
}
template<class T>
// Destruktor
MatrixCOO<T>::~MatrixCOO()
{
if(data != nullptr)
delete [] data;
if(spaltenindex != nullptr)
delete [] spaltenindex;
if(zeilenindex != nullptr)
delete [] zeilenindex;
};
template<class T>
// Überladung (), Matrixeinträge
T& MatrixCOO<T>::operator()(unsigned long i, unsigned long j)
{
assert(i < zeilen);
assert(j < spalten);
assert(data != nullptr);
for(unsigned long l(0u); l<k; l++)
{
if((zeilenindex[l] == i) && (spaltenindex[l] == j))
return data[l];
}
k++;
zeilenindex[k-1]=i;
spaltenindex[k-1]=j;
return data[k-1];
}
template<class T>
// Zeilen
unsigned long MatrixCOO<T>::get_zei()
{
return zeilen;
}
template<class T>
// Spalten
unsigned long MatrixCOO<T>::get_spa()
{
return spalten;
}
template<class T>
// k
unsigned long MatrixCOO<T>::get_k()
{
return k;
}
template<class T>
unsigned long MatrixCOO<T>::get_zeilenindex(unsigned long i)
{
assert(i < k);
assert(zeilenindex != nullptr);
return zeilenindex[i];
}
template<class T>
unsigned long MatrixCOO<T>::get_spaltenindex(unsigned long i)
{
assert(i < k);
assert(spaltenindex != nullptr);
return spaltenindex[i];
}
template class MatrixCOO<double>;
template class MatrixCOO<float>;
template class MatrixCOO<int>;