Mercurial > hg > Gears > GearsAgda
annotate RedBlackTree.agda @ 531:f6060e1bf900
add clearStack
author | ryokka |
---|---|
date | Tue, 09 Jan 2018 17:26:19 +0900 |
parents | 63f3df7f5448 |
children | ccf98ed4a4f7 |
rev | line source |
---|---|
417 | 1 module RedBlackTree where |
2 | |
3 open import stack | |
511 | 4 open import Level |
417 | 5 |
511 | 6 record TreeMethods {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.⊔ n) where |
7 field | |
8 putImpl : treeImpl -> a -> (treeImpl -> t) -> t | |
9 getImpl : treeImpl -> (treeImpl -> Maybe a -> t) -> t | |
10 open TreeMethods | |
11 | |
12 record Tree {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.⊔ n) where | |
417 | 13 field |
14 tree : treeImpl | |
513 | 15 treeMethods : TreeMethods {n} {m} {a} {t} treeImpl |
16 putTree : a -> (Tree treeImpl -> t) -> t | |
511 | 17 putTree d next = putImpl (treeMethods ) tree d (\t1 -> next (record {tree = t1 ; treeMethods = treeMethods} )) |
513 | 18 getTree : (Tree treeImpl -> Maybe a -> t) -> t |
511 | 19 getTree next = getImpl (treeMethods ) tree (\t1 d -> next (record {tree = t1 ; treeMethods = treeMethods} ) d ) |
427 | 20 |
478 | 21 open Tree |
22 | |
513 | 23 data Color {n : Level } : Set n where |
425 | 24 Red : Color |
25 Black : Color | |
26 | |
512 | 27 data CompareResult {n : Level } : Set n where |
28 LT : CompareResult | |
29 GT : CompareResult | |
30 EQ : CompareResult | |
31 | |
513 | 32 record Node {n : Level } (a k : Set n) : Set n where |
33 inductive | |
425 | 34 field |
512 | 35 key : k |
36 value : a | |
513 | 37 right : Maybe (Node a k) |
38 left : Maybe (Node a k) | |
514 | 39 color : Color {n} |
512 | 40 open Node |
425 | 41 |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
42 record RedBlackTree {n m : Level } {t : Set m} (a k si : Set n) : Set (m Level.⊔ n) where |
417 | 43 field |
514 | 44 root : Maybe (Node a k) |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
45 nodeStack : Stack {n} {m} (Node a k) {t} si |
514 | 46 compare : k -> k -> CompareResult {n} |
425 | 47 |
417 | 48 open RedBlackTree |
49 | |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
50 open Stack |
512 | 51 |
518
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
52 -- |
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
53 -- put new node at parent node, and rebuild tree to the top |
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
54 -- |
519
0a723e418b2a
add some more directives in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
518
diff
changeset
|
55 {-# TERMINATING #-} -- https://agda.readthedocs.io/en/v2.5.3/language/termination-checking.html |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
56 replaceNode : {n m : Level } {t : Set m } {a k si : Set n} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) si -> Node a k -> Node a k -> (RedBlackTree {n} {m} {t} a k si -> t) -> t |
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
57 replaceNode {n} {m} {t} {a} {k} {si} tree s parent n0 next = popStack s ( |
518
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
58 \s grandParent -> replaceNode1 s grandParent ( compare tree (key parent) (key n0) ) ) |
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
59 where |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
60 replaceNode1 : Stack (Node a k) si -> Maybe ( Node a k ) -> CompareResult -> t |
529 | 61 replaceNode1 s Nothing LT = next ( record tree { root = Just ( record parent { left = Just n0 ; color = Black } ) } ) |
62 replaceNode1 s Nothing GT = next ( record tree { root = Just ( record parent { right = Just n0 ; color = Black } ) } ) | |
63 replaceNode1 s Nothing EQ = next ( record tree { root = Just ( record parent { right = Just n0 ; color = Black } ) } ) | |
518
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
64 replaceNode1 s (Just grandParent) result with result |
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
65 ... | LT = replaceNode tree s grandParent ( record parent { left = Just n0 } ) next |
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
66 ... | GT = replaceNode tree s grandParent ( record parent { right = Just n0 } ) next |
529 | 67 ... | EQ = next tree |
478 | 68 |
525 | 69 |
530 | 70 rotateRight : {n m : Level } {t : Set m } {a k si : Set n} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Maybe (Node a k) -> Maybe (Node a k) -> Node a k -> |
526 | 71 (RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Node a k -> Maybe (Node a k) -> Node a k -> t) -> t |
530 | 72 rotateRight {n} {m} {t} {a} {k} {si} tree s n0 parent grandParent rotateNext = getStack s (\ s n0 -> rotateRight1 tree s n0 parent grandParent rotateNext) |
73 where | |
74 rotateRight1 : {n m : Level } {t : Set m } {a k si : Set n} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Maybe (Node a k) -> Maybe (Node a k) -> Node a k -> | |
75 (RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Node a k -> Maybe (Node a k) -> Node a k -> t) -> t | |
76 rotateRight1 {n} {m} {t} {a} {k} {si} tree s n0 parent grandParent rotateNext with n0 | |
77 ... | Nothing = rotateNext tree s {!!} Nothing grandParent | |
78 ... | Just n1 with parent | |
79 ... | Nothing = rotateNext tree s n1 Nothing grandParent | |
80 ... | Just parent1 with left parent1 | |
81 ... | Nothing = rotateNext tree s n1 Nothing grandParent | |
82 ... | Just leftParent with compare tree (key n1) (key leftParent) | |
83 ... | EQ = rotateNext tree s n1 parent grandParent | |
84 ... | _ = rotateNext tree s n1 parent grandParent | |
85 | |
519
0a723e418b2a
add some more directives in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
518
diff
changeset
|
86 |
530 | 87 rotateLeft : {n m : Level } {t : Set m } {a k si : Set n} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Maybe (Node a k) -> Maybe (Node a k) -> Node a k -> |
526 | 88 (RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Node a k -> Maybe (Node a k) -> Node a k -> t) -> t |
530 | 89 rotateLeft {n} {m} {t} {a} {k} {si} tree s n0 parent grandParent rotateNext = getStack s (\ s n0 -> rotateLeft1 tree s n0 parent grandParent rotateNext) |
90 where | |
91 rotateLeft1 : {n m : Level } {t : Set m } {a k si : Set n} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Maybe (Node a k) -> Maybe (Node a k) -> Node a k -> | |
92 (RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Node a k -> Maybe (Node a k) -> Node a k -> t) -> t | |
93 rotateLeft1 {n} {m} {t} {a} {k} {si} tree s n0 parent grandParent rotateNext with n0 | |
94 ... | Nothing = rotateNext tree s {!!} Nothing grandParent | |
95 ... | Just n1 with parent | |
96 ... | Nothing = rotateNext tree s n1 Nothing grandParent | |
97 ... | Just parent1 with right parent1 | |
98 ... | Nothing = rotateNext tree s n1 Nothing grandParent | |
99 ... | Just rightParent with compare tree (key n1) (key rightParent) | |
100 ... | EQ = rotateNext tree s n1 parent grandParent | |
101 ... | _ = rotateNext tree s n1 parent grandParent | |
519
0a723e418b2a
add some more directives in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
518
diff
changeset
|
102 |
530 | 103 {-# TERMINATING #-} |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
104 insertCase5 : {n m : Level } {t : Set m } {a k si : Set n} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Node a k -> Node a k -> Node a k -> (RedBlackTree {n} {m} {t} a k si -> t) -> t |
530 | 105 insertCase5 {n} {m} {t} {a} {k} {si} tree s n0 parent grandParent next = pop2Stack s (\ s parent grandParent -> insertCase51 tree s n0 parent grandParent next) |
106 where | |
107 insertCase51 : {n m : Level } {t : Set m } {a k si : Set n} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Node a k -> Maybe (Node a k) -> Maybe (Node a k) -> (RedBlackTree {n} {m} {t} a k si -> t) -> t | |
108 insertCase51 {n} {m} {t} {a} {k} {si} tree s n0 parent grandParent next with parent | grandParent | |
109 ... | Nothing | _ = next tree | |
110 ... | _ | Nothing = next tree | |
111 ... | Just parent1 | Just grandParent1 with left parent1 | left grandParent1 | |
112 ... | Nothing | _ = next tree | |
113 ... | _ | Nothing = next tree | |
114 ... | Just leftParent1 | Just leftGrandParent1 | |
115 with compare tree (key n0) (key leftParent1) | compare tree (key leftParent1) (key leftGrandParent1) | |
116 ... | EQ | EQ = rotateRight tree s {!!} parent grandParent1 | |
117 (\ tree s n0 parent grandParent -> insertCase5 tree s n0 parent1 grandParent next) | |
118 ... | _ | _ = rotateLeft tree s {!!} parent grandParent1 | |
119 (\ tree s n0 parent grandParent -> insertCase5 tree s n0 parent1 grandParent next) | |
519
0a723e418b2a
add some more directives in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
518
diff
changeset
|
120 |
528 | 121 insertCase4 : {n m : Level } {t : Set m } {a k si : Set n} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Node a k -> Node a k -> Node a k -> (RedBlackTree {n} {m} {t} a k si -> t) -> t |
527 | 122 insertCase4 {n} {m} {t} {a} {k} {si} tree s n0 parent grandParent next |
528 | 123 with (right parent) | (left grandParent) |
529 | 124 ... | Nothing | _ = insertCase5 tree s n0 parent grandParent next |
530 | 125 ... | _ | Nothing = insertCase5 tree s n0 parent grandParent next |
528 | 126 ... | Just rightParent | Just leftGrandParent with compare tree (key n0) (key rightParent) | compare tree (key parent) (key leftGrandParent) |
530 | 127 ... | EQ | EQ = popStack s (\ s n0 -> rotateLeft tree s n0 {!!} grandParent |
128 (\ tree s n0 parent grandParent -> insertCase5 tree s n0 rightParent grandParent next)) | |
129 ... | _ | _ = insertCase41 tree s n0 parent grandParent next | |
130 where | |
131 insertCase41 : {n m : Level } {t : Set m } {a k si : Set n} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Node a k -> Node a k -> Node a k -> (RedBlackTree {n} {m} {t} a k si -> t) -> t | |
132 insertCase41 {n} {m} {t} {a} {k} {si} tree s n0 parent grandParent next | |
133 with (left parent) | (right grandParent) | |
134 ... | Nothing | _ = insertCase5 tree s n0 parent grandParent next | |
135 ... | _ | Nothing = insertCase5 tree s n0 parent grandParent next | |
136 ... | Just leftParent | Just rightGrandParent with compare tree (key n0) (key leftParent) | compare tree (key parent) (key rightGrandParent) | |
137 ... | EQ | EQ = popStack s (\ s n0 -> rotateRight tree s n0 {!!} grandParent | |
138 (\ tree s n0 parent grandParent -> insertCase5 tree s n0 leftParent grandParent next)) | |
139 ... | _ | _ = insertCase5 tree s n0 parent grandParent next | |
527 | 140 |
141 | |
519
0a723e418b2a
add some more directives in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
518
diff
changeset
|
142 {-# TERMINATING #-} |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
143 insertNode : {n m : Level } {t : Set m } {a k si : Set n} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) {t} si -> Node a k -> (RedBlackTree {n} {m} {t} a k si -> t) -> t |
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
144 insertNode {n} {m} {t} {a} {k} {si} tree s n0 next = get2Stack s (\ s d1 d2 -> insertCase1 s n0 d1 d2 ) |
518
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
145 where |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
146 insertCase1 : Stack (Node a k) si -> Node a k -> Maybe (Node a k) -> Maybe (Node a k) -> t -- placed here to allow mutual recursion |
519
0a723e418b2a
add some more directives in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
518
diff
changeset
|
147 -- http://agda.readthedocs.io/en/v2.5.2/language/mutual-recursion.html |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
148 insertCase3 : Stack (Node a k) si -> Node a k -> Node a k -> Node a k -> t |
518
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
149 insertCase3 s n0 parent grandParent with left grandParent | right grandParent |
528 | 150 ... | Nothing | Nothing = insertCase4 tree s n0 parent grandParent next |
151 ... | Nothing | Just uncle = insertCase4 tree s n0 parent grandParent next | |
518
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
152 ... | Just uncle | _ with compare tree ( key uncle ) ( key parent ) |
528 | 153 ... | EQ = insertCase4 tree s n0 parent grandParent next |
518
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
154 ... | _ with color uncle |
529 | 155 ... | Red = pop2Stack s ( \s p0 p1 -> insertCase1 s ( |
518
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
156 record grandParent { color = Red ; left = Just ( record parent { color = Black ; left = Just n0 } ) ; right = Just ( record uncle { color = Black } ) }) p0 p1 ) |
528 | 157 ... | Black = insertCase4 tree s n0 parent grandParent next |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
158 insertCase2 : Stack (Node a k) si -> Node a k -> Node a k -> Node a k -> t |
518
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
159 insertCase2 s n0 parent grandParent with color parent |
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
160 ... | Black = replaceNode tree s grandParent n0 next |
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
161 ... | Red = insertCase3 s n0 parent grandParent |
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
162 insertCase1 s n0 Nothing Nothing = next tree |
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
163 insertCase1 s n0 Nothing (Just grandParent) = replaceNode tree s grandParent n0 next |
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
164 insertCase1 s n0 (Just grandParent) Nothing = replaceNode tree s grandParent n0 next |
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
165 insertCase1 s n0 (Just parent) (Just grandParent) = insertCase2 s n0 parent grandParent |
528 | 166 |
531 | 167 ---- |
168 -- find node potition to insert or to delete, the pass will be in the stack | |
169 -- | |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
170 findNode : {n m : Level } {a k si : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) si -> (Node a k) -> (Node a k) -> (RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) si -> Node a k -> t) -> t |
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
171 findNode {n} {m} {a} {k} {si} {t} tree s n0 n1 next = pushStack s n1 (\ s -> findNode1 s n1) |
417 | 172 where |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
173 findNode2 : Stack (Node a k) si -> (Maybe (Node a k)) -> t |
515 | 174 findNode2 s Nothing = next tree s n0 |
175 findNode2 s (Just n) = findNode tree s n0 n next | |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
176 findNode1 : Stack (Node a k) si -> (Node a k) -> t |
515 | 177 findNode1 s n1 with (compare tree (key n0) (key n1)) |
529 | 178 ... | EQ = next tree s n0 |
515 | 179 ... | GT = findNode2 s (right n1) |
180 ... | LT = findNode2 s (left n1) | |
425 | 181 |
182 | |
518
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
183 leafNode : {n : Level } {a k : Set n} -> k -> a -> Node a k |
515 | 184 leafNode k1 value = record { |
185 key = k1 ; | |
186 value = value ; | |
187 right = Nothing ; | |
188 left = Nothing ; | |
529 | 189 color = Black |
518
c9f90f573efe
add more reblack tree in agda
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
515
diff
changeset
|
190 } |
417 | 191 |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
192 putRedBlackTree : {n m : Level } {a k si : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k si -> k -> a -> (RedBlackTree {n} {m} {t} a k si -> t) -> t |
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
193 putRedBlackTree {n} {m} {a} {k} {si} {t} tree k1 value next with (root tree) |
515 | 194 ... | Nothing = next (record tree {root = Just (leafNode k1 value) }) |
531 | 195 ... | Just n2 = clearStack (nodeStack tree) (\ s -> findNode tree s (leafNode k1 value) n2 (\ tree1 s n1 -> insertNode tree1 s n1 next)) |
515 | 196 |
522
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
197 getRedBlackTree : {n m : Level } {a k si : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k si -> k -> (RedBlackTree {n} {m} {t} a k si -> (Maybe (Node a k)) -> t) -> t |
f63a9a081b61
remove implementation from RedBlackTree.aga
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
521
diff
changeset
|
198 getRedBlackTree {_} {_} {a} {k} {_} {t} tree k1 cs = checkNode (root tree) |
417 | 199 where |
515 | 200 checkNode : Maybe (Node a k) -> t |
201 checkNode Nothing = cs tree Nothing | |
202 checkNode (Just n) = search n | |
203 where | |
204 search : Node a k -> t | |
205 search n with compare tree k1 (key n) | |
206 search n | LT = checkNode (left n) | |
207 search n | GT = checkNode (right n) | |
208 search n | EQ = cs tree (Just n) |