1. james woodyatt
  2. oni

Commits

jhwoodyatt  committed cb4dbe1

Minor improvements to [delete].

  • Participants
  • Parent commits 311cc86
  • Branches default

Comments (0)

Files changed (1)

File cf/cf_rbtree.ml

View file
     let ifdz_b_ = function R (z, a, b) -> B (z, a, b), false | u -> u, true
     
     let rec delete_aux_ k = function
-        | Z -> raise Not_found
-        | B (y, a, b) -> delete_aux_mirror_ cons_b_ ifdz_b_ k y a b
-        | R (y, a, b) -> delete_aux_mirror_ cons_r_ ifdz_r_ k y a b
-
+        | Z ->
+            raise Not_found
+        | B (y, a, b) ->
+            delete_aux_mirror_ cons_b_ ifdz_b_ k y a b
+        | R (y, a, b) ->
+            delete_aux_mirror_ cons_r_ ifdz_r_ k y a b
+    
     and delete_aux_mirror_ cons ifdz k y a b =
         let d = N.kcompare k y in
-        if d < 0 then begin
+        if d > 0 then begin
+            let b, r = delete_aux_ k b in
+            let n = cons y a b in
+            if r then l_repair_ n else n, false
+        end
+        else if d < 0 then begin
             let a, r = delete_aux_ k a in
             let n = cons y a b in
             if r then r_repair_ n else n, false
         end
-        else if d > 0 then begin
-            let b, r = delete_aux_ k b in
-            let n = cons y a b in
-            if r then l_repair_ n else n, false
-        end
-        else if b = Z then begin
+        else match b with
+        | Z ->
             ifdz a
-        end
-        else begin
+        | b ->
             let b, z, d = extract_min_ b in
             let n = cons z a b in
             if d then l_repair_ n else n, false
-        end
-
+        
     let delete k u =
         try
             let u, _ = delete_aux_ k u in