Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file pres_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339(*
RES - Automatically Resizing Contiguous Memory for OCaml
Copyright (C) 1999-2002 Markus Mottl
email: markus.mottl@gmail.com
WWW: http://www.ocaml.info
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)(** Interface to parameterized resizable arrays *)moduletypeT=sig(** {6 Signatures and types} *)(** Module implementing the reallocation strategy *)moduleStrategy:Strat.Ttypestrategy=Strategy.t(** Type of reallocation strategy *)type'at(** Type of parameterized resizable arrays *)(** {6 Index and length information} *)vallength:'at->int(** [length ra] @return (virtual) length of resizable array [ra]
excluding the reserved space. *)vallix:'at->int(** [lix ra] @return (virtual) last index of resizable array [ra]
excluding the reserved space. *)valreal_length:'at->int(** [real_length ra] @return (real) length of resizable array [ra]
including the reserved space. *)valreal_lix:'at->int(** [real_lix ra] @return (real) last index of resizable array [ra]
including the reserved space. *)(** {6 Getting and setting} *)valget:'at->int->'a(** [get ra n] @return the [n]th element of [ra].
@raise Invalid_argument if index out of bounds. *)valset:'at->int->'a->unit(** [set ra n] sets the [n]th element of [ra].
@raise Invalid_argument if index out of bounds. *)(** {6 Creation of resizable arrays} *)valsempty:strategy->'at(** [sempty s] @return an empty resizable array using strategy [s]. *)valempty:unit->'at(** [empty ()] same as [sempty] but uses default strategy. *)valscreate:strategy->int->'a->'at(** [screate s n el] @return a resizable array of length [n] containing
element [el] only using strategy [s]. *)valcreate:int->'a->'at(** [create n el] same as [screate] but uses default strategy. *)valsmake:strategy->int->'a->'at(** [smake s n el] same as [screate]. *)valmake:int->'a->'at(** [make n el] same as [create]. *)valsinit:strategy->int->(int->'a)->'at(** [sinit s n f] @return an array of length [n] containing
elements that were created by applying function [f] to the index,
using strategy [s]. *)valinit:int->(int->'a)->'at(** [init n f] sames as [sinit] but uses default strategy. *)(** {6 Strategy handling} *)valget_strategy:'at->strategy(** [get_strategy ra] @return the reallocation strategy used by
resizable array [ra]. *)valset_strategy:'at->strategy->unit(** [set_strategy ra s] sets the reallocation strategy of
resizable array [ra] to [s], possibly causing an immediate
reallocation. *)valput_strategy:'at->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. *)valenforce_strategy:'at->unit(** [enforce_strategy ra] forces a reallocation if necessary
(e.g. after a [put_strategy]. *)(** {6 Matrix functions} *)valmake_matrix:int->int->'a->'att(** [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. *)(** {6 Copying, blitting and range extraction} *)valcopy:'at->'at(** [copy ra] @return a copy of resizable array [ra]. The two
arrays share the same strategy! *)valsub:'at->int->int->'at(** [sub ra ofs len] @return a resizable subarray of length [len]
from resizable array [ra] starting at offset [ofs] using the
default strategy.
@raise Invalid_argument if parameters do not denote a correct
subarray. *)valfill:'at->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. *)valblit:'at->int->'at->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]. *)(** {6 Combining resizable arrays} *)valappend:'at->'at->'at(** [append ra1 ra2] @return a new resizable array using the
default strategy and copying [ra1] and [ra2] in this order onto
it. *)valconcat:'atlist->'at(** [concat l] @return a new resizable array using the default
strategy and copying all resizable arrays in [l] in their respective
order onto it. *)(** {6 Adding and removing elements} *)valadd_one:'at->'a->unit(** [add_one ra el] adds element [el] to resizable array [ra],
possibly causing a reallocation. *)valremove_one:'at->unit(** [remove_one ra] removes the last element of resizable array
[ra], possibly causing a reallocation.
@raise Failure if the array is empty. *)valremove_n:'at->int->unit(** [remove_n ra n] removes the last n elements of resizable
array [ra], possibly causing a reallocation.
@raise Invalid_arg if there are not enough elements or [n < 0]. *)valremove_range:'at->int->int->unit(** [remove_range ra ofs len] removes [len] elements from resizable
array [ra] starting at [ofs] and possibly causing a
reallocation.
@raise Invalid_argument if range is invalid. *)valclear:'at->unit(** [clear ra] removes all elements from resizable array [ra],
possibly causing a reallocation. *)(** {6 Swapping} *)valswap:'at->int->int->unit(** [swap ra n m] swaps elements at indices [n] and [m].
@raise Invalid_argument if any index is out of range. *)valswap_in_last:'at->int->unit(** [swap_in_last ra n] swaps the last element with the one at
position [n].
@raise Invalid_argument if index [n] is out of range. *)(** {6 Array conversions} *)valto_array:'at->'aarray(** [to_array ra] converts a resizable array to a standard one. *)valsof_array:strategy->'aarray->'at(** [sof_array s ar] converts a standard array to a resizable one,
using strategy [s]. *)valof_array:'aarray->'at(** [of_array ar] converts a standard array to a resizable one
using the default strategy. *)(** {6 List conversions} *)valto_list:'at->'alist(** [to_list ra] converts resizable array [ra] to a list. *)valsof_list:strategy->'alist->'at(** [sof_list s l] creates a resizable array using strategy [s] and
the elements in list [l]. *)valof_list:'alist->'at(** [of_list l] creates a resizable array using the default
strategy and the elements in list [l]. *)(** {6 Iterators} *)valiter:('a->unit)->'at->unit(** [iter f ra] applies the unit-function [f] to each element in
resizable array [ra]. *)valmap:('a->'b)->'at->'bt(** [map f ra] @return 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]. *)valiteri:(int->'a->unit)->'at->unit(** [iteri f ra] applies the unit-function [f] to each index and
element in resizable array [ra]. *)valmapi:(int->'a->'b)->'at->'bt(** [mapi f ra] @return 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. *)valfold_left:('b->'a->'b)->'b->'at->'b(** [fold_left f a ra] left-folds values in resizable array [ra]
using function [f] and start accumulator [a]. *)valfold_right:('a->'b->'b)->'at->'b->'b(** [fold_right f a ra] right-folds values in resizable array [ra]
using function [f] and start accumulator [a]. *)(** {6 Scanning of resizable arrays} *)valfor_all:('a->bool)->'at->bool(** [for_all p ra] @return [true] if all elements in resizable
array [ra] satisfy the predicate [p], [false] otherwise. *)valexists:('a->bool)->'at->bool(** [exists p ra] @return [true] if at least one element in
resizable array [ra] satisfies the predicate [p], [false]
otherwise. *)valmem:'a->'at->bool(** [mem el ra] @return [true] if element [el] is logically equal
to any element in resizable array [ra], [false] otherwise. *)valmemq:'a->'at->bool(** [memq el ra] @return [true] if element [el] is physically equal
to any element in resizable array [ra], [false] otherwise. *)valpos:'a->'at->intoption(** [pos el ra] @return [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. *)valposq:'a->'at->intoption(** [posq el ra] @return [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. *)(** {6 Searching of resizable arrays} *)valfind:('a->bool)->'at->'a(** [find p ra] @return the first element in resizable array [ra]
that satisfies predicate [p].
@raise Not_found if there is no such element. *)valfind_index:('a->bool)->'at->int->int(** [find_index p ra pos] @return the index of the first element
that satisfies predicate [p] in resizable array [ra], starting
search at index [pos].
@raise Not_found if there is no such element or if [pos] is larger
than the highest index.
@raise Invalid_argument if [pos] is negative. *)valfilter:('a->bool)->'at->'at(** [filter p ra] @return a new resizable array by filtering
out all elements in [ra] that satisfy predicate [p] using the same
strategy as [ra]. *)valfind_all:('a->bool)->'at->'at(** [find_all p ra] is the same as [filter] *)valfilter_in_place:('a->bool)->'at->unit(** [filter_in_place p ra] as [filter], but filters in place. *)valpartition:('a->bool)->'at->'at*'at(** [partition p ra] @return 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]. *)(** {6 {b UNSAFE STUFF - USE WITH CAUTION!}} *)valunsafe_get:'at->int->'avalunsafe_set:'at->int->'a->unitvalunsafe_sub:'at->int->int->'atvalunsafe_fill:'at->int->int->'a->unitvalunsafe_blit:'at->int->'at->int->int->unitvalunsafe_remove_one:'at->unitvalunsafe_remove_n:'at->int->unitvalunsafe_swap:'at->int->int->unitvalunsafe_swap_in_last:'at->int->unitend