[go: up one dir, main page]

Menu

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

Download this file

87 lines (73 with data), 2.0 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
#include <assert.h>
#include "vector_s.h"
//great, a "sortable" vector
namespace libpetey {
template <class type>
vector_s<type>::vector_s(int n) {
nel=n;
data=new float[nel];
}
template <class type>
vector_s<type>::vector_s(type *dt, int n, int ncp_flag) {
nel=n;
if (ncp_flag) {
data=&dt;
} else {
data=new float[nel];
for (int i=0; i<n; i++) {
(*data)[i]=dt[i];
}
}
}
template <class type>
vector_s<type>::~vector_s() {
}
template <class type>
type & vector_s<type>::operator [] (int ind) {
return (*data)[ind];
}
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;
}
} //end fucking namespace libwhathisface...