mirror of
https://github.com/c-cube/sidekick.git
synced 2026-01-26 03:16:41 -05:00
if plugin data is updated before `Th_data.on_pre_merge` is called, it never has a chance to observe the un-merged data and react accordingly. we need to ensure that all handlers see the same data before any change is made.
104 lines
2.9 KiB
OCaml
104 lines
2.9 KiB
OCaml
(** Vectors
|
|
|
|
A resizable array, workhorse of imperative programming :-).
|
|
This implementation originated in alt-ergo-zero but has been basically rewritten
|
|
from scratch several times since.
|
|
*)
|
|
|
|
type 'a t
|
|
(** Abstract type of vectors of 'a *)
|
|
|
|
val make : int -> 'a -> 'a t
|
|
(** [make cap dummy] creates a new vector filled with [dummy]. The vector
|
|
is initially empty but its underlying array has capacity [cap].
|
|
[dummy] will stay alive as long as the vector *)
|
|
|
|
val create : unit -> 'a t
|
|
|
|
val to_list : 'a t -> 'a list
|
|
(** Returns the list of elements of the vector *)
|
|
|
|
val to_array : 'a t -> 'a array
|
|
val of_list : 'a list -> 'a t
|
|
|
|
val clear : 'a t -> unit
|
|
(** Set size to 0, doesn't free elements *)
|
|
|
|
val ensure_size : 'a t -> elt:'a -> int -> unit
|
|
(** ensure size is at least [n] *)
|
|
|
|
val ensure_size_with : 'a t -> (unit -> 'a) -> int -> unit
|
|
(** ensure size is at least [n] *)
|
|
|
|
val shrink : 'a t -> int -> unit
|
|
(** [shrink vec sz] resets size of [vec] to [sz].
|
|
Assumes [sz >=0 && sz <= size vec] *)
|
|
|
|
val pop_exn : 'a t -> 'a
|
|
(** Pop last element and return it.
|
|
@raise Invalid_argument if the vector is empty *)
|
|
|
|
val pop : 'a t -> 'a option
|
|
val size : 'a t -> int
|
|
val is_empty : 'a t -> bool
|
|
|
|
val is_full : 'a t -> bool
|
|
(** Is the capacity of the vector equal to the number of its elements? *)
|
|
|
|
val push : 'a t -> 'a -> unit
|
|
(** Push element into the vector *)
|
|
|
|
val get : 'a t -> int -> 'a
|
|
(** get the element at the given index, or
|
|
@raise Invalid_argument if the index is not valid *)
|
|
|
|
val set : 'a t -> int -> 'a -> unit
|
|
(** set the element at the given index, either already set or the first
|
|
free slot if [not (is_full vec)], or
|
|
@raise Invalid_argument if the index is not valid *)
|
|
|
|
val copy : 'a t -> 'a t
|
|
(** Fresh copy *)
|
|
|
|
val fast_remove : 'a t -> int -> unit
|
|
(** Remove element at index [i] without preserving order
|
|
(swap with last element) *)
|
|
|
|
val append : into:'a t -> 'a t -> unit
|
|
(** [append ~into v] pushes elements of [v] in the vector [into] *)
|
|
|
|
val prepend : 'a t -> into:'a t -> unit
|
|
(** [prepend v ~into] pushes all elements of [v] into [into],
|
|
at the beginning. consumes [v]. *)
|
|
|
|
val filter_in_place : ('a -> bool) -> 'a t -> unit
|
|
(** [filter_in_place f v] removes from [v] the elements that do
|
|
not satisfy [f] *)
|
|
|
|
val sort : 'a t -> ('a -> 'a -> int) -> unit
|
|
(** Sort in place the array *)
|
|
|
|
val iter : f:('a -> unit) -> 'a t -> unit
|
|
(** Iterate on elements *)
|
|
|
|
val rev_iter : f:('a -> unit) -> 'a t -> unit
|
|
val to_iter : 'a t -> 'a Iter.t
|
|
|
|
val iteri : f:(int -> 'a -> unit) -> 'a t -> unit
|
|
(** Iterate on elements with their index *)
|
|
|
|
val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
|
|
(** Fold over elements *)
|
|
|
|
val exists : ('a -> bool) -> 'a t -> bool
|
|
(** Does there exist an element that satisfies the predicate? *)
|
|
|
|
val for_all : ('a -> bool) -> 'a t -> bool
|
|
(** Do all elements satisfy the predicate? *)
|
|
|
|
val pp :
|
|
?sep:string ->
|
|
(Format.formatter -> 'a -> unit) ->
|
|
Format.formatter ->
|
|
'a t ->
|
|
unit
|