Res.Weak
Resizable weak array using the default reallocation strategy.
module Strategy = DefStrat
Module implementing the reallocation strategy
type strategy = Strategy.t
Type of reallocation strategy
val length : 'a t -> int
length ra
val lix : 'a t -> int
lix ra
val real_length : 'a t -> int
real_length ra
val real_lix : 'a t -> int
real_lix ra
val get : 'a t -> int -> 'a option
get ra n
val get_copy : 'a t -> int -> 'a option
get_copy ra n
see documentation of module Weak
in the standard distribution.
val check : 'a t -> int -> bool
check ra n
val set : 'a t -> int -> 'a option -> unit
set ra n
sets the n
th element of ra
.
val empty : unit -> 'a t
empty ()
same as sempty
but uses default strategy.
val create : int -> 'a t
create n
same as screate
but uses default strategy.
val init : int -> (int -> 'a option) -> 'a t
init n f
sames as sinit
but uses default strategy.
set_strategy ra s
sets the reallocation strategy of resizable array ra
to s
, possibly causing an immediate reallocation.
put_strategy ra s
sets the reallocation strategy of resizable array ra
to s
. Reallocation is only done at later changes in size.
val enforce_strategy : 'a t -> unit
enforce_strategy ra
forces a reallocation if necessary (e.g. after a put_strategy
).
val fill : 'a t -> int -> int -> 'a option -> unit
fill ra ofs len el
fills resizable array ra
from offset ofs
with len
elements el
, possibly adding elements at the end. Raises Invalid_argument
if offset ofs
is larger than the length of the array.
blit ra1 ofs1 ra2 ofs2 len
blits resizable array ra1
onto ra2
reading len
elements from offset ofs1
and writing them to ofs2
, possibly adding elements at the end of ra2. Raises Invalid_argument
if ofs1
and len
do not designate a valid subarray of ra1
or if ofs2
is larger than the length of ra2
.
val add_one : 'a t -> 'a option -> unit
add_one ra el
adds element el
to resizable array ra
, possibly causing a reallocation.
val remove_one : 'a t -> unit
remove_one ra
removes the last element of resizable array ra
, possibly causing a reallocation.
val remove_n : 'a t -> int -> unit
remove_n ra n
removes the last n elements of resizable array ra
, possibly causing a reallocation.
val remove_range : 'a t -> int -> int -> unit
remove_range ra ofs len
removes len
elements from resizable array ra
starting at ofs
and possibly causing a reallocation.
val clear : 'a t -> unit
clear ra
removes all elements from resizable array ra
, possibly causing a reallocation.
val swap : 'a t -> int -> int -> unit
swap ra n m
swaps elements at indices n
and m
.
val swap_in_last : 'a t -> int -> unit
swap_in_last ra n
swaps the last element with the one at position n
.
val to_std : 'a t -> 'a Stdlib.Weak.t
to_std ra
converts a resizable weak array to a standard one.
sof_std s ar
converts a standard weak array to a resizable one, using strategy s
.
val of_std : 'a Stdlib.Weak.t -> 'a t
of_std ar
converts a standard weak array to a resizable one using the default strategy.
val to_list : 'a t -> 'a option list
to_list ra
converts resizable array ra
to a list.
val of_list : 'a option list -> 'a t
of_list l
creates a resizable array using the default strategy and the elements in list l
.
val iter : ('a option -> unit) -> 'a t -> unit
iter f ra
applies the unit-function f
to each element in resizable array ra
.
val iteri : (int -> 'a option -> unit) -> 'a t -> unit
iteri f ra
applies the unit-function f
to each index and element in resizable array ra
.
val fold_left : ('b -> 'a option -> 'b) -> 'b -> 'a t -> 'b
fold_left f a ra
left-folds values in resizable array ra
using function f
and start accumulator a
.
val fold_right : ('a option -> 'b -> 'b) -> 'a t -> 'b -> 'b
fold_right f a ra
right-folds values in resizable array ra
using function f
and start accumulator a
.
val for_all : ('a option -> bool) -> 'a t -> bool
for_all p ra
val exists : ('a option -> bool) -> 'a t -> bool
exists p ra
val mem : 'a option -> 'a t -> bool
mem el ra
val memq : 'a option -> 'a t -> bool
memq el ra
val pos : 'a option -> 'a t -> int option
pos el ra
val posq : 'a option -> 'a t -> int option
posq el ra
val find : ('a option -> bool) -> 'a t -> 'a option
find p ra
val find_index : ('a option -> bool) -> 'a t -> int -> int
find_index p ra pos
val filter_in_place : ('a option -> bool) -> 'a t -> unit
filter_in_place p ra
as filter
, but filters in place.
val unsafe_get : 'a t -> int -> 'a option
val unsafe_set : 'a t -> int -> 'a option -> unit
val unsafe_fill : 'a t -> int -> int -> 'a option -> unit
val unsafe_remove_one : 'a t -> unit
val unsafe_remove_n : 'a t -> int -> unit
val unsafe_swap : 'a t -> int -> int -> unit
val unsafe_swap_in_last : 'a t -> int -> unit