Commit 8796e6aa authored by Giuseppe Castagna's avatar Giuseppe Castagna

Commited for a bug

parent 7a7520a0
......@@ -103,7 +103,7 @@ let is_empty (RBtree('a) -> Bool) (*better type (Any\[] -> `false ; [] ->`true
let member (x : 'a) (t : RBtree('a)) : Bool =
(* better type: 'a -> ([] -> `false & RBtree('a) -> Bool) *)
(* better type: 'a -> ([] -> `false) & (RBtree('a) -> Bool) *)
match t with
| [] -> `false
| <_ elem=y>[ left right ] ->
......@@ -116,3 +116,54 @@ let singleton (x : 'a): Btree('a) = <black elem=x>[ [] [] ]
let cardinal ( RBtree('a) -> Int ) (* better type: [] -> 0, Any\[] -> [1--*] *)
| [] -> 0
| <_ ..>[ l r ] -> cardinal l + cardinal r + 1
(* The though case: deletion *)
(* remove the rightmost leave of the tree and return a flag to state
whether the resulting tree decreased the the depth of black nodes
let remove_min (RBtree('a)\[] -> [RBtree('a) Bool 'a])
(* black leaf: remove it and flag the depth decrease *)
| <black elem=x>[ [] [] ] ->
[ [] `true x ]
(* black node with red child: promote the child to black *)
| <black elem=x>[ ([] <red elem=y>[ l r ])
| (<red elem=y>[ l r ] [] )] ->
[ <black elem=y>[ l r ] `false x ]
(* you cannot have a red node with one empty sibling *)
| <black elem=x>[ ([] <red ..>Any)
| (<red ..>Any []) ] ->
raise "false"
(* red node with at least on empty child : remove it without any flag *)
| <red elem=x>[ ([] n) | (n []) ] ->
[ n `false x ]
(* general case of a node with two non empty childs *)
| <(c) elem=x>[ l r ] ->
let [ ll d e ] = remove_min l in
let tree = <(c) elem=x>[ ll r] in
if d then
(bubble_left tree)@[e]
else
[ tree `false e ]
*)
(* BUG TYPE ERROR *)
let blackify( (<_ ('a)>'b) -> <black ('a)>'b )
| <_ x>y -> <black x>y
| _ -> raise "false"
let redify( (<_ ('a)>'b) -> <black ('a)>'b )
| <_ x>y -> <red x>y
(*
let bubble_left
| <(c) elem=e>[ l r] ->
(<black elem=e>[ (blackify l) (balance(redify r)) ], c=`black]
*)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment