1. Roma Sokolov
  2. kamlostuff

Commits

Roma Sokolov  committed ae5ea2b

next improvement

  • Participants
  • Parent commits 9e9459c
  • Branches default

Comments (0)

Files changed (1)

File btrees.ml

View file
       let empty = E
         
       let insert x st = 
-        let rec aux = function 
+        let rec loop_none = function 
           | E -> T (E, x, E)
           | T (a, y, b) when (Element.lt x y) -> 
-              T (aux a, y, b)
-          | T (a, y, b) when (Element.lt y x) ->
-              T (a, y, aux b)
-          | s -> raise Exit
-        in try aux st with Exit -> st
+              let nl = loop_none a in T (nl, y, b)
+          | T (a, y, b) ->
+              let nr = loop_some y b in T (a, y, nr)
+        and loop_some last = function 
+          | E when x = last -> raise Exit
+          | E -> T (E, x, E)
+          | T (a, y, b) when (Element.lt x y) ->
+              let nl = loop_some last a in T (nl, y, b)
+          | T (a, y, b) -> 
+              let nr = loop_some last b in T (a, y, nr)
+        in try loop_none st with Exit -> st
                         
       let  member x collection = 
         let rec loop_none = function