Adding support for (de)serializing MutableSet
authorHamed <hamed.gorjiara@gmail.com>
Wed, 13 Sep 2017 03:14:24 +0000 (20:14 -0700)
committerHamed <hamed.gorjiara@gmail.com>
Wed, 13 Sep 2017 03:14:24 +0000 (20:14 -0700)
src/AST/mutableset.h
src/AST/set.cc
src/AST/set.h
src/Serialize/deserializer.cc

index 568678f..c608f3f 100644 (file)
@@ -7,6 +7,7 @@ public:
        MutableSet(VarType t);
        void addElementMSet(uint64_t element);
        Set *clone(CSolver *solver, CloneMap *map);
+       bool isMutableSet() {return true;}
        CMEMALLOC;
 };
 #endif
index 54c6679..fc8bf15 100644 (file)
@@ -95,6 +95,8 @@ void Set::serialize(Serializer* serializer){
        serializer->mywrite(&isRange, sizeof(bool));
        serializer->mywrite(&low, sizeof(uint64_t));
        serializer->mywrite(&high, sizeof(uint64_t));
+       bool isMutable = isMutableSet();
+       serializer->mywrite(&isMutable, sizeof(bool));
        uint size = members->getSize();
        serializer->mywrite(&size, sizeof(uint));
        for(uint i=0; i<size; i++){
index 6dbeac0..efd281d 100644 (file)
@@ -24,6 +24,7 @@ public:
        uint64_t getNewUniqueItem() {return low++;}
        uint64_t getMemberAt(uint index);
        uint64_t getElement(uint index);
+       virtual bool isMutableSet() {return false;}
        virtual Set *clone(CSolver *solver, CloneMap *map);
        virtual void serialize(Serializer* serializer);
        CMEMALLOC;
index 7119119..fc4cd7b 100644 (file)
@@ -13,6 +13,7 @@
 #include "predicate.h"
 #include "table.h"
 #include "element.h"
+#include "mutableset.h"
 
 Deserializer::Deserializer(const char* file):
        solver(new CSolver())
@@ -148,16 +149,28 @@ void Deserializer::deserializeSet(){
        myread(&low, sizeof(uint64_t));
        uint64_t high;
        myread(&high, sizeof(uint64_t));
+       bool isMutable;
+       myread(&isMutable, sizeof(bool));
+       Set *set;
+       if(isMutable){
+               set = new MutableSet(type);
+       }
        uint size;
        myread(&size, sizeof(uint));
        Vector<uint64_t> members;
        for(uint i=0; i<size; i++){
                uint64_t mem;
                myread(&mem, sizeof(uint64_t));
-               members.push(mem);
+               if(isMutable) {
+                       ((MutableSet*) set)->addElementMSet(mem);
+               }else {
+                       members.push(mem);
+               }
+       }
+       if(!isMutable){
+               set = isRange? solver->createRangeSet(type, low, high):
+                       solver->createSet(type, members.expose(), size);
        }
-       Set *set = isRange? solver->createRangeSet(type, low, high):
-               solver->createSet(type, members.expose(), size);
        map.put(s_ptr, set);
 }