diff --git a/src/sigs/sidekick_sigs.ml b/src/sigs/sidekick_sigs.ml index 8fb16dd9..4cbcd6b6 100644 --- a/src/sigs/sidekick_sigs.ml +++ b/src/sigs/sidekick_sigs.ml @@ -18,10 +18,12 @@ module type HASH = sig val hash : t -> int end +type 'a printer = Format.formatter -> 'a -> unit + module type PRINT = sig type t - val pp : t CCFormat.printer + val pp : t printer end module type EQ_HASH_PRINT = sig @@ -37,4 +39,46 @@ module type EQ_ORD_HASH_PRINT = sig include PRINT with type t := t end -type 'a printer = Format.formatter -> 'a -> unit +module type DYN_BACKTRACKABLE = sig + val n_levels : unit -> int + (** Number of levels *) + + val push_level : unit -> unit + (** Push a backtracking point *) + + val pop_levels : int -> unit + (** [pop_levels n] removes [n] levels *) +end + +module type BACKTRACKABLE0 = sig + type t + + val n_levels : t -> int + (** Number of levels *) + + val push_level : t -> unit + (** Push a backtracking point *) + + val pop_levels : t -> int -> unit + (** [pop_levels st n] removes [n] levels *) +end + +module type BACKTRACKABLE1 = sig + type 'a t + + val n_levels : _ t -> int + (** Number of levels *) + + val push_level : _ t -> unit + (** Push a backtracking point *) + + val pop_levels : _ t -> int -> unit + (** [pop_levels st n] removes [n] levels *) +end + +module type BACKTRACKABLE1_CB = sig + include BACKTRACKABLE1 + + val pop_levels : 'a t -> int -> f:('a -> unit) -> unit + (** [pop_levels st n ~f] removes [n] levels, calling [f] on every removed item *) +end diff --git a/src/util/Backtrack_stack.mli b/src/util/Backtrack_stack.mli index ced0f18f..d71ea285 100644 --- a/src/util/Backtrack_stack.mli +++ b/src/util/Backtrack_stack.mli @@ -10,13 +10,6 @@ val push : 'a t -> 'a -> unit val push_if_nonzero_level : 'a t -> 'a -> unit (** Push an element onto the stack if level > 0 *) -val n_levels : _ t -> int -(** Number of levels *) - -val push_level : _ t -> unit -(** Push a backtracking point *) - -val pop_levels : 'a t -> int -> f:('a -> unit) -> unit -(** [pop_levels st n ~f] removes [n] levels, calling [f] on every removed item *) +include Sidekick_sigs.BACKTRACKABLE1_CB with type 'a t := 'a t val iter : f:('a -> unit) -> 'a t -> unit diff --git a/src/util/Backtrackable_ref.mli b/src/util/Backtrackable_ref.mli index bb686ff3..1b2fb56b 100644 --- a/src/util/Backtrackable_ref.mli +++ b/src/util/Backtrackable_ref.mli @@ -16,14 +16,4 @@ val get : 'a t -> 'a val update : 'a t -> ('a -> 'a) -> unit (** Update the reference's current content *) -val push_level : _ t -> unit -(** Push a backtracking level, copying the current value on top of some - stack. The [copy] function will be used if it was provided in {!create}. *) - -val n_levels : _ t -> int -(** Number of saved values *) - -val pop_levels : _ t -> int -> unit -(** Pop [n] levels, restoring to the value the reference was storing [n] calls - to [push_level] earlier. - @raise Invalid_argument if [n] is bigger than [n_levels]. *) +include Sidekick_sigs.BACKTRACKABLE1 with type 'a t := 'a t diff --git a/src/util/Backtrackable_tbl.ml b/src/util/Backtrackable_tbl.ml index 08c1bfc1..ccdcfdbf 100644 --- a/src/util/Backtrackable_tbl.ml +++ b/src/util/Backtrackable_tbl.ml @@ -14,9 +14,8 @@ module type S = sig val to_iter : 'a t -> (key * 'a) Iter.t val add : 'a t -> key -> 'a -> unit val remove : _ t -> key -> unit - val push_level : _ t -> unit - val pop_levels : _ t -> int -> unit - val n_levels : _ t -> int + + include Sidekick_sigs.BACKTRACKABLE1 with type 'a t := 'a t end module type ARG = sig diff --git a/src/util/Backtrackable_tbl.mli b/src/util/Backtrackable_tbl.mli index f5cb8896..90181801 100644 --- a/src/util/Backtrackable_tbl.mli +++ b/src/util/Backtrackable_tbl.mli @@ -16,9 +16,8 @@ module type S = sig val to_iter : 'a t -> (key * 'a) Iter.t val add : 'a t -> key -> 'a -> unit val remove : _ t -> key -> unit - val push_level : _ t -> unit - val pop_levels : _ t -> int -> unit - val n_levels : _ t -> int + + include Sidekick_sigs.BACKTRACKABLE1 with type 'a t := 'a t end module type ARG = sig diff --git a/src/util/Sidekick_util.ml b/src/util/Sidekick_util.ml index e1ffadf7..44a0af18 100644 --- a/src/util/Sidekick_util.ml +++ b/src/util/Sidekick_util.ml @@ -13,7 +13,7 @@ module Int_id = Int_id module Int_tbl = Util.Int_tbl module Int_set = Util.Int_set module Int_map = Util.Int_map -module IArray = IArray +module Event = Event module Backtrack_stack = Backtrack_stack module Backtrackable_tbl = Backtrackable_tbl module Backtrackable_ref = Backtrackable_ref @@ -24,4 +24,3 @@ module Stat = Stat module Hash = Hash module Profile = Profile module Chunk_stack = Chunk_stack -module Intf = Sidekick_sigs