mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-05 19:00:33 -05:00
feat: add some BACKTRACKABLE sigs
This commit is contained in:
parent
833fa8e038
commit
ea752b5cf5
6 changed files with 53 additions and 29 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue