diff options
Diffstat (limited to 'lib/splay/splay.ml')
| -rw-r--r-- | lib/splay/splay.ml | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/lib/splay/splay.ml b/lib/splay/splay.ml index bf0a2ac..979d017 100644 --- a/lib/splay/splay.ml +++ b/lib/splay/splay.ml @@ -28,40 +28,40 @@ module Make (El : KEY) = struct let (Node (l, y, r)) = t in begin match El.compare x (fst y) with | 0 -> t - | v when v < 0 -> begin - match l with + | v when v < 0 -> + begin match l with | Leaf -> t - | Node (ll, z, rr) -> begin - match El.compare x (fst z) with + | Node (ll, z, rr) -> + begin match El.compare x (fst z) with | 0 -> Node (ll, z, Node (rr, y, r)) - | v when v < 0 -> begin - match ll with + | v when v < 0 -> + begin match ll with | Leaf -> Node (ll, z, Node (rr, y, r)) | Node _ as ll -> let (Node (newL, newV, newR)) = splay x ll in Node (newL, newV, Node (newR, z, Node (rr, y, r))) - end + end | _ -> ( match rr with | Leaf -> Node (ll, z, Node (rr, y, r)) | Node _ as rr -> let (Node (newL, newV, newR)) = splay x rr in Node (Node (ll, z, newL), newV, Node (newR, y, r))) - end - end + end + end | _ -> ( match r with | Leaf -> t | Node (ll, z, rr) -> ( match El.compare x (fst z) with | 0 -> Node (Node (l, y, ll), z, rr) - | v when v < 0 -> begin - match ll with + | v when v < 0 -> + begin match ll with | Leaf -> Node (Node (l, y, ll), z, rr) | Node _ as ll -> let (Node (newL, newV, newR)) = splay x ll in Node (Node (l, y, newL), newV, Node (newR, z, rr)) - end + end | _ -> ( match rr with | Leaf -> Node (Node (l, y, ll), z, rr) @@ -128,8 +128,8 @@ module Make (El : KEY) = struct let root' = splay key root in let (Node (l, c', r)) = root' in begin match El.compare (fst c') key with - | 0 -> begin - match _subtree_maximum l with + | 0 -> + begin match _subtree_maximum l with | Node (l, c, Leaf) -> T (ref (Node (l, c, r))) | Node (_, _, _) -> raise Not_found | Leaf -> ( @@ -137,7 +137,7 @@ module Make (El : KEY) = struct | Leaf -> empty () | Node (Leaf, c, r) -> T (ref (Node (l, c, r))) | Node (_, _, _) -> raise Not_found) - end + end (* The key is not present, return the splayed tree *) | _ -> T (ref root') end @@ -155,11 +155,11 @@ module Make (El : KEY) = struct let c = (key, value) in (_fold [@tailcall]) ((c, Branch right) :: acc) v left (* We have nothing left, we process the values delayed *) - | Leaf -> begin - match acc with + | Leaf -> + begin match acc with | [] -> v | (c, Branch right) :: tl -> (_fold [@tailcall]) tl (f v c) right - end + end in _fold [] init !t @@ -174,14 +174,14 @@ module Make (El : KEY) = struct let pp formatter (T t) = let leaf_id = ref 0 in let repr_edge from formatter dest = - Format.fprintf formatter "\"%a\" -> \"%a\"@;" El.pp from El.pp dest + Format.fprintf formatter "@,\"%a\" -> \"%a\"" El.pp from El.pp dest in let rec repr' : type b. El.t -> Format.formatter -> (b, _) branch -> unit = fun parent formatter -> function | Leaf -> - Format.fprintf formatter "leaf_%d [shape=point]@;" !leaf_id; - Format.fprintf formatter "\"%a\" -> leaf_%d@;" El.pp parent !leaf_id; + Format.fprintf formatter "@,leaf_%d [shape=point]" !leaf_id; + Format.fprintf formatter "@,\"%a\" -> leaf_%d" El.pp parent !leaf_id; incr leaf_id | Node (l, c, r) -> let key = fst c in @@ -193,6 +193,6 @@ module Make (El : KEY) = struct | Leaf -> Format.fprintf formatter "digraph G {}" | Node (l, c, r) -> let key = fst c in - Format.fprintf formatter "@[<v 2>digraph G {@;%a%a@]}" (repr' key) l + Format.fprintf formatter "@[<v 2>digraph G {%a%a@]@,}" (repr' key) l (repr' key) r end |
