adding TableEntries and ...
authorHamed <hamed.gorjiara@gmail.com>
Fri, 16 Jun 2017 23:40:03 +0000 (16:40 -0700)
committerHamed <hamed.gorjiara@gmail.com>
Fri, 16 Jun 2017 23:40:03 +0000 (16:40 -0700)
src/AST/table.c
src/AST/table.h
src/AST/tableentry.c [new file with mode: 0644]
src/AST/tableentry.h [new file with mode: 0644]
src/Collections/structs.h
src/classlist.h
src/csolver.c
src/csolver.h

index e89d72ad94fa001918b2da83e090e0bbefe31c3e..48bd532d52c4aade239cb49c9cc35f5cd15e00e8 100644 (file)
@@ -1 +1,20 @@
 #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));
+}
+
index 2bb98051f02c6ec5eefc902c3765cebda393d3b4..8027f88046199120915df5c2ab8f43e8e58f4d34 100644 (file)
@@ -2,10 +2,15 @@
 #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
diff --git a/src/AST/tableentry.c b/src/AST/tableentry.c
new file mode 100644 (file)
index 0000000..216a2b5
--- /dev/null
@@ -0,0 +1,10 @@
+#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
diff --git a/src/AST/tableentry.h b/src/AST/tableentry.h
new file mode 100644 (file)
index 0000000..fae0a3b
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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 */
+
index 888f359e3fdee2266f7a63a661ecc7e8bba26046..3e08e976a65b4b55367c0362298d5aebc916f096 100644 (file)
@@ -11,6 +11,9 @@ VectorDef(Boolean, Boolean *, 4);
 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);
index 361dcb6d0756f733109cc595327c9f83aee0efee..fc265b579577b9e0978d139fc3038c61d7f079dc 100644 (file)
@@ -54,6 +54,9 @@ typedef struct ElementEncoding ElementEncoding;
 struct FunctionEncoding;
 typedef struct FunctionEncoding FunctionEncoding;
 
+struct TableEntry;
+typedef struct TableEntry TableEntry;
+
 typedef unsigned int uint;
 typedef uint64_t VarType;
 #endif
index 8835fbf1c75939d67614f7d62624dc58bf3bde7f..68bbb469e811c75d74c678793bd32095323fd4d2 100644 (file)
@@ -5,6 +5,7 @@
 #include "AST/boolean.h"
 #include "AST/predicate.h"
 #include "AST/order.h"
+#include "table.h"
 
 CSolver * allocCSolver() {
        CSolver * tmp=(CSolver *) ourmalloc(sizeof(CSolver));
@@ -12,6 +13,8 @@ CSolver * allocCSolver() {
        tmp->allBooleans=allocDefVectorBoolean();
        tmp->allSets=allocDefVectorSet();
        tmp->allElements=allocDefVectorElement();
+       tmp->allPredicates = allocDefVectorPredicate();
+       tmp->allTables = allocDefVectorTable();
        return tmp;
 }
 
@@ -38,7 +41,7 @@ void deleteSolver(CSolver *this) {
        for(uint i=0;i<size;i++) {
                deleteElement(getVectorElement(this->allElements, i));
        }
-
+       //FIXME: Freeing alltables and allpredicates
        deleteVectorElement(this->allElements);
        ourfree(this);
 }
@@ -89,14 +92,19 @@ Function * createFunctionOperator(CSolver *solver, enum ArithOp op, Set ** domai
 }
 
 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) {
index 15d3f47f305effa88dbd26bb3afed1f4a4303d6d..0093586600778d9c34bc4615884df69a45f3f25d 100644 (file)
@@ -9,6 +9,8 @@ struct CSolver {
        VectorBoolean * allBooleans;
        VectorSet * allSets;
        VectorElement * allElements;
+       VectorPredicate * allPredicates;
+       VectorTable * allTables;
 };
 
 /** Create a new solver instance. */
@@ -60,7 +62,7 @@ Table * createTable(CSolver *solver, Set **domains, uint numDomain, Set * range)
 
 /** 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. */
 
@@ -86,6 +88,6 @@ void addBoolean(CSolver *, Boolean * constraint);
 /** 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