6 imports |
6 imports |
7 AA_Set |
7 AA_Set |
8 Lookup2 |
8 Lookup2 |
9 begin |
9 begin |
10 |
10 |
11 fun update :: "'a::cmp \<Rightarrow> 'b \<Rightarrow> ('a*'b) aa_tree \<Rightarrow> ('a*'b) aa_tree" where |
11 fun update :: "'a::linorder \<Rightarrow> 'b \<Rightarrow> ('a*'b) aa_tree \<Rightarrow> ('a*'b) aa_tree" where |
12 "update x y Leaf = Node 1 Leaf (x,y) Leaf" | |
12 "update x y Leaf = Node 1 Leaf (x,y) Leaf" | |
13 "update x y (Node lv t1 (a,b) t2) = |
13 "update x y (Node lv t1 (a,b) t2) = |
14 (case cmp x a of |
14 (case cmp x a of |
15 LT \<Rightarrow> split (skew (Node lv (update x y t1) (a,b) t2)) | |
15 LT \<Rightarrow> split (skew (Node lv (update x y t1) (a,b) t2)) | |
16 GT \<Rightarrow> split (skew (Node lv t1 (a,b) (update x y t2))) | |
16 GT \<Rightarrow> split (skew (Node lv t1 (a,b) (update x y t2))) | |
17 EQ \<Rightarrow> Node lv t1 (x,y) t2)" |
17 EQ \<Rightarrow> Node lv t1 (x,y) t2)" |
18 |
18 |
19 fun delete :: "'a::cmp \<Rightarrow> ('a*'b) aa_tree \<Rightarrow> ('a*'b) aa_tree" where |
19 fun delete :: "'a::linorder \<Rightarrow> ('a*'b) aa_tree \<Rightarrow> ('a*'b) aa_tree" where |
20 "delete _ Leaf = Leaf" | |
20 "delete _ Leaf = Leaf" | |
21 "delete x (Node lv l (a,b) r) = |
21 "delete x (Node lv l (a,b) r) = |
22 (case cmp x a of |
22 (case cmp x a of |
23 LT \<Rightarrow> adjust (Node lv (delete x l) (a,b) r) | |
23 LT \<Rightarrow> adjust (Node lv (delete x l) (a,b) r) | |
24 GT \<Rightarrow> adjust (Node lv l (a,b) (delete x r)) | |
24 GT \<Rightarrow> adjust (Node lv l (a,b) (delete x r)) | |