package soteria

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Reversible.Make_mutable_array

An efficient, in-place, mutable reversible state for an array of values, where checkpoints are represented by indices in the array.

Parameters

module Elt : sig ... end

Signature

include Mutable
type t
val init : unit -> t

Create a new reversible state initialized with the default value.

val backtrack_n : t -> int -> unit

Remove the last n checkpoints from state.

val save : t -> unit

Save the current state as a new checkpoint.

val reset : t -> unit

Clear all checkpoints and reset to the default value.

val truncate_to_checkpoint : t -> unit

This is an optimised version of backtrack_n 1 t; save t: it truncates the values accumulated since the last checkpoint, effectively backtracking to the last checkpoint, but without removing it. This is useful when the last checkpoint is still needed, but the changes since then should be discarded.

val is_at_checkpoint : t -> bool

Returns true if no values have been added since the last checkpoint.

val peek_last : t -> Elt.t

Gets the last value added to the array

val add : t -> Elt.t -> unit

Adds a value to the array.

val iter : t -> (Elt.t -> unit) -> unit

Iterate over all values in the current state.

val find_map : t -> (Elt.t -> 'a option) -> 'a option

Find the first value in the current state for which f returns Some, and return that value.

val to_seq_rev : t -> Elt.t Seq.t

Return a sequence of all values in the current state, in reverse order.