Page
Library
Module
Module type
Parameter
Class
Class type
Source
AgridSourceAdjustable grids are two dimensional arrays whose width/height can be changed by adding or removing row/column at either end (one at a time).
Implemented using the flex-array library by Jean-Christophe Filliâtre.
The type of grids. This is an immutable data structure. Values of type 'a t can be compared using structural equality = (provided the elements of type 'a can).
dim g returns a pair in which the first element is the width of g and the second one its height.
get g ~x ~y returns the element at width-index ~x and height-index ~y in grid g. Index start at 0.
get_row g y returns the row at height-index y in grid g. Index start at 0.
get_col g x returns the column at width-index x in grid g. Index start at 0.
of_array a returns a grid from the two dimensional array a with the same height, width and order.
of_list l returns a grid from the two dimensional list l with the same height, width and order.
set g ~x ~y v returns a new grid where all elements are identical to those of g, except at width-index x and height-index y where the element is v.
cons_row row grid returns a new grid obtained by appending the row row at the height-axis front of grid g.
snow_row grid row returns a new grid obtained by appending the row row at the height-axis end of grid g.
cons_col col grid returns a new grid obtained by appending the column col at the width-axis front of grid g.
snow_col grid col returns a new grid obtained by appending the column col at the width-axis end of grid g.
tail_row g returns a new grid obtained by removing the row at the height-axis front of grid g.
liat_row g returns a new grid obtained by removing the row at the height-axis end of grid g.
tail_col g returns a new grid obtained by removing the column at the width-axis front of grid g.
liat_col g returns a new grid obtained by removing the column at the width-axis end of grid g.
iter f g applies function f in turn to all the elements of g. It goes row by row. It is equivalent to f (get g ~x:0 ~y:0); f (get g ~x:1 ~y:0); ...; f (get g ~x:(w - 1) ~y:0); ...; f (get g ~x:0 ~y:(h - 1)); f (get g ~x:1 ~y:(h -1)); ...; f (get g ~x:(w - 1) ~y:(h - 1)) where w and h are respectively the width and the height of g but runs faster.
Same as iter, but the function is applied with the width-index and height-index of the element as first and second argument, and the element itself as third argument.
map f g returns a grid with the same dimension than g but where each element x has been replaced by the value of f x.
Same as map, but the function is applied with the width-index and height-index of the element as first and second arguement, and the element itself as third argument.
fold f acc g computes Flex_array.fold (Flex_array.fold f) acc g.
val pp :
?pp_sep_row:(Format.formatter -> unit -> unit) ->
?pp_sep_col:(Format.formatter -> unit -> unit) ->
(Format.formatter -> 'a -> unit) ->
Format.formatter ->
'a t ->
unitpp ?pp_sep_row ?pp_sep_col pp_v fmt g prints items of grid g using pp_v to print each item, calling pp_sep_row between rows and pp_sep_col between items (i.e. between each column). pp_sep_row defaults to Format.pp_print_cut and pp_print_col defaults to fun fmt () -> Format.fprintf fmt ";". Does nothing on empty grids.