Resolving Conflicts ... Still there're errors that should be fixed
[satune.git] / src / Encoders / encodings.c
1 #include "encodings.h"
2 #include "elementencoding.h"
3 #include "functionencoding.h"
4 #include "element.h"
5 #include "common.h"
6 #include "boolean.h"
7 #include "naiveencoder.h"
8
9 Encodings* allocEncodings(){
10         Encodings* This = (Encodings*) ourmalloc(sizeof(Encodings));
11         allocInlineDefVectorElementEncoding(GETVECTORELEMENTENCODING(This));
12         allocInlineDefVectorFunctionEncoding(GETVECTORFUNCTIONENCODING(This));
13         This->elemToEncode= allocHashTableElemToEncod(HT_INITIAL_CAPACITY, HT_DEFAULT_FACTOR);
14         This->voidToFuncEncode= allocHashTableVoidToFuncEncod(HT_INITIAL_CAPACITY, HT_DEFAULT_FACTOR);
15         return This;
16 }
17
18 void deleteEncodings(Encodings* This){
19         deleteVectorArrayFunctionEncoding(GETVECTORFUNCTIONENCODING(This));
20         deleteVectorArrayElementEncoding(GETVECTORELEMENTENCODING(This));
21         deleteHashTableElemToEncod(This->elemToEncode);
22         deleteHashTableVoidToFuncEncod(This->voidToFuncEncode);
23         ourfree(This);
24 }
25
26 void assignEncoding(CSolver* csolver, Encodings* This){
27         uint size = getSizeVectorElement(csolver->allElements);
28         for(uint i=0; i<size; i++){
29                 Element* element = getVectorElement(csolver->allElements, i);
30                 if(GETELEMENTTYPE(element)==ELEMSET){
31                         ElementEncoding* eencoding = allocElementEncoding( BINARYINDEX, element);
32                         baseBinaryIndexElementAssign(eencoding);
33                         pushVectorElementEncoding(GETVECTORELEMENTENCODING(This) , eencoding);
34                         putElemToEncod(This->elemToEncode, element, eencoding); 
35                 }else if (GETELEMENTTYPE(element)==ELEMFUNCRETURN){
36                         FunctionEncoding* fencoding = allocFunctionEncoding( ENUMERATEIMPLICATIONS, element);
37                         pushVectorFunctionEncoding(GETVECTORFUNCTIONENCODING(This) , fencoding);
38                         putVoidToFuncEncod(This->voidToFuncEncode,element, fencoding);
39                 }else
40                         ASSERT(0);
41         }
42         
43         size = getSizeVectorBoolean(csolver->allBooleans);
44         for(uint i=0; i<size; i++){
45                 Boolean* predicate = getVectorBoolean(csolver->allBooleans, i);
46                 if(GETBOOLEANTYPE(predicate)==PREDICATEOP){
47                         FunctionEncoding* fencoding = allocPredicateEncoding(ENUMERATEIMPLICATIONS, predicate);
48                         pushVectorFunctionEncoding(GETVECTORFUNCTIONENCODING(This), fencoding);
49                         putVoidToFuncEncod(This->voidToFuncEncode, predicate,fencoding);
50                 }else 
51                         ASSERT(0);
52         }
53 }
54
55 void encodeFunctionsElements(Encodings* This){
56         //call encoding for each element/predicate
57 }