From cf8b2b9ede58402a6e98d38985f7a399fcd72306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Nguy=E1=BB=85n?= Date: Sat, 28 Mar 2015 11:10:30 +0100 Subject: [PATCH] More factorisation between Bool and BoolVar modules. --- misc/bool.ml | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/misc/bool.ml b/misc/bool.ml index 3b52cb69..7277047d 100644 --- a/misc/bool.ml +++ b/misc/bool.ml @@ -126,17 +126,21 @@ struct | c -> [ fun ppf -> print f ppf c ] - let rec get accu pos neg = function - | True -> (pos,neg) :: accu + let rec get_aux rev accu pos neg = function + | True -> + let x = + if rev then (List.rev pos, List.rev neg) + else (pos,neg) + in x :: accu | False -> accu | Split (_,x, p,i,n) -> (*OPT: can avoid creating this list cell when pos or neg =False *) - let accu = get accu (x::pos) neg p in - let accu = get accu pos (x::neg) n in - let accu = get accu pos neg i in + let accu = get_aux rev accu (x::pos) neg p in + let accu = get_aux rev accu pos (x::neg) n in + let accu = get_aux rev accu pos neg i in accu - let get x = get [] [] [] x + let get x = get_aux false [] [] [] x let rec get' accu pos neg = function | True -> (pos,neg) :: accu @@ -346,22 +350,13 @@ struct let h = compute_hash v a False False in (Split (h,`Var v, a, False, False) :> t ) - let get x = - let rec aux accu pos neg = function - | True -> (List.rev pos, List.rev neg) :: accu - | False -> accu - | Split (_,x, p,i,n) -> - let accu = aux accu (x::pos) neg p in - let accu = aux accu pos (x::neg) n in - let accu = aux accu pos neg i in - accu - in aux [] [] [] x + let get x = get_aux true [] [] [] x let leafconj x = let rec aux accu = function | True -> accu | False -> accu - | Split (_,`Atm x, True,False,False) -> x :: accu + | Split (_,`Atm x, True,False,False) -> T.cup x accu | Split (_,`Atm x, _,_,_) -> assert false | Split (_,`Var x, p,i,n) -> let accu = aux accu p in @@ -369,25 +364,11 @@ struct let accu = aux accu i in accu in - List.fold_left T.cup T.empty (aux [] x) + (aux T.empty x) - let compute ~empty ~full ~cup ~cap ~diff ~atom b = - let rec aux = function - | True -> full - | False -> empty - | Split (_,`Atm x,True,_,_) when T.equal x T.empty -> empty - | Split (_,`Atm x,True,_,_) when T.equal x T.full -> full - | Split(_,x, p,i,n) -> - let x1 = atom x in - let p = cap x1 (aux p) in - let i = aux i in - let n = diff (aux n) x1 in - cup (cup p i) n - in - aux b - let empty = False let full = split0 (`Atm T.full) True False False + let is_empty = function False -> true | _ -> false let rec split x p i n = -- 2.22.0