@@ -12,6 +12,9 @@ import GHC.Generics (Generic)
1212import qualified Data.Vector as V
1313import qualified Data.List as L
1414import qualified Data.Text as T
15+import Data.Binary
16+import Data.Vector.Binary()
17+import ProjectM36.HashSetBinary()
1518
1619type StringType = T.Text
1720
@@ -23,7 +26,9 @@ data Atom = StringAtom StringType |
2326
2427instance NFData Atom where rnf = genericRnf
2528
26−instance Hash.Hashable Atom
29+instance Hash.Hashable Atom
30+
31+instance Binary Atom
2732
2833data AtomType = StringAtomType |
2934 IntAtomType |
@@ -33,6 +38,7 @@ data AtomType = StringAtomType |
3338 deriving (Eq, Show, Generic)
3439
3540instance NFData AtomType where rnf = genericRnf
41+instance Binary AtomType
3642
3743type AttributeName = T.Text
3844
@@ -42,6 +48,8 @@ instance Hash.Hashable Attribute where
4248 hashWithSalt salt (Attribute attrName _) = Hash.hashWithSalt salt attrName
4349
4450instance NFData Attribute where rnf = genericRnf
51+
52+instance Binary Attribute
4553
4654type Attributes = V.Vector Attribute
4755
@@ -68,6 +76,8 @@ instance Hash.Hashable RelationTuple where
6876--maybe the attribute->int mapping should be stored once in the relation and then passed down when needed
6977data RelationTuple = RelationTuple Attributes (V.Vector Atom) deriving (Show, Generic)
7078
79+instance Binary RelationTuple
80+
7181instance Eq RelationTuple where
7282 (==) tuple1@(RelationTuple attrs1 _) tuple2@(RelationTuple attrs2 _) = attributesEqual attrs1 attrs2 && atomsEqual
7383 where
@@ -91,6 +101,8 @@ instance Hash.Hashable Relation where
91101 HS.toList tupSet
92102 where
93103 sortedAttrs = map snd (sortedAttributesIndices attrs)
104+
105+instance Binary Relation
94106
95107data RelationCardinality = Uncountable | Countable Int deriving (Eq, Show, Generic)
96108data RelationSizeInfinite = RelationSizeInfinite
@@ -115,17 +127,23 @@ data RelationalExpr where
115127 NotEquals :: RelationalExpr -> RelationalExpr -> RelationalExpr
116128 Extend :: TupleExpr -> RelationalExpr -> RelationalExpr
117129 --Summarize :: AtomExpr -> AttributeName -> RelationalExpr -> RelationalExpr -> RelationalExpr -- a special case of Extend
118− deriving (Show,Eq)
130+ deriving (Show,Eq, Generic)
131+
132+instance Binary RelationalExpr
119133
120134data DatabaseContext = DatabaseContext {
121135 inclusionDependencies :: M.Map IncDepName InclusionDependency,
122136 relationVariables :: M.Map RelVarName Relation,
123137 atomFunctions :: AtomFunctions
124− } deriving (Show)
138+ } deriving (Show, Generic)
139+
140+--instance Binary DatabaseContext
125141
126142type IncDepName = StringType
127143
128−data InclusionDependency = InclusionDependency RelationalExpr RelationalExpr deriving (Show, Eq)
144+data InclusionDependency = InclusionDependency RelationalExpr RelationalExpr deriving (Show, Eq, Generic)
145+
146+instance Binary InclusionDependency
129147
130148--Database context expressions modify the database context while relational expressions do not
131149data DatabaseExpr where
@@ -150,7 +168,9 @@ data RestrictionPredicateExpr where
150168 RelationalExprPredicate :: RelationalExpr -> RestrictionPredicateExpr --type must be same as true and false relations (no attributes)
151169 AtomExprPredicate :: AtomExpr -> RestrictionPredicateExpr --atom must evaluate to boolean
152170 AttributeEqualityPredicate :: AttributeName -> AtomExpr -> RestrictionPredicateExpr -- relationalexpr must result in relation with single tuple
153− deriving (Show, Eq)
171+ deriving (Show, Eq, Generic)
172+
173+instance Binary RestrictionPredicateExpr
154174
155175-- child + parent links
156176-- the string represents the branch name and can be used to find the named HEADs
@@ -169,10 +189,14 @@ transactionHeadsForGraph (TransactionGraph heads _) = heads
169189
170190data TransactionInfo = TransactionInfo UUID (S.Set UUID) | -- 1 parent + n children
171191 MergeTransactionInfo UUID UUID (S.Set UUID) -- 2 parents, n children
172− deriving(Show)
192+ deriving(Show, Generic)
193+
194+--instance Binary TransactionInfo
173195
174196data Transaction = Transaction UUID TransactionInfo DatabaseContext -- self uuid
175− deriving (Show)
197+ deriving (Show, Generic)
198+
199+--instance Binary Transaction
176200
177201--represents an "in-progress" transaction which has not yet been added to the transaction graph
178202--one the transaction is "complete", it is committed and no longer can be changed
@@ -196,11 +220,15 @@ data AtomExpr = AttributeAtomExpr AttributeName |
196220 NakedAtomExpr Atom |
197221 FunctionAtomExpr AtomFunctionName [AtomExpr] |
198222 RelationAtomExpr RelationalExpr
199− deriving (Eq,Show)
223+ deriving (Eq,Show,Generic)
224+
225+instance Binary AtomExpr
200226
201227--used to extend a relation
202228data TupleExpr = AttributeTupleExpr AttributeName AtomExpr
203− deriving (Show, Eq)
229+ deriving (Show, Eq, Generic)
230+
231+instance Binary TupleExpr
204232
205233--enumerates the list of functions available to be run as part of tuple expressions
206234type AtomFunctions = HS.HashSet AtomFunction
@@ -223,7 +251,10 @@ instance Show AtomFunction where
223251 show aFunc = T.unpack (atomFuncName aFunc) ++ "::" ++ showArgTypes
224252 where
225253 showArgTypes = concat (L.intersperse "->" $ map show (atomFuncType aFunc))
226−
254+
227255data AttributeNames = AttributeNames (S.Set AttributeName) |
228256 InvertedAttributeNames (S.Set AttributeName)
229− deriving (Eq, Show)
257+ deriving (Eq, Show, Generic)
258+
259+instance Binary AttributeNames
260+