feat: add some BACKTRACKABLE sigs

This commit is contained in:
Simon Cruanes 2022-07-17 20:21:22 -04:00
parent 833fa8e038
commit ea752b5cf5
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
6 changed files with 53 additions and 29 deletions

View file

@ -18,10 +18,12 @@ module type HASH = sig
val hash : t -> int val hash : t -> int
end end
type 'a printer = Format.formatter -> 'a -> unit
module type PRINT = sig module type PRINT = sig
type t type t
val pp : t CCFormat.printer val pp : t printer
end end
module type EQ_HASH_PRINT = sig module type EQ_HASH_PRINT = sig
@ -37,4 +39,46 @@ module type EQ_ORD_HASH_PRINT = sig
include PRINT with type t := t include PRINT with type t := t
end 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

View file

@ -10,13 +10,6 @@ val push : 'a t -> 'a -> unit
val push_if_nonzero_level : 'a t -> 'a -> unit val push_if_nonzero_level : 'a t -> 'a -> unit
(** Push an element onto the stack if level > 0 *) (** Push an element onto the stack if level > 0 *)
val n_levels : _ t -> int include Sidekick_sigs.BACKTRACKABLE1_CB with type 'a t := 'a t
(** 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 *)
val iter : f:('a -> unit) -> 'a t -> unit val iter : f:('a -> unit) -> 'a t -> unit

View file

@ -16,14 +16,4 @@ val get : 'a t -> 'a
val update : 'a t -> ('a -> 'a) -> unit val update : 'a t -> ('a -> 'a) -> unit
(** Update the reference's current content *) (** Update the reference's current content *)
val push_level : _ t -> unit include Sidekick_sigs.BACKTRACKABLE1 with type 'a t := 'a t
(** 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]. *)

View file

@ -14,9 +14,8 @@ module type S = sig
val to_iter : 'a t -> (key * 'a) Iter.t val to_iter : 'a t -> (key * 'a) Iter.t
val add : 'a t -> key -> 'a -> unit val add : 'a t -> key -> 'a -> unit
val remove : _ t -> key -> unit val remove : _ t -> key -> unit
val push_level : _ t -> unit
val pop_levels : _ t -> int -> unit include Sidekick_sigs.BACKTRACKABLE1 with type 'a t := 'a t
val n_levels : _ t -> int
end end
module type ARG = sig module type ARG = sig

View file

@ -16,9 +16,8 @@ module type S = sig
val to_iter : 'a t -> (key * 'a) Iter.t val to_iter : 'a t -> (key * 'a) Iter.t
val add : 'a t -> key -> 'a -> unit val add : 'a t -> key -> 'a -> unit
val remove : _ t -> key -> unit val remove : _ t -> key -> unit
val push_level : _ t -> unit
val pop_levels : _ t -> int -> unit include Sidekick_sigs.BACKTRACKABLE1 with type 'a t := 'a t
val n_levels : _ t -> int
end end
module type ARG = sig module type ARG = sig

View file

@ -13,7 +13,7 @@ module Int_id = Int_id
module Int_tbl = Util.Int_tbl module Int_tbl = Util.Int_tbl
module Int_set = Util.Int_set module Int_set = Util.Int_set
module Int_map = Util.Int_map module Int_map = Util.Int_map
module IArray = IArray module Event = Event
module Backtrack_stack = Backtrack_stack module Backtrack_stack = Backtrack_stack
module Backtrackable_tbl = Backtrackable_tbl module Backtrackable_tbl = Backtrackable_tbl
module Backtrackable_ref = Backtrackable_ref module Backtrackable_ref = Backtrackable_ref
@ -24,4 +24,3 @@ module Stat = Stat
module Hash = Hash module Hash = Hash
module Profile = Profile module Profile = Profile
module Chunk_stack = Chunk_stack module Chunk_stack = Chunk_stack
module Intf = Sidekick_sigs