Merge branch 'encoding'
[satune.git] / src / Encoders / elementencoding.h
index eb20f2b865853a948626f3033e861a092b667df0..6797c66bf530b9024fba0fd3627f43643799ce04 100644 (file)
@@ -1,21 +1,57 @@
 #ifndef ELEMENTENCODING_H
 #define ELEMENTENCODING_H
 #include "classlist.h"
+#include "naiveencoder.h"
+#include "constraint.h"
 
-enum ElementEncodingType {
-       ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
-};
+class ElementEncoding {
+public:
+       ElementEncoding(Element *element);
+       ElementEncodingType getElementEncodingType() {return type;}
+       ~ElementEncoding();
+       void setElementEncodingType(ElementEncodingType type);
+       void deleteElementEncoding();
+       void allocEncodingArrayElement(uint size);
+       void allocInUseArrayElement(uint size);
+       uint numEncodingVars() {return numVars;}
+       bool isinUseElement(uint offset) { return (inUseArray[(offset >> 6)] >> (offset & 63)) & 0x1;}
+       void setInUseElement(uint offset) {inUseArray[(offset >> 6)] |= 1 << (offset & 63);}
+       void encodingArrayInitialization();
+       uint getSizeEncodingArray(uint setSize) {
+               switch (type) {
+               case BINARYINDEX:
+                       return NEXTPOW2(setSize);
+               case ONEHOT:
+               case UNARY:
+                       return setSize;
+               default:
+                       ASSERT(0);
+               }
+               return -1;
+       }
 
-typedef enum ElementEncodingType ElementEncodingType;
 
-struct ElementEncoding {
        ElementEncodingType type;
-       Element * element;
-       Boolean ** variables; /* List Variables Use To Encode Element */
-       uint64_t * encodingArray; /* List the Variables in the appropriate order */
-       uint numVars; /* Number of variables */
+       Element *element;
+       Edge *variables;/* List Variables Used To Encode Element */
+       union {
+               struct {
+                       uint64_t *encodingArray;        /* List the Variables in the appropriate order */
+                       uint64_t *inUseArray;   /* Bitmap to track variables in use */
+                       uint encArraySize;
+               };
+               struct {
+                       uint64_t offset;/* Value = offset + encoded number (interpretted according to isBinaryValSigned) */
+                       uint64_t low;/* Lowest value to encode */
+                       uint64_t high;/* High value to encode.   If low > high, we assume wrap around to include 0. */
+                       uint numBits;
+                       bool isBinaryValSigned;
+               };
+       };
+       uint numVars;   /* Number of variables */
+       CMEMALLOC;
 };
 
-ElementEncoding * allocElementEncoding(ElementEncodingType type, Element *element);
-void deleteElementEncoding(ElementEncoding *this);
+
+
 #endif