@@ -12,6 +12,9 @@ import GHC.Generics (Generic)
12import qualified Data.Vector as V
12import qualified Data.Vector as V
13import qualified Data.List as L
13import qualified Data.List as L
14import qualified Data.Text as T
14import qualified Data.Text as T
16+import Data.Vector.Binary()
17+import ProjectM36.HashSetBinary()
16type StringType = T.Text
19type StringType = T.Text
@@ -23,7 +26,9 @@ data Atom = StringAtom StringType |
24instance NFData Atom where rnf = genericRnf
27instance NFData Atom where rnf = genericRnf
26−instance Hash.Hashable Atom
29+instance Hash.Hashable Atom
28data AtomType = StringAtomType |
33data AtomType = StringAtomType |
29 IntAtomType |
34 IntAtomType |
@@ -33,6 +38,7 @@ data AtomType = StringAtomType |
33 deriving (Eq, Show, Generic)
38 deriving (Eq, Show, Generic)
35instance NFData AtomType where rnf = genericRnf
40instance NFData AtomType where rnf = genericRnf
41+instance Binary AtomType
37type AttributeName = T.Text
43type AttributeName = T.Text
@@ -42,6 +48,8 @@ instance Hash.Hashable Attribute where
42 hashWithSalt salt (Attribute attrName _) = Hash.hashWithSalt salt attrName
48 hashWithSalt salt (Attribute attrName _) = Hash.hashWithSalt salt attrName
44instance NFData Attribute where rnf = genericRnf
50instance NFData Attribute where rnf = genericRnf
52+instance Binary Attribute
46type Attributes = V.Vector Attribute
54type Attributes = V.Vector Attribute
@@ -68,6 +76,8 @@ instance Hash.Hashable RelationTuple where
68--maybe the attribute->int mapping should be stored once in the relation and then passed down when needed
76--maybe the attribute->int mapping should be stored once in the relation and then passed down when needed
69data RelationTuple = RelationTuple Attributes (V.Vector Atom) deriving (Show, Generic)
77data RelationTuple = RelationTuple Attributes (V.Vector Atom) deriving (Show, Generic)
79+instance Binary RelationTuple
71instance Eq RelationTuple where
81instance Eq RelationTuple where
72 (==) tuple1@(RelationTuple attrs1 _) tuple2@(RelationTuple attrs2 _) = attributesEqual attrs1 attrs2 && atomsEqual
82 (==) tuple1@(RelationTuple attrs1 _) tuple2@(RelationTuple attrs2 _) = attributesEqual attrs1 attrs2 && atomsEqual
@@ -91,6 +101,8 @@ instance Hash.Hashable Relation where
91 HS.toList tupSet
101 HS.toList tupSet
93 sortedAttrs = map snd (sortedAttributesIndices attrs)
103 sortedAttrs = map snd (sortedAttributesIndices attrs)
105+instance Binary Relation
95data RelationCardinality = Uncountable | Countable Int deriving (Eq, Show, Generic)
107data RelationCardinality = Uncountable | Countable Int deriving (Eq, Show, Generic)
96data RelationSizeInfinite = RelationSizeInfinite
108data RelationSizeInfinite = RelationSizeInfinite
@@ -115,17 +127,23 @@ data RelationalExpr where
115 NotEquals :: RelationalExpr -> RelationalExpr -> RelationalExpr
127 NotEquals :: RelationalExpr -> RelationalExpr -> RelationalExpr
116 Extend :: TupleExpr -> RelationalExpr -> RelationalExpr
128 Extend :: TupleExpr -> RelationalExpr -> RelationalExpr
117 --Summarize :: AtomExpr -> AttributeName -> RelationalExpr -> RelationalExpr -> RelationalExpr -- a special case of Extend
129 --Summarize :: AtomExpr -> AttributeName -> RelationalExpr -> RelationalExpr -> RelationalExpr -- a special case of Extend
118− deriving (Show,Eq)
130+ deriving (Show,Eq, Generic)
132+instance Binary RelationalExpr
120data DatabaseContext = DatabaseContext {
134data DatabaseContext = DatabaseContext {
121 inclusionDependencies :: M.Map IncDepName InclusionDependency,
135 inclusionDependencies :: M.Map IncDepName InclusionDependency,
122 relationVariables :: M.Map RelVarName Relation,
136 relationVariables :: M.Map RelVarName Relation,
123 atomFunctions :: AtomFunctions
137 atomFunctions :: AtomFunctions
124− } deriving (Show)
138+ } deriving (Show, Generic)
140+--instance Binary DatabaseContext
126type IncDepName = StringType
142type IncDepName = StringType
128−data InclusionDependency = InclusionDependency RelationalExpr RelationalExpr deriving (Show, Eq)
144+data InclusionDependency = InclusionDependency RelationalExpr RelationalExpr deriving (Show, Eq, Generic)
146+instance Binary InclusionDependency
130--Database context expressions modify the database context while relational expressions do not
148--Database context expressions modify the database context while relational expressions do not
131data DatabaseExpr where
149data DatabaseExpr where
@@ -150,7 +168,9 @@ data RestrictionPredicateExpr where
150 RelationalExprPredicate :: RelationalExpr -> RestrictionPredicateExpr --type must be same as true and false relations (no attributes)
168 RelationalExprPredicate :: RelationalExpr -> RestrictionPredicateExpr --type must be same as true and false relations (no attributes)
151 AtomExprPredicate :: AtomExpr -> RestrictionPredicateExpr --atom must evaluate to boolean
169 AtomExprPredicate :: AtomExpr -> RestrictionPredicateExpr --atom must evaluate to boolean
152 AttributeEqualityPredicate :: AttributeName -> AtomExpr -> RestrictionPredicateExpr -- relationalexpr must result in relation with single tuple
170 AttributeEqualityPredicate :: AttributeName -> AtomExpr -> RestrictionPredicateExpr -- relationalexpr must result in relation with single tuple
153− deriving (Show, Eq)
171+ deriving (Show, Eq, Generic)
173+instance Binary RestrictionPredicateExpr
155-- child + parent links
175-- child + parent links
156-- the string represents the branch name and can be used to find the named HEADs
176-- the string represents the branch name and can be used to find the named HEADs
@@ -169,10 +189,14 @@ transactionHeadsForGraph (TransactionGraph heads _) = heads
170data TransactionInfo = TransactionInfo UUID (S.Set UUID) | -- 1 parent + n children
190data TransactionInfo = TransactionInfo UUID (S.Set UUID) | -- 1 parent + n children
171 MergeTransactionInfo UUID UUID (S.Set UUID) -- 2 parents, n children
191 MergeTransactionInfo UUID UUID (S.Set UUID) -- 2 parents, n children
172− deriving(Show)
192+ deriving(Show, Generic)
194+--instance Binary TransactionInfo
174data Transaction = Transaction UUID TransactionInfo DatabaseContext -- self uuid
196data Transaction = Transaction UUID TransactionInfo DatabaseContext -- self uuid
175− deriving (Show)
197+ deriving (Show, Generic)
199+--instance Binary Transaction
177--represents an "in-progress" transaction which has not yet been added to the transaction graph
201--represents an "in-progress" transaction which has not yet been added to the transaction graph
178--one the transaction is "complete", it is committed and no longer can be changed
202--one the transaction is "complete", it is committed and no longer can be changed
@@ -196,11 +220,15 @@ data AtomExpr = AttributeAtomExpr AttributeName |
196 NakedAtomExpr Atom |
220 NakedAtomExpr Atom |
197 FunctionAtomExpr AtomFunctionName [AtomExpr] |
221 FunctionAtomExpr AtomFunctionName [AtomExpr] |
198 RelationAtomExpr RelationalExpr
222 RelationAtomExpr RelationalExpr
199− deriving (Eq,Show)
223+ deriving (Eq,Show,Generic)
225+instance Binary AtomExpr
201--used to extend a relation
227--used to extend a relation
202data TupleExpr = AttributeTupleExpr AttributeName AtomExpr
228data TupleExpr = AttributeTupleExpr AttributeName AtomExpr
203− deriving (Show, Eq)
229+ deriving (Show, Eq, Generic)
231+instance Binary TupleExpr
205--enumerates the list of functions available to be run as part of tuple expressions
233--enumerates the list of functions available to be run as part of tuple expressions
206type AtomFunctions = HS.HashSet AtomFunction
234type AtomFunctions = HS.HashSet AtomFunction
@@ -223,7 +251,10 @@ instance Show AtomFunction where
223 show aFunc = T.unpack (atomFuncName aFunc) ++ "::" ++ showArgTypes
251 show aFunc = T.unpack (atomFuncName aFunc) ++ "::" ++ showArgTypes
225 showArgTypes = concat (L.intersperse "->" $ map show (atomFuncType aFunc))
253 showArgTypes = concat (L.intersperse "->" $ map show (atomFuncType aFunc))
227data AttributeNames = AttributeNames (S.Set AttributeName) |
255data AttributeNames = AttributeNames (S.Set AttributeName) |
228 InvertedAttributeNames (S.Set AttributeName)
256 InvertedAttributeNames (S.Set AttributeName)
229− deriving (Eq, Show)
257+ deriving (Eq, Show, Generic)
259+instance Binary AttributeNames