on f7fc888 help sign in
33 lines 1.4 kB history raw
1module ProjectM36.TupleSet where
2import ProjectM36.Base
3import ProjectM36.Tuple
4import ProjectM36.Error
5import qualified Data.HashSet as HS
6import qualified Data.Vector as V
7import qualified Control.Parallel.Strategies as P
8import Data.Either
10emptyTupleSet :: RelationTupleSet
11emptyTupleSet = RelationTupleSet []
13singletonTupleSet :: RelationTupleSet
14singletonTupleSet = RelationTupleSet [emptyTuple]
16--ensure that all maps have the same keys and key count
18verifyTupleSet :: Attributes -> RelationTupleSet -> Either RelationalError RelationTupleSet
19verifyTupleSet attrs tupleSet = do
20 --check that all tuples have the same attributes and that the atom types match
21 let tupleList = map (verifyTuple attrs) (asList tupleSet) `P.using` P.parListChunk chunkSize P.r0
22 chunkSize = (length . asList) tupleSet `div` 24
23 --let tupleList = P.parMap P.rdeepseq (verifyTuple attrs) (HS.toList tupleSet)
24 if not (null (lefts tupleList)) then
25 Left $ head (lefts tupleList)
26 else
27 return $ RelationTupleSet $ (HS.toList . HS.fromList) (rights tupleList)
29mkTupleSet :: Attributes -> [RelationTuple] -> Either RelationalError RelationTupleSet
30mkTupleSet attrs tuples = verifyTupleSet attrs (RelationTupleSet tuples)
32mkTupleSetFromList :: Attributes -> [[Atom]] -> Either RelationalError RelationTupleSet
33mkTupleSetFromList attrs atomMatrix = mkTupleSet attrs $ map (mkRelationTuple attrs . V.fromList) atomMatrix