diff --git a/otherlibs/stdune/src/array.ml b/otherlibs/stdune/src/array.ml index 408047a9a91..5d8f56f0103 100644 --- a/otherlibs/stdune/src/array.ml +++ b/otherlibs/stdune/src/array.ml @@ -1,3 +1,11 @@ +module Array = Stdlib.Array + +let swap arr i j = + let first, second = arr.(i), arr.(j) in + arr.(i) <- second; + arr.(j) <- first +;; + module T = struct include ArrayLabels diff --git a/otherlibs/stdune/src/array.mli b/otherlibs/stdune/src/array.mli index d4de6c04e6a..cd0e687f75a 100644 --- a/otherlibs/stdune/src/array.mli +++ b/otherlibs/stdune/src/array.mli @@ -4,6 +4,7 @@ val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool val map : 'a t -> f:('a -> 'b) -> 'b t val exists : 'a t -> f:('a -> bool) -> bool val fold_right : 'a t -> f:('a -> 'acc -> 'acc) -> init:'acc -> 'acc +val swap : 'a t -> int -> int -> unit module Immutable : sig type 'a t diff --git a/src/0install-solver/sat.ml b/src/0install-solver/sat.ml index 56bd10c081b..f737aa032fe 100644 --- a/src/0install-solver/sat.ml +++ b/src/0install-solver/sat.ml @@ -86,12 +86,6 @@ let log_debug p = Pp.to_fmt Format.std_formatter (Pp.vbox (Pp.hovbox (Pp.text "sat: " ++ p)) ++ Pp.cut) ;; -let swap arr i j = - let first, second = arr.(i), arr.(j) in - arr.(i) <- second; - arr.(j) <- first -;; - module Make (User : USER) = struct type clause = < (* [lit] is now [True]. Add any new deductions. @@ -401,7 +395,7 @@ module Make (User : USER) = struct - value[lits[0]] = Undecided | True - value[lits[1]] = False If it's the other way around, just swap them before we start. *) - if lit_equal lits.(0) (neg lit) then swap lits 0 1; + if lit_equal lits.(0) (neg lit) then Array.swap lits 0 1; if lit_value lits.(0) = True then ( (* We're already satisfied. Do nothing. *) @@ -422,7 +416,7 @@ module Make (User : USER) = struct | Undecided | True -> (* If it's True then we've already done our job, so this means we don't get notified unless we backtrack, which is fine. *) - swap lits 1 i; + Array.swap lits 1 i; watch_lit (neg lits.(1)) (self :> clause); true | False -> find_not_false (i + 1)) @@ -572,7 +566,7 @@ module Make (User : USER) = struct best_level := level; best_i := i) done; - swap lits 1 !best_i); + Array.swap lits 1 !best_i); (* Watch the first two literals in the clause (both must be undefined at this point). *) let watch i = watch_lit (neg lits.(i)) clause in