mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 11:15:43 -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
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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]. *)
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue