66a97d08602672d2eed1390f4788b7b50249bfa0
[satune.git] / src / Encoders / elementencoding.cc
1 #include "elementencoding.h"
2 #include "common.h"
3 #include "naiveencoder.h"
4 #include "element.h"
5 #include "satencoder.h"
6 #include "set.h"
7
8 ElementEncoding::ElementEncoding(Element *_element) :
9         type(ELEM_UNASSIGNED),
10         element(_element),
11         variables(NULL),
12         encodingArray(NULL),
13         inUseArray(NULL),
14         encArraySize(0),
15         numVars(0) {
16 }
17
18 ElementEncoding::~ElementEncoding() {
19         if (variables != NULL)
20                 ourfree(variables);
21         if (encodingArray != NULL)
22                 ourfree(encodingArray);
23         if (inUseArray != NULL)
24                 ourfree(inUseArray);
25 }
26
27 void ElementEncoding::allocEncodingArrayElement(uint size) {
28         encodingArray = (uint64_t *) ourcalloc(1, sizeof(uint64_t) * size);
29         encArraySize = size;
30 }
31
32 void ElementEncoding::allocInUseArrayElement(uint size) {
33         uint bytes = ((size + ((1 << 9) - 1)) >> 6) & ~7;//Depends on size of inUseArray
34         inUseArray = (uint64_t *) ourcalloc(1, bytes);
35 }
36
37 void ElementEncoding::setElementEncodingType(ElementEncodingType _type) {
38         type = _type;
39 }
40
41 void ElementEncoding::encodingArrayInitialization() {
42         Set *set = element->getRange();
43         uint size = set->getSize();
44         uint encSize = getSizeEncodingArray(size);
45         allocEncodingArrayElement(encSize);
46         allocInUseArrayElement(encSize);
47         for (uint i = 0; i < size; i++) {
48                 encodingArray[i] = set->getMemberAt(i);
49                 setInUseElement(i);
50         }
51 }