package res

  1. Overview
  2. Docs

Module Res.MakeFloatsSource

Functor that creates resizable float arrays from reallocation strategies.

Parameters

module S : sig ... end

Signature

Signatures and types
Sourcemodule Strategy = S

Module implementing the reallocation strategy

Sourcetype strategy = Strategy.t

Type of reallocation strategy

Sourcetype t

Type of resizable arrays

Sourcetype el = float

Type of the elements in the resizable array

Index and length information
Sourceval length : t -> int

length ra

  • returns

    (virtual) length of resizable array ra excluding the reserved space.

Sourceval lix : t -> int

lix ra

  • returns

    (virtual) last index of resizable array ra excluding the reserved space.

Sourceval real_length : t -> int

real_length ra

  • returns

    (real) length of resizable array ra including the reserved space.

Sourceval real_lix : t -> int

real_lix ra

  • returns

    (real) last index of resizable array ra including the reserved space.

Getting and setting
Sourceval get : t -> int -> el

get ra n

  • returns

    the nth element of ra.

Sourceval set : t -> int -> el -> unit

set ra n sets the nth element of ra.

Creation of resizable arrays
Sourceval sempty : strategy -> t

sempty s

  • returns

    an empty resizable array using strategy s.

Sourceval empty : unit -> t

empty () same as sempty but uses default strategy.

Sourceval screate : strategy -> int -> t

screate s n

  • returns

    a resizable array with strategy s containing n arbitrary elements.

Attention: the contents is not specified!

Sourceval create : int -> t

create n same as screate but uses default strategy.

Sourceval smake : strategy -> int -> el -> t

smake s n el

  • returns

    a resizable array of length n containing element el only using strategy s.

Sourceval make : int -> el -> t

make n el same as smake but uses default strategy.

Sourceval sinit : strategy -> int -> (int -> el) -> t

sinit s n f

  • returns

    an array of length n containing elements that were created by applying function f to the index, using strategy s.

Sourceval init : int -> (int -> el) -> t

init n f sames as sinit but uses default strategy.

Strategy handling
Sourceval get_strategy : t -> strategy

get_strategy ra

  • returns

    the reallocation strategy used by resizable array ra.

Sourceval set_strategy : t -> strategy -> unit

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

Sourceval put_strategy : 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.

Sourceval enforce_strategy : t -> unit

enforce_strategy ra forces a reallocation if necessary (e.g. after a put_strategy.

Copying, blitting and range extraction
Sourceval copy : t -> t

copy ra

  • returns

    a copy of resizable array ra. The two arrays share the same strategy!

Sourceval sub : t -> int -> int -> t

sub ra ofs len

  • returns

    a resizable subarray of length len from resizable array ra starting at offset ofs using the default strategy.

Sourceval fill : t -> int -> int -> el -> 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.

Sourceval blit : t -> int -> 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
Sourceval append : t -> t -> t

append ra1 ra2

  • returns

    a new resizable array using the default strategy and copying ra1 and ra2 in this order onto it.

Sourceval concat : t list -> t

concat l

  • returns

    a new resizable array using the default strategy and copying all resizable arrays in l in their respective order onto it.

Adding and removing elements
Sourceval add_one : t -> el -> unit

add_one ra el adds element el to resizable array ra, possibly causing a reallocation.

Sourceval remove_one : t -> unit

remove_one ra removes the last element of resizable array ra, possibly causing a reallocation.

  • raises Failure

    if the array is empty.

Sourceval remove_n : t -> int -> unit

remove_n ra n removes the last n elements of resizable array ra, possibly causing a reallocation.

  • raises Invalid_arg

    if there are not enough elements or n < 0.

Sourceval remove_range : t -> int -> int -> unit

remove_range ra ofs len removes len elements from resizable array ra starting at ofs and possibly causing a reallocation.

Sourceval clear : t -> unit

clear ra removes all elements from resizable array ra, possibly causing a reallocation.

Swapping
Sourceval swap : t -> int -> int -> unit

swap ra n m swaps elements at indices n and m.

Sourceval swap_in_last : t -> int -> unit

swap_in_last ra n swaps the last element with the one at position n.

Array conversions
Sourceval to_array : t -> el array

to_array ra converts a resizable array to a standard one.

Sourceval sof_array : strategy -> el array -> t

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

Sourceval of_array : el array -> t

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

List conversions
Sourceval to_list : t -> el list

to_list ra converts resizable array ra to a list.

Sourceval sof_list : strategy -> el list -> t

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

Sourceval of_list : el list -> t

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

Iterators
Sourceval iter : (el -> unit) -> t -> unit

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

Sourceval map : (el -> el) -> t -> t

map f ra

  • returns

    a resizable array using the strategy of ra and mapping each element in ra to its corresponding position in the new array using function f.

Sourceval iteri : (int -> el -> unit) -> t -> unit

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

Sourceval mapi : (int -> el -> el) -> t -> t

mapi f ra

  • returns

    a resizable array using the strategy of ra and mapping each element in ra to its corresponding position in the new array using function f and the index position.

Sourceval fold_left : ('a -> el -> 'a) -> 'a -> t -> 'a

fold_left f a ra left-folds values in resizable array ra using function f and start accumulator a.

Sourceval fold_right : (el -> 'a -> 'a) -> t -> 'a -> 'a

fold_right f a ra right-folds values in resizable array ra using function f and start accumulator a.

Scanning of resizable arrays
Sourceval for_all : (el -> bool) -> t -> bool

for_all p ra

  • returns

    true if all elements in resizable array ra satisfy the predicate p, false otherwise.

Sourceval exists : (el -> bool) -> t -> bool

exists p ra

  • returns

    true if at least one element in resizable array ra satisfies the predicate p, false otherwise.

Sourceval mem : el -> t -> bool

mem el ra

  • returns

    true if element el is logically equal to any element in resizable array ra, false otherwise.

Sourceval memq : el -> t -> bool

memq el ra

  • returns

    true if element el is physically equal to any element in resizable array ra, false otherwise.

Sourceval pos : el -> t -> int option

pos el ra

  • returns

    Some index if el is logically equal to the element at index in ra, None otherwise. index is the index of the first element that matches.

Sourceval posq : el -> t -> int option

posq el ra

  • returns

    Some index if el is physically equal to the element at index in ra, None otherwise. index is the index of the first element that matches.

Searching of resizable arrays
Sourceval find : (el -> bool) -> t -> el

find p ra

  • returns

    the first element in resizable array ra that satisfies predicate p.

  • raises Not_found

    if there is no such element.

Sourceval find_index : (el -> bool) -> t -> int -> int

find_index p ra pos

  • returns

    the index of the first element that satisfies predicate p in resizable array ra, starting search at index pos.

  • raises Not_found

    if there is no such element or if pos is larger than the highest index.

Sourceval filter : (el -> bool) -> t -> t

filter p ra

  • returns

    a new resizable array by filtering out all elements in ra that satisfy predicate p using the same strategy as ra.

Sourceval find_all : (el -> bool) -> t -> t

find_all p ra is the same as filter

Sourceval filter_in_place : (el -> bool) -> t -> unit

filter_in_place p ra as filter, but filters in place.

Sourceval partition : (el -> bool) -> t -> t * t

partition p ra

  • returns

    a pair of resizable arrays, the left part containing only elements of ra that satisfy predicate p, the right one only those that do not satisfy it. Both returned arrays are created using the strategy of ra.

UNSAFE STUFF - USE WITH CAUTION!
Sourceval unsafe_get : t -> int -> el
Sourceval unsafe_set : t -> int -> el -> unit
Sourceval unsafe_sub : t -> int -> int -> t
Sourceval unsafe_fill : t -> int -> int -> el -> unit
Sourceval unsafe_blit : t -> int -> t -> int -> int -> unit
Sourceval unsafe_remove_one : t -> unit
Sourceval unsafe_remove_n : t -> int -> unit
Sourceval unsafe_swap : t -> int -> int -> unit
Sourceval unsafe_swap_in_last : t -> int -> unit
OCaml

Innovation. Community. Security.