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