-
Notifications
You must be signed in to change notification settings - Fork 0
/
VectorInt.cpp
121 lines (106 loc) · 2.21 KB
/
VectorInt.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
110
111
112
113
114
115
116
117
118
119
120
121
#include <Expressions.hpp>
#include <VectorInt.hpp>
#include <string.h>
#include <iostream>
using namespace std;
// Class Vector
//For constructors
void VectorInt::init(){
coefs = (unsigned char *)malloc(entriesNb * sizeof(char));
memset(coefs, (char)0, entriesNb * sizeof(char));
}
// First constructor
VectorInt::VectorInt()
{
init();
update_hash();
#if USE_MIN_HEURISTIC
min = 0;
#endif
}
//set Vector size
void VectorInt::SetSize(uint size)
{
if(entriesNb != size) {
int_vectors.clear();
entriesNb = size;
}
}
// Assignment operator which performs a memcopy of the field sons
VectorInt & VectorInt::operator=(const VectorInt & other) {
memcpy(coefs, other.coefs, entriesNb * sizeof(char));
_hash = other.Hash();
#if USE_MIN_HEURISTIC
min = other.min;
#endif
return *this;
}
// Second constructor
VectorInt::VectorInt(const VectorInt & other)
{
memcpy(coefs, other.coefs, entriesNb * sizeof(char));
_hash = other.Hash();
#if USE_MIN_HEURISTIC
min = other.min;
#endif
}
// Third constructor
VectorInt::VectorInt(vector<char> data)
{
init();
#if USE_MIN_HEURISTIC
min = -1;
#endif
for (int i = 0; i < data.size(); i++) {
coefs[i] = data[i];
#if USE_MIN_HEURISTIC
if(data[i] < min) min = data[i];
#endif
}
update_hash();
}
// Fourth constructor
VectorInt::VectorInt(unsigned char * data)
{
// if (copy)
{
coefs = (unsigned char *) malloc(entriesNb * sizeof(char));
memcpy(coefs, data, entriesNb * sizeof(char));
}
/* else
{
coefs = data;
}
*/
#if USE_MIN_HEURISTIC
min = -1;
for (int i = 0; i < entriesNb; i++)
if(coefs[i] < min)
min = coefs[i];
#endif
update_hash();
};
void VectorInt::print(ostream & os) const
{
// throw runtime_error("Unimplemented");
/*
for (uint i = 0; i < entriesNb; i++)
os << (contains(i) ? "1" : "0");
os << endl;
*/
}
// Number of entries
uint VectorInt::entriesNb = 0;
VectorInt::~VectorInt()
{
free(coefs);
coefs = NULL;
}
bool VectorInt::operator==(const VectorInt & vec) const
{
if (entriesNb != vec.entriesNb) return false;
for (uint i = 0; i < entriesNb; i++)
if (coefs[i] != vec.coefs[i]) return false;
return true;
}
std::unordered_set<VectorInt> int_vectors;