Module Res.MakeArray

Functor that creates resizable parameterized arrays from reallocation strategies.

Parameters

Signature

Signatures and types
module Strategy = S

Module implementing the reallocation strategy

type strategy = Strategy.t

Type of reallocation strategy

type 'a t

Type of parameterized resizable arrays

Index and length information
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

Getting and setting
val get : 'a t ‑> int ‑> 'a

get ra n

val set : 'a t ‑> int ‑> 'a ‑> unit

set ra n sets the nth element of ra.

Creation of resizable arrays
val sempty : strategy ‑> 'a t

sempty s

val empty : unit ‑> 'a t

empty () same as sempty but uses default strategy.

val screate : strategy ‑> int ‑> 'a ‑> 'a t

screate s n el

val create : int ‑> 'a ‑> 'a t

create n el same as screate but uses default strategy.

val smake : strategy ‑> int ‑> 'a ‑> 'a t

smake s n el same as screate.

val make : int ‑> 'a ‑> 'a t

make n el same as create.

val sinit : strategy ‑> int ‑> (int ‑> 'a) ‑> 'a t

sinit s n f

val init : int ‑> (int ‑> 'a) ‑> 'a t

init n f sames as sinit but uses default strategy.

Strategy handling
val get_strategy : 'a t ‑> strategy

get_strategy ra

val set_strategy : 'a t ‑> strategy ‑> unit

set_strategy ra s sets the reallocation strategy of resizable array ra to s, possibly causing an immediate reallocation.

val put_strategy : 'a t ‑> strategy ‑> unit

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.

Matrix functions
val make_matrix : int ‑> int ‑> 'a ‑> 'a t t

make_matrix sx sy el creates a (resizable) matrix of dimensions sx and sy containing element el only. Both dimensions are controlled by the default strategy.

Copying, blitting and range extraction
val copy : 'a t ‑> 'a t

copy ra

val sub : 'a t ‑> int ‑> int ‑> 'a t

sub ra ofs len

val fill : 'a t ‑> int ‑> int ‑> 'a ‑> 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.

val blit : 'a t ‑> int ‑> 'a t ‑> int ‑> int ‑> unit

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.

Combining resizable arrays
val append : 'a t ‑> 'a t ‑> 'a t

append ra1 ra2

val concat : 'a t list ‑> 'a t

concat l

Adding and removing elements
val add_one : 'a t ‑> 'a ‑> 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.

Swapping
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.

Array conversions
val to_array : 'a t ‑> 'a array

to_array ra converts a resizable array to a standard one.

val sof_array : strategy ‑> 'a array ‑> 'a t

sof_array s ar converts a standard array to a resizable one, using strategy s.

val of_array : 'a array ‑> 'a t

of_array ar converts a standard array to a resizable one using the default strategy.

List conversions
val to_list : 'a t ‑> 'a list

to_list ra converts resizable array ra to a list.

val sof_list : strategy ‑> 'a list ‑> 'a t

sof_list s l creates a resizable array using strategy s and the elements in list l.

val of_list : 'a list ‑> 'a t

of_list l creates a resizable array using the default strategy and the elements in list l.

Iterators
val iter : ('a ‑> unit) ‑> 'a t ‑> unit

iter f ra applies the unit-function f to each element in resizable array ra.

val map : ('a ‑> 'b) ‑> 'a t ‑> 'b t

map f ra

val iteri : (int ‑> 'a ‑> unit) ‑> 'a t ‑> unit

iteri f ra applies the unit-function f to each index and element in resizable array ra.

val mapi : (int ‑> 'a ‑> 'b) ‑> 'a t ‑> 'b t

mapi f ra

val fold_left : ('b ‑> 'a ‑> '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 ‑> '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.

Scanning of resizable arrays
val for_all : ('a ‑> bool) ‑> 'a t ‑> bool

for_all p ra

val exists : ('a ‑> bool) ‑> 'a t ‑> bool

exists p ra

val mem : 'a ‑> 'a t ‑> bool

mem el ra

val memq : 'a ‑> 'a t ‑> bool

memq el ra

val pos : 'a ‑> 'a t ‑> int option

pos el ra

val posq : 'a ‑> 'a t ‑> int option

posq el ra

Searching of resizable arrays
val find : ('a ‑> bool) ‑> 'a t ‑> 'a

find p ra

val find_index : ('a ‑> bool) ‑> 'a t ‑> int ‑> int

find_index p ra pos

val filter : ('a ‑> bool) ‑> 'a t ‑> 'a t

filter p ra

val find_all : ('a ‑> bool) ‑> 'a t ‑> 'a t

find_all p ra is the same as filter

val filter_in_place : ('a ‑> bool) ‑> 'a t ‑> unit

filter_in_place p ra as filter, but filters in place.

val partition : ('a ‑> bool) ‑> 'a t ‑> 'a t * 'a t

partition p ra

UNSAFE STUFF - USE WITH CAUTION!
val unsafe_get : 'a t ‑> int ‑> 'a
val unsafe_set : 'a t ‑> int ‑> 'a ‑> unit
val unsafe_sub : 'a t ‑> int ‑> int ‑> 'a t
val unsafe_fill : 'a t ‑> int ‑> int ‑> 'a ‑> unit
val unsafe_blit : 'a t ‑> int ‑> 'a t ‑> int ‑> int ‑> 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