Module Searray (.ml)

module Searray: sig .. end
Building and using extensible arrays, with type constraints on indices to avoid using an indice with a wrong array.
Author(s): Maxence Guesdon
Version: 0.1
Earray

type 'a ind 
To type indices.
type ('a, 'b) t 
The type of arrays is parametrized by the type of data ('b) and the type of the indices ('a, to have indices of type 'a ind).
val create : ?step:int -> unit -> ('a, 'b) t
Create a new extensible array. One should force the type of the created array to force the type of indices.
step : can be used to specify by how many cells the array is extended when it is too small. Default is 256.
val add : ('a, 'b) t -> 'b -> 'a ind
add t v adds a new value in the array, returning the indice of the new value.
val get : ('a, 'b) t -> 'a ind -> 'b
get t pos returns the value in t at position ind.
Raises Invalid_argument "index out of bounds" if there is no such value (i.e. the array is smaller than the given position.
val set : ('a, 'b) t -> 'a ind -> 'b -> unit
set t pos v sets the given value v in t at position pos.
Raises Invalid_argument "index out of bounds" if there is no such value (i.e. the array is smaller than the given position.
val find : ('a, 'b) t -> ('b -> int) -> 'a ind
find t pred returns the indice of the first value for which pred returns true.
Raises Not_found is no value verifies pred.
val copy : ?copy:('b -> 'b) -> ('a, 'b) t -> ('a, 'b) t
copy t returns a copy of the given array.
copy : can be used to specify a copy function for values.
val length : ('a, 'b) t -> int
length t returns the length of the array, that is the number of values in it.
val iteri : ('a ind -> 'b -> unit) -> ('a, 'b) t -> unit
Same as Array.iteri but on an extensible array.
val iter : ('b -> unit) -> ('a, 'b) t -> unit
Same as Array.iter but on an extensible array.
val fold_left : ('c -> 'b -> 'c) -> 'c -> ('a, 'b) t -> 'c
Same as Array.fold_left but on an extensible array.
val fold_right : ('b -> 'c -> 'c) -> ('a, 'b) t -> 'c -> 'c
Same as Array.fold_right but on an extensible array.
val fold_lefti : ('c -> 'a ind -> 'b -> 'c) -> 'c -> ('a, 'b) t -> 'c
Same as Array.fold_left but on an extensible array, and the function takes also the indice of the value.
val fold_righti : ('a ind -> 'b -> 'c -> 'c) -> ('a, 'b) t -> 'c -> 'c
Same as Array.fold_right but on an extensible array, and the function takes also the indice of the value.
val to_array : ('a, 'b) t -> 'b array
to_array t returns a regular array from an extensible array.
val mapi : ('a ind -> 'b -> 'c) -> ('a, 'b) t -> ('a, 'c) t
Same as Array.mapi but on an extensible array.
val mapi_as_list : ('a ind -> 'b -> 'c) -> ('a, 'b) t -> 'c list
Same as Searray.mapi but returns a list instead of an extensible array.
val insert : ('a, 'b) t -> 'a ind -> 'b -> unit
insert t pos v inserts a value v in array t at position pos.
Raises Invalid_argument if the position is too big, that is it is greater than the length of the array.
val int : 'a ind -> int
int pos convert an indice to a reguler integer.
val (@>) : ('a, 'b) t -> int -> 'a ind
t @> n converts a regular integer into a position for extensible array t. Beware that no check is done on the size of the array.
val (@~) : ('a, 'b) t -> int -> 'b
Same as Searray.get but use a regular integer as indice.
val (@@) : ('a, 'b) t -> 'a ind -> 'b
Same as Searray.get.
val (~~) : 'a ind -> int
Same as Searray.int.