diff --git a/src/sat/Solver.ml b/src/sat/Solver.ml index 84f23ded..10be61c4 100644 --- a/src/sat/Solver.ml +++ b/src/sat/Solver.ml @@ -42,7 +42,13 @@ module Make(Plugin : PLUGIN) (* ### types ### *) (* a boolean variable (positive int) *) - module Var0 : INT_ID = Mk_int_id() + module Var0 : sig + include INT_ID + module Set : Set.S with type elt = t + end = struct + include Mk_int_id() + module Set = Util.Int_set + end type var = Var0.t (* a signed atom. +v is (v << 1), -v is (v<<1 | 1) *) diff --git a/src/util/Vec.ml b/src/util/Vec.ml index 782a8b6a..89759a51 100644 --- a/src/util/Vec.ml +++ b/src/util/Vec.ml @@ -31,6 +31,12 @@ let[@inline] copy t : _ t = let data = Array.copy t.data in {t with data} +let resize_ t x size = + let arr' = Array.make size x in + Array.blit t.data 0 arr' 0 t.sz; + t.data <- arr'; + () + (* grow the array *) let[@inline never] grow_to_double_size t x : unit = if Array.length t.data = Sys.max_array_length then ( @@ -39,9 +45,7 @@ let[@inline never] grow_to_double_size t x : unit = let size = min Sys.max_array_length (max 4 (2 * Array.length t.data)) in - let arr' = Array.make size x in - Array.blit t.data 0 arr' 0 (Array.length t.data); - t.data <- arr'; + resize_ t x size; assert (Array.length t.data > t.sz); () @@ -67,6 +71,17 @@ let[@inline] fast_remove t i = Array.unsafe_set t.data i @@ Array.unsafe_get t.data (t.sz - 1); t.sz <- t.sz - 1 +let prepend v ~into : unit = + if v.sz = 0 then () + else ( + if v.sz + into.sz > Array.length into.data then ( + resize_ into v.data.(0) (v.sz + into.sz); + ); + Array.blit into.data 0 into.data v.sz into.sz; (* shift elements *) + Array.blit v.data 0 into.data 0 v.sz; + ) + + let filter_in_place f vec = let i = ref 0 in while !i < size vec do diff --git a/src/util/Vec.mli b/src/util/Vec.mli index b4994de4..d00f060f 100644 --- a/src/util/Vec.mli +++ b/src/util/Vec.mli @@ -62,6 +62,10 @@ val fast_remove : 'a t -> int -> unit (** Remove element at index [i] without preserving order (swap with last element) *) +val prepend : 'a t -> into:'a t -> unit +(** [prepend v ~into] pushes all elements of [v] into [into], + at the beginning. consumes [v]. *) + val filter_in_place : ('a -> bool) -> 'a t -> unit (** [filter_in_place f v] removes from [v] the elements that do not satisfy [f] *)