#define ELEMENTENCODING_H
#include "classlist.h"
#include "naiveencoder.h"
+#include "constraint.h"
-enum ElementEncodingType {
- ELEM_UNASSIGNED, ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
-};
+typedef enum ElemEnc {EENC_UNKNOWN, EENC_NONE, EENC_BOTH} ElemEnc;
-typedef enum ElementEncodingType ElementEncodingType;
+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;
+ }
+ void print();
-struct ElementEncoding {
ElementEncodingType type;
- Element * element;
- Constraint ** variables;/* List Variables Used To Encode Element */
- uint64_t * encodingArray; /* List the Variables in the appropriate order */
- uint64_t * inUseArray;/* Bitmap to track variables in use */
- uint encArraySize;
+ 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 */
+ Edge * edgeArray;
+ Polarity * polarityArray;
+ uint encArraySize;
+ ElemEnc encoding;
+ };
+ 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;
};
-void initElementEncoding(ElementEncoding *This, Element *element);
-void setElementEncodingType(ElementEncoding* This, ElementEncodingType type);
-void deleteElementEncoding(ElementEncoding *This);
-void allocEncodingArrayElement(ElementEncoding *This, uint size);
-void allocInUseArrayElement(ElementEncoding *This, uint size);
-//FIXME
-//uint addNewVariableToEncodingArray(ElementEncoding* This, uint64_t var);
-static inline bool isinUseElement(ElementEncoding *This, uint offset) {
- return (This->inUseArray[(offset>>6)] >> (offset & 63)) &0x1;
-}
-
-static inline void setInUseElement(ElementEncoding *This, uint offset) {
- This->inUseArray[(offset>>6)] |= 1 << (offset & 63);
-}
-void generateBinaryIndexEncodingVars(SATEncoder* encode, ElementEncoding* This);
-void generateElementEncodingVariables(SATEncoder* encoder, ElementEncoding* This);
#endif