c0f0d2d9e774270d30ee4c934fad0d23e91aa627
[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 enum ElementEncodingType {
8         ELEM_UNASSIGNED, ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
9 };
10
11 typedef enum ElementEncodingType ElementEncodingType;
12
13 struct ElementEncoding {
14         ElementEncodingType type;
15         Element *element;
16         Edge *variables;/* List Variables Used To Encode Element */
17         union {
18                 struct {
19                         uint64_t *encodingArray;        /* List the Variables in the appropriate order */
20                         uint64_t *inUseArray;   /* Bitmap to track variables in use */
21                         uint encArraySize;
22                 };
23                 struct {
24                         uint64_t offset;/* Value = offset + encoded number (interpretted according to isBinaryValSigned) */
25                         uint64_t low;/* Lowest value to encode */
26                         uint64_t high;/* High value to encode.   If low > high, we assume wrap around to include 0. */
27                         uint numBits;
28                         bool isBinaryValSigned;
29                 };
30         };
31         uint numVars;   /* Number of variables */
32 };
33
34 void initElementEncoding(ElementEncoding *This, Element *element);
35 static inline ElementEncodingType getElementEncodingType(ElementEncoding *This) {return This->type;}
36 void setElementEncodingType(ElementEncoding *This, ElementEncodingType type);
37 void deleteElementEncoding(ElementEncoding *This);
38 void allocEncodingArrayElement(ElementEncoding *This, uint size);
39 void allocInUseArrayElement(ElementEncoding *This, uint size);
40 static inline uint numEncodingVars(ElementEncoding *This) {return This->numVars;}
41
42 static inline bool isinUseElement(ElementEncoding *This, uint offset) {
43         return (This->inUseArray[(offset >> 6)] >> (offset & 63)) & 0x1;
44 }
45
46 static inline void setInUseElement(ElementEncoding *This, uint offset) {
47         This->inUseArray[(offset >> 6)] |= 1 << (offset & 63);
48 }
49
50 #endif