Binary encoding for ElementSet and table-based ElementFunction
[satune.git] / src / AST / table.c
index 48bd532d52c4aade239cb49c9cc35f5cd15e00e8..a8af588fb4a67e9f4dff37176c125b4c9a099256 100644 (file)
@@ -2,19 +2,30 @@
 #include "common.h"
 #include "structs.h"
 #include "tableentry.h"
+#include "set.h"
+#include "mutableset.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;
+Table * allocTable(Element **domains, uint numDomain, Element * range){
+       Table* table = (Table*) ourmalloc(sizeof(Table));
+       allocInlineArrayInitElement(&table->domains, domains, numDomain);
+       allocInlineDefVectorTableEntry(&table->entries);
+       table->range =range;
+       return table;
 }
 
 void addNewTableEntry(Table* table, uint64_t* inputs, uint inputSize, uint64_t result){
-    ASSERT(getSizeVectorSet( table->domains) == inputSize);
-    pushVectorTableEntry(table->entries, allocTableEntry(inputs, inputSize, result));
+       ASSERT(getSizeArrayElement( &table->domains) == inputSize);
+       pushVectorTableEntry(&table->entries, allocTableEntry(inputs, inputSize, result));
+}
+
+void deleteTable(Table* table){
+  deleteInlineArrayElement(&table->domains);
+  uint size = getSizeVectorTableEntry(&table->entries);
+  for(uint i=0; i<size; i++){
+    deleteTableEntry(getVectorTableEntry(&table->entries, i));
+  }
+  deleteVectorArrayTableEntry(&table->entries);
+  ourfree(table);
 }