-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataRecords.hs
92 lines (70 loc) · 2.22 KB
/
DataRecords.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
module DataRecords where
import GHC.Generics (Generic)
import Control.DeepSeq
-- Update structure
data TimeEdge = TimeEdge
{ idFrom :: Int
, field :: Int
, idTo :: Int
, timeFrom :: Int
, timeTo :: Int
}
deriving (Eq, Ord, Show, Generic, NFData)
data TimeTree s
= TimeLeaf
| TimeNode
{ tElm :: s
, tId :: Int
, tFields :: [(Int, TimeTree s)] -- (Exists from time, nodeto)
}
deriving (Eq, Show, Generic, NFData)
data PartialTree s = PartialTree
{ edgeFreezer :: [TimeEdge]
, idStaticList :: [(Int, s)] -- (id, staticInfo)
, rootList :: [(Int, Int)] -- (time, id), convention: id '-1' is the empty tree
, idCount :: Int
, fieldCount :: Int
, time :: Int
, currentTree :: TimeTree s
}
deriving (Eq, Show, Generic, NFData)
type EPH_BST t s =
( Tree s -- empty function
, t -> Tree s -> Tree s -- insert function
, t -> Tree s -> Tree s -- delete function
)
type PER_BST t s =
( PartialTree s -- empty function
, t -> PartialTree s -> PartialTree s -- insert function
, t -> PartialTree s -> PartialTree s -- delete function
)
-- User viewed update structure
type State s = ([TimeEdge], [(Int, s)], Int)
type Update s t = (Int, State s) -> (t, State s)
type TreeUpdate s = Update s (TimeTree s)
data UserTree s
= UserLeaf
| UserNode (s, s -> [TreeUpdate s] -> TreeUpdate s, TreeUpdate s -> TreeUpdate s, [(UserTree s, TreeUpdate s)])
-- Input: element in the node, func to make node from element and fields, func to replace node by build tree, list of fields
-- Nodes used in DAG
data FrozenNode staticType = FrozenNode
{ staticInformation :: staticType
, fields :: [FrozenEdge staticType]
}
deriving (Show, Generic, NFData)
data FrozenEdge staticType = FrozenEdge
{ fieldFrom :: Int
, nodeTo :: FrozenNode staticType
, frozenTimeFrom :: Int
, frozenTimeTo :: Int
}
deriving (Show, Generic, NFData)
-- Nodes exposed to user under query
data Tree t
= Leaf
| Node
{ elm :: t
, children :: [Tree t]
}
deriving (Eq, Show, Generic, NFData)