Adding a new abstraction for elements: must have value
[satune.git] / src / Encoders / elementencoding.h
1 #ifndef ELEMENTENCODING_H
2 #define ELEMENTENCODING_H
3 #include "classlist.h"
4 #include "naiveencoder.h"
5 #include "constraint.h"
6
7 typedef enum ElemEnc {EENC_UNKNOWN, EENC_NONE, EENC_BOTH} ElemEnc;
8
9 class ElementEncoding {
10 public:
11         ElementEncoding(Element *element);
12         ElementEncodingType getElementEncodingType() {return type;}
13         ~ElementEncoding();
14         void setElementEncodingType(ElementEncodingType type);
15         void deleteElementEncoding();
16         void allocEncodingArrayElement(uint size);
17         void allocInUseArrayElement(uint size);
18         uint numEncodingVars() {return numVars;}
19         bool isinUseElement(uint offset) { return (inUseArray[(offset >> 6)] >> (offset & 63)) & 0x1;}
20         void setInUseElement(uint offset) {inUseArray[(offset >> 6)] |= 1 << (offset & 63);}
21         void encodingArrayInitialization();
22         uint getSizeEncodingArray(uint setSize) {
23                 switch (type) {
24                 case BINARYINDEX:
25                         return NEXTPOW2(setSize);
26                 case ONEHOT:
27                 case UNARY:
28                         return setSize;
29                 default:
30                         ASSERT(0);
31                 }
32                 return -1;
33         }
34         void print();
35
36         bool anyValue;
37         ElementEncodingType type;
38         Element *element;
39         Edge *variables;/* List Variables Used To Encode Element */
40         union {
41                 struct {
42                         uint64_t *encodingArray;        /* List the Variables in the appropriate order */
43                         uint64_t *inUseArray;   /* Bitmap to track variables in use */
44                         Edge * edgeArray;
45                         Polarity * polarityArray;
46                         uint encArraySize;
47                         ElemEnc encoding;
48                 };
49                 struct {
50                         uint64_t offset;/* Value = offset + encoded number (interpretted according to isBinaryValSigned) */
51                         uint64_t low;   /* Lowest value to encode */
52                         uint64_t high;/* High value to encode.   If low > high, we assume wrap around to include 0. */
53                         uint numBits;
54                         bool isBinaryValSigned;
55                 };
56         };
57         uint numVars;   /* Number of variables */
58         CMEMALLOC;
59 };
60
61
62
63 #endif