annotate src/parallel_execution/RedBlackTree.agda @ 417:24c98ca207f4

add RedBlackTree.agda
author mir3636
date Thu, 05 Oct 2017 17:52:06 +0900
parents
children ea6353b6c4ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
417
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
1 module RedBlackTree where
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
2
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
3 open import stack
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
4
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
5 record Tree {a t : Set} (treeImpl : Set) : Set where
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
6 field
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
7 tree : treeImpl
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
8 put : treeImpl -> a -> (treeImpl -> t) -> t
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
9 get : treeImpl -> (treeImpl -> Maybe a -> t) -> t
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
10
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
11 record RedBlackTree (a : Set) : Set where
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
12 field
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
13 top : Maybe (Element a)
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
14 stack : Stack
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
15 open RedBlackTree
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
16
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
17 putRedBlackTree : {Data t : Set} -> RedBlackTree Data -> Data -> (Code : RedBlackTree Data -> t) -> t
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
18 putRedBlackTree stack datum next = next newtree
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
19 where
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
20 element = cons datum (top stack)
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
21 newtree = record {top = Just element}
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
22
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
23 getRedBlackTree : {a t : Set} -> RedBlackTree a -> (Code : RedBlackTree a -> (Maybe a) -> t) -> t
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
24 getRedBlackTree tree cs with (top tree)
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
25 ... | Nothing = cs tree Nothing
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
26 ... | Just d = cs stack1 (Just data1)
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
27 where
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
28 data1 = datum d
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
29 stack1 = record { top = (next d) }
24c98ca207f4 add RedBlackTree.agda
mir3636
parents:
diff changeset
30