[go: up one dir, main page]

Menu

[r320]: / libpetey / vector_s.cc  Maximize  Restore  History

Download this file

201 lines (174 with data), 5.1 kB

  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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <assert.h>
#include "time_class.h"
#include "vector_s.h"
//great, a "sortable" vector
namespace libpetey {
template <class type>
vector_s<type>::vector_s(int n) {
nel=n;
array_size=n;
data=new type[nel];
missing=0.;
}
template <class type>
vector_s<type>::vector_s(int n, type m) {
nel=n;
array_size=n;
data=new type[nel];
missing=m;
}
template <class type>
vector_s<type>::vector_s(type *dt, int n, int ncp_flag) {
nel=n;
array_size=n;
if (ncp_flag) {
data=dt;
} else {
data=new type[nel];
for (int i=0; i<n; i++) {
data[i]=dt[i];
}
}
}
template <class type>
vector_s<type>::~vector_s() {
delete [] data;
}
template <class type>
vector_s<type>::vector_s(vector_s<type> &other) {
delete [] data;
data=new type[other.nel];
nel=other.nel;
array_size=nel;
missing=other.missing;
for (int i=0; i<nel; i++) data[i]=other.data[i];
}
template <class type>
vector_s<type> & vector_s<type>::operator = (vector_s<type> &other) {
delete [] data;
data=new type[other.nel];
nel=other.nel;
array_size=nel;
missing=other.missing;
for (int i=0; i<nel; i++) data[i]=other.data[i];
return *this; //can this work??
}
template <class type>
type & vector_s<type>::operator [] (int ind) {
assert(ind>-1);
if (ind>=nel) {
if (ind>=array_size) {
type *newdata;
array_size=(ind/array_size+1)*array_size;
newdata=new type[array_size];
for (int i=0; i<nel; i++) newdata[i]=data[i];
for (int i=nel; i<=ind; i++) newdata[i]=missing;
delete [] data;
data=newdata;
}
nel=ind+1;
}
return data[ind];
}
template <class type>
vector_s<type> & vector_s<type>::operator + (vector_s<type> &other) {
vector_s<type> *result;
assert(nel==other.nel);
result=new vector_s<type>(nel, missing);
for (int i=0; i<nel; i++) result->data[i]=data[i]+other.data[i];
return *result; //can this work??
}
template <class type>
vector_s<type> & vector_s<type>::operator - (vector_s<type> &other) {
vector_s<type> *result;
assert(nel==other.nel);
result=new vector_s<type>(nel, missing);
for (int i=0; i<nel; i++) result->data[i]=data[i]-other.data[i];
return *result; //can this work??
}
template <class type>
vector_s<type> & vector_s<type>::operator + (type &c) {
vector_s<type> *result;
result=new vector_s<type>(nel, missing);
for (int i=0; i<nel; i++) result->data[i]=data[i]+c;
return *result; //can this work??
}
template <class type>
vector_s<type> & vector_s<type>::operator - (const type &c) {
vector_s<type> *result;
result=new vector_s<type>(nel, missing);
for (int i=0; i<nel; i++) result->data[i]=data[i]-c;
return *result; //can this work??
}
template <class type>
vector_s<type> & vector_s<type>::operator * (const double &c) {
vector_s<type> *result;
result=new vector_s<type>(nel, missing);
for (int i=0; i<nel; i++) result->data[i]=data[i]*c;
return *result; //can this work??
}
template <class type>
vector_s<type> & vector_s<type>::operator / (const double &c) {
vector_s<type> *result;
result=new vector_s<type>(nel, missing);
for (int i=0; i<nel; i++) result->data[i]=data[i]/c;
return *result; //can this work??
}
template <class type>
int vector_s<type>::operator == (vector_s<type> &other) {
assert(nel == other.nel);
for (int i=0; i<nel; i++) {
if (other.data[i] != data[i]) return 0;
}
return 1;
}
template <class type>
int vector_s<type>::operator > (vector_s<type> &other) {
assert(nel == other.nel);
for (int i=0; i<nel; i++) {
if (data[i] > other.data[i]) return 1;
else if (data[i] < other.data[i]) return 0;
}
return 0;
}
template <class type>
int vector_s<type>::operator < (vector_s<type> &other) {
assert(nel == other.nel);
for (int i=0; i<nel; i++) {
if (data[i] < other.data[i]) return 1;
else if (data[i] > other.data[i]) return 0;
}
return 0;
}
template <class type>
int vector_s<type>::operator >= (vector_s<type> &other) {
assert(nel == other.nel);
for (int i=0; i<nel; i++) {
if (data[i] > other.data[i]) return 1;
else if (data[i] < other.data[i]) return 0;
}
return 1;
}
template <class type>
int vector_s<type>::operator <= (vector_s<type> &other) {
assert(nel == other.nel);
for (int i=0; i<nel; i++) {
if (data[i] < other.data[i]) return 1;
else if (data[i] > other.data[i]) return 0;
}
return 1;
}
template <class type>
int vector_s<type>::size () {
return nel;
}
template <class type>
vector_s<type>::operator type * () {
return data;
}
template class vector_s<int32_t>;
template class vector_s<int64_t>;
template class vector_s<float>;
template class vector_s<double>;
template class vector_s<time_class>;
} //end fucking namespace libwhathisface...