1f95f43c1d4b61d23a32f67ba4f9f6b220f3337b
[satune.git] / src / AST / table.c
1 #include "table.h"
2 #include "common.h"
3 #include "structs.h"
4 #include "tableentry.h"
5 #include "set.h"
6
7
8 Table * allocTable(Set **domains, uint numDomain, Set * range){
9     Table* table = (Table*) ourmalloc(sizeof(Table));
10     table->domains = allocDefVectorSet();
11     for(int i=0; i<numDomain; i++){
12         pushVectorSet(table->domains, domains[i]);
13     }
14     table->range =range;
15                 return table;
16 }
17
18 void addNewTableEntry(Table* table, uint64_t* inputs, uint inputSize, uint64_t result){
19     ASSERT(getSizeVectorSet( table->domains) == inputSize);
20     pushVectorTableEntry(table->entries, allocTableEntry(inputs, inputSize, result));
21 }
22
23 void deleteTable(Table* table){
24     uint size = getSizeVectorSet(table->domains);
25     for(uint i=0; i<size; i++){
26         deleteSet(getVectorSet(table->domains,i));
27     }
28     ourfree(table->domains);
29     ourfree(table->range);
30     size = getSizeVectorTableEntry(table->entries);
31     for(uint i=0; i<size; i++){
32         deleteTableEntry(getVectorTableEntry(table->entries, i));
33     }
34     ourfree(table);
35 }
36