diff options
Diffstat (limited to 'tools.ml')
-rwxr-xr-x | tools.ml | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -304,7 +304,7 @@ module type COMPARABLE_TYPE = sig type 'a t - val eq: 'a t -> 'b t -> ('a, 'b) cmp + val comp: 'a t -> 'b t -> ('a, 'b) cmp end @@ -317,7 +317,7 @@ module ArrayMap(Ord: COMPARABLE_TYPE) = struct let find: type a. a key -> t -> a = begin fun k (Val map) -> let rec find_ idx : a = begin let x, v = Array.get map idx in - match Ord.eq x k with + match Ord.comp x k with | Eq -> v | Lt -> find_ ((2 * idx) + 1) | Gt -> find_ ((2 * idx) + 2) @@ -326,7 +326,7 @@ module ArrayMap(Ord: COMPARABLE_TYPE) = struct end let from_list l = begin - let compare (key_x, _) (key_y, _) = match Ord.eq key_x key_y with + let compare (key_x, _) (key_y, _) = match Ord.comp key_x key_y with | Eq -> 0 | Lt -> -1 | Gt -> 1 @@ -401,7 +401,7 @@ module Map(Ord: COMPARABLE_TYPE) = struct let rec add: type a. a key -> a -> t -> t = begin fun x data t -> match t with | Empty -> Node(Empty, x, data, Empty, 1) | Node(l, v, d, r, h) -> - match Ord.eq x v with + match Ord.comp x v with | Eq -> Node(l, x, data, r, h) | Lt -> bal (add x data l) v d r | Gt -> bal l v d (add x data r) @@ -410,7 +410,7 @@ module Map(Ord: COMPARABLE_TYPE) = struct let rec find: type a. a key -> t -> a = begin fun x t -> match t with | Empty -> raise Not_found | Node(l, k, v, r, _) -> - match Ord.eq x k with + match Ord.comp x k with | Eq -> v | Lt -> find x l | Gt -> find x r @@ -419,12 +419,13 @@ module Map(Ord: COMPARABLE_TYPE) = struct let rec mem: type a. a key -> t -> bool = begin fun x t -> match t with | Empty -> false | Node(l, k, v, r, _) -> - match Ord.eq x k with + match Ord.comp x k with | Eq -> true | Lt -> mem x l | Gt -> mem x r end + (* let rec fold: ('a -> wrapper -> 'a) -> 'a -> t -> 'a = begin fun f init t -> match t with | Empty -> init @@ -433,4 +434,5 @@ module Map(Ord: COMPARABLE_TYPE) = struct let result = f res_left @@ Ex (k, v) in fold f result r end + *) end |