bug fixes
[satune.git] / src / Encoders / elementencoding.cc
index 89d3c3262e11105e3c52de2b488de953d271ea8f..cc9688964a39a2e14c05a81224c9bd1e5c3b0ee6 100644 (file)
@@ -5,6 +5,8 @@
 #include "satencoder.h"
 #include "set.h"
 
+const char *elemEncTypeNames[] = {"UNASSIGNED", "ONEHOT", "UNARY", "BINARYINDEX", "BINARYVAL"};
+
 ElementEncoding::ElementEncoding(Element *_element) :
        type(ELEM_UNASSIGNED),
        element(_element),
@@ -30,7 +32,7 @@ void ElementEncoding::allocEncodingArrayElement(uint size) {
 }
 
 void ElementEncoding::allocInUseArrayElement(uint size) {
-       uint bytes = ((size + ((1 << 9) - 1)) >> 6) & ~7;//Depends on size of inUseArray
+       uint bytes = ((size + 63) >> 3) & ~7;   //Depends on size of inUseArray
        inUseArray = (uint64_t *) ourcalloc(1, bytes);
 }
 
@@ -39,7 +41,7 @@ void ElementEncoding::setElementEncodingType(ElementEncodingType _type) {
 }
 
 void ElementEncoding::encodingArrayInitialization() {
-       Set *set = getElementSet(element);
+       Set *set = element->getRange();
        uint size = set->getSize();
        uint encSize = getSizeEncodingArray(size);
        allocEncodingArrayElement(encSize);
@@ -49,3 +51,17 @@ void ElementEncoding::encodingArrayInitialization() {
                setInUseElement(i);
        }
 }
+
+void ElementEncoding::print() {
+       model_print("%s ", elemEncTypeNames[type]);
+       if (type == BINARYINDEX) {
+               for (uint i = 0; i < encArraySize; i++) {
+                       if (i != 0)
+                               model_print(", ");
+                       if (isinUseElement(i))
+                               model_print("%" PRIu64 "", encodingArray[i]);
+                       else
+                               model_print("_");
+               }
+       }
+}