-
Notifications
You must be signed in to change notification settings - Fork 0
/
VectorUInt.cpp
83 lines (71 loc) · 1.44 KB
/
VectorUInt.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
#include <Expressions.hpp>
#include <VectorUInt.hpp>
#include <string.h>
#include <iostream>
using namespace std;
// Class VectorUInt
//For constructors
void VectorUInt::init(){
coefs = (uint *)malloc(entriesNb * sizeof(uint));
memset(coefs, (uint)0, entriesNb * sizeof(uint));
update_hash();
}
// First constructor
VectorUInt::VectorUInt()
{
init();
}
// Second constructor
VectorUInt::VectorUInt(const VectorUInt & other)
{
memcpy(coefs, other.coefs, entriesNb * sizeof(uint));
_hash = other.Hash();
id=other.id;
}
// Third constructor
VectorUInt::VectorUInt(vector<uint> data,uint k)
{
init();
id=k;
for (int i = data.size() - 1; i >= 0; i--)
coefs[i] = data[i];
update_hash();
}
// Fourth constructor
VectorUInt::VectorUInt(uint * data, uint k,bool copy)
{
id=k;
if (copy)
{
coefs = (uint *)malloc(entriesNb * sizeof(uint));
memcpy(coefs, data, entriesNb * sizeof(uint));
}
else
{
coefs = data;
}
update_hash();
};
void VectorUInt::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 VectorUInt::entriesNb = 0;
VectorUInt::~VectorUInt()
{
free(coefs);
coefs = NULL;
}
bool VectorUInt::operator==(const VectorUInt & 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;
}