-
Notifications
You must be signed in to change notification settings - Fork 0
/
VectorInt.hpp
119 lines (83 loc) · 2.28 KB
/
VectorInt.hpp
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
#ifndef VECTORR_INT_HPP
#define VECTORR_INT_HPP
#include <unordered_set>
#include <vector>
#include <set>
class VectorInt;
//The Min Heuristic consists in recording the minimal element in each vector and using it
//for speeding up vector scalr poduct:
//if the minimum is reached during the product then the loop stops
#define USE_MIN_HEURISTIC 0
// Class of vectors
class VectorInt
{
public:
//set Vector size
static void SetSize(uint size);
static uint GetStateNb()
{
return entriesNb;
}
// Entries is an array containing integers whose first entriesNb bits encode the entries
// thus the array size is the smallest integer larger than entriesNb / (sizeof(uint) * 8)
unsigned char * coefs;
#if USE_MIN_HEURISTIC
//the minimum
unsigned char min;
#endif
// bool contains(size_t n) const { return ( bits[n / (sizeof(uint) * 8)] & (1 << (n % (sizeof(uint) * 8)) ) ) != 0; };
// Second constructor: copy constructor
VectorInt(const VectorInt & other);
// Third constructor
VectorInt(std::vector<char> data);
//copy the data
VectorInt(unsigned char * data);
// Function returning the hash
size_t Hash() const { return _hash; };
// Equality operator
bool operator == (const VectorInt & vec) const;
// Free a useless vector
~VectorInt();
// Print
void print(std::ostream& os) const;
protected:
// Construct new vector, size is fixed by set_size
VectorInt();
// Number of entries
static uint entriesNb;
// Hash
size_t _hash;
static std::hash <std::vector <bool> > hash_val;
// Function computing the hash
void update_hash(){
_hash = 0;
for (unsigned char * index = coefs; index != coefs + entriesNb; index++)
_hash ^= std::hash_value(*index) + 0x9e3779b9 + (_hash << 6) + (_hash >> 2);
};
// Initialization of content
void init();
private:
// Affecttaion operator
VectorInt & operator=(const VectorInt & other);
};
/* Defines default hash for the class of Vector */
namespace std
{
template <> struct hash < const VectorInt >
{
size_t operator()(const VectorInt & vec) const
{
return vec.Hash();
}
};
template <> struct hash < VectorInt >
{
size_t operator()(const VectorInt & vec) const
{
return vec.Hash();
}
};
}
/* the set of all vectors */
extern std::unordered_set<VectorInt> int_vectors;
#endif