#include "table.h"
+#include "common.h"
+#include "structs.h"
+#include "tableentry.h"
+
+
+Table * allocTable(Set **domains, uint numDomain, Set * range){
+ Table* table = (Table*) ourmalloc(sizeof(Table));
+ table->domains = allocDefVectorSet();
+ for(int i=0; i<numDomain; i++){
+ pushVectorSet(table->domains, domains[i]);
+ }
+ table->range =range;
+}
+
+void addNewTableEntry(Table* table, uint64_t* inputs, uint inputSize, uint64_t result){
+ ASSERT(getSizeVectorSet( table->domains) == inputSize);
+ pushVectorTableEntry(table->entries, allocTableEntry(inputs, inputSize, result));
+}
+
#define TABLE_H
#include "classlist.h"
#include "mymemory.h"
+#include "structs.h"
struct Table {
-
+ VectorSet* domains;
+ Set * range;
+ VectorTableEntry* entries;
};
-Table * allocTable();
+Table * allocTable(Set **domains, uint numDomain, Set * range);
+void addNewTableEntry(Table* table, uint64_t* inputs, uint inputSize, uint64_t result);
+
#endif
--- /dev/null
+#include "tableentry.h"
+
+TableEntry* allocTableEntry(uint64_t* inputs, uint inputSize, uint64_t result){
+ TableEntry* te = (TableEntry*) ourmalloc(sizeof(TableEntry)+inputSize*sizeof(uint64_t));
+ te->output=result;
+ for(int i=0; i<inputSize; i++){
+ te->inputs[i]=inputs[i];
+ }
+ return te;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/*
+ * File: tableentry.h
+ * Author: hamed
+ *
+ * Created on June 16, 2017, 3:54 PM
+ */
+
+#ifndef TABLEENTRY_H
+#define TABLEENTRY_H
+
+#include "classlist.h";
+#include "mymemory.h";
+struct TableEntry{
+ uint64_t output;
+ uint64_t inputs[];
+};
+
+TableEntry* allocTableEntry(uint64_t* inputs, uint inputSize, uint64_t result);
+
+#endif /* TABLEENTRY_H */
+
VectorDef(Constraint, Constraint *, 4);
VectorDef(Set, Set *, 4);
VectorDef(Element, Element *, 4);
+VectorDef(TableEntry, TableEntry *, 4);
+VectorDef(Predicate, Predicate *, 4);
+VectorDef(Table, Table *, 4);
inline unsigned int Ptr_hash_function(void * hash) {
return (unsigned int)((uint64_t)hash >> 4);
struct FunctionEncoding;
typedef struct FunctionEncoding FunctionEncoding;
+struct TableEntry;
+typedef struct TableEntry TableEntry;
+
typedef unsigned int uint;
typedef uint64_t VarType;
#endif
#include "AST/boolean.h"
#include "AST/predicate.h"
#include "AST/order.h"
+#include "table.h"
CSolver * allocCSolver() {
CSolver * tmp=(CSolver *) ourmalloc(sizeof(CSolver));
tmp->allBooleans=allocDefVectorBoolean();
tmp->allSets=allocDefVectorSet();
tmp->allElements=allocDefVectorElement();
+ tmp->allPredicates = allocDefVectorPredicate();
+ tmp->allTables = allocDefVectorTable();
return tmp;
}
for(uint i=0;i<size;i++) {
deleteElement(getVectorElement(this->allElements, i));
}
-
+ //FIXME: Freeing alltables and allpredicates
deleteVectorElement(this->allElements);
ourfree(this);
}
}
Predicate * createPredicateOperator(CSolver *solver, enum CompOp op, Set ** domain, uint numDomain) {
- return allocPredicate(op, domain,numDomain);
+ Predicate* predicate= allocPredicate(op, domain,numDomain);
+ pushVectorPredicate(solver->allPredicates, predicate);
+ return predicate;
}
Table * createTable(CSolver *solver, Set **domains, uint numDomain, Set * range) {
- return NULL;
+ Table* table= allocTable(domains,numDomain,range);
+ pushVectorTable(solver->allTables, table);
+ return table;
}
-void addTableEntry(CSolver *solver, uint64_t* inputs, uint inputSize, uint64_t result) {
+void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSize, uint64_t result) {
+ addNewTableEntry(table,inputs, inputSize,result);
}
Function * completeTable(CSolver *solver, Table * table) {
VectorBoolean * allBooleans;
VectorSet * allSets;
VectorElement * allElements;
+ VectorPredicate * allPredicates;
+ VectorTable * allTables;
};
/** Create a new solver instance. */
/** This function adds an input output relation to a table. */
-void addTableEntry(CSolver *solver, uint64_t* inputs, uint inputSize, uint64_t result);
+void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSize, uint64_t result);
/** This function converts a completed table into a function. */
/** This function instantiates an order of type type over the set set. */
Order * createOrder(CSolver *, enum OrderType type, Set * set);
-/** This function instantiates a predicate on two items in an order. */
+/** This function instantiates a boolean on two items in an order. */
Boolean * orderConstraint(CSolver *, Order * order, uint64_t first, uint64_t second);
#endif