\documentclass[11pt]{article} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} \usepackage{fullpage} \usepackage{url} \usepackage{ocamldoc} \begin{document} \tableofcontents \section{Module {\tt{Strat}} : Interface to strategies} \label{module:Strat}\index{Strat@\verb`Strat`} \ocamldocvspace{0.5cm} \begin{ocamldoccode} {\tt{module type }}{\tt{T}}{\tt{ = }}\end{ocamldoccode} \label{moduletype:Strat.T}\index{T@\verb`T`} \begin{ocamldocsigend} \label{type:Strat.T.t}\begin{ocamldoccode} type t \end{ocamldoccode} \index{t@\verb`t`} \begin{ocamldocdescription} The abstract type of strategies. \end{ocamldocdescription} \label{val:Strat.T.default}\begin{ocamldoccode} val default : t \end{ocamldoccode} \index{default@\verb`default`} \begin{ocamldocdescription} Default strategy of this strategy implementation. \end{ocamldocdescription} \label{val:Strat.T.grow}\begin{ocamldoccode} val grow : t -> int -> int \end{ocamldoccode} \index{grow@\verb`grow`} \begin{ocamldocdescription} {\tt{grow strat new\_len}} {\bf Returns }the new real length of some contiguous datastructure using strategy {\tt{strat}} given new virtual length {\tt{new\_len}}. The user should then use this new real length to resize the datastructure. Be careful, the new (real) length {\bf must} be larger than the new virtual length, otherwise your program will crash! \end{ocamldocdescription} \label{val:Strat.T.shrink}\begin{ocamldoccode} val shrink : t -> real_len:int -> new_len:int -> int \end{ocamldoccode} \index{shrink@\verb`shrink`} \begin{ocamldocdescription} {\tt{shrink strat \~{}real\_len \~{}new\_len}} {\bf Returns }the new real length of a resizable datastructure given its current real length {\tt{real\_len}} and its required new virtual length {\tt{new\_len}} wrt. strategy {\tt{strat}}. The user should then use this new real length to resize the datastructure. If {\tt{-1}} is returned, it is not necessary to resize. Be careful, the new (real) length {\bf must} be larger than the new (virtual) length, otherwise your program may crash! \end{ocamldocdescription} \end{ocamldocsigend} \section{Module {\tt{Pres\_intf}} : Interface to parameterized resizable arrays} \label{module:Pres-underscoreintf}\index{Pres-underscoreintf@\verb`Pres_intf`} \ocamldocvspace{0.5cm} \begin{ocamldoccode} {\tt{module type }}{\tt{T}}{\tt{ = }}\end{ocamldoccode} \label{moduletype:Pres-underscoreintf.T}\index{T@\verb`T`} \begin{ocamldocsigend} Signatures and types \begin{ocamldoccode} {\tt{module }}{\tt{Strategy}}{\tt{ : }}\end{ocamldoccode} \label{module:Pres-underscoreintf.T.Strategy}\index{Strategy@\verb`Strategy`} {\tt{Strat.T}}{\tt{ }}{\tt{}} \begin{ocamldocdescription} Module implementing the reallocation strategy \end{ocamldocdescription} \label{type:Pres-underscoreintf.T.strategy}\begin{ocamldoccode} type strategy = Strategy.t \end{ocamldoccode} \index{strategy@\verb`strategy`} \begin{ocamldocdescription} Type of reallocation strategy \end{ocamldocdescription} \label{type:Pres-underscoreintf.T.t}\begin{ocamldoccode} type 'a t \end{ocamldoccode} \index{t@\verb`t`} \begin{ocamldocdescription} Type of parameterized resizable arrays \end{ocamldocdescription} Index and length information \label{val:Pres-underscoreintf.T.length}\begin{ocamldoccode} val length : 'a t -> int \end{ocamldoccode} \index{length@\verb`length`} \begin{ocamldocdescription} {\tt{length ra}} {\bf Returns }(virtual) length of resizable array {\tt{ra}} excluding the reserved space. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.lix}\begin{ocamldoccode} val lix : 'a t -> int \end{ocamldoccode} \index{lix@\verb`lix`} \begin{ocamldocdescription} {\tt{lix ra}} {\bf Returns }(virtual) last index of resizable array {\tt{ra}} excluding the reserved space. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.real-underscorelength}\begin{ocamldoccode} val real_length : 'a t -> int \end{ocamldoccode} \index{real-underscorelength@\verb`real_length`} \begin{ocamldocdescription} {\tt{real\_length ra}} {\bf Returns }(real) length of resizable array {\tt{ra}} including the reserved space. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.real-underscorelix}\begin{ocamldoccode} val real_lix : 'a t -> int \end{ocamldoccode} \index{real-underscorelix@\verb`real_lix`} \begin{ocamldocdescription} {\tt{real\_lix ra}} {\bf Returns }(real) last index of resizable array {\tt{ra}} including the reserved space. \end{ocamldocdescription} Getting and setting \label{val:Pres-underscoreintf.T.get}\begin{ocamldoccode} val get : 'a t -> int -> 'a \end{ocamldoccode} \index{get@\verb`get`} \begin{ocamldocdescription} {\tt{get ra n}} {\bf Raises} {\tt{Invalid\_argument}} if index out of bounds. {\bf Returns }the {\tt{n}}th element of {\tt{ra}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.set}\begin{ocamldoccode} val set : 'a t -> int -> 'a -> unit \end{ocamldoccode} \index{set@\verb`set`} \begin{ocamldocdescription} {\tt{set ra n}} sets the {\tt{n}}th element of {\tt{ra}}. {\bf Raises} {\tt{Invalid\_argument}} if index out of bounds. \end{ocamldocdescription} Creation of resizable arrays \label{val:Pres-underscoreintf.T.sempty}\begin{ocamldoccode} val sempty : strategy -> 'a t \end{ocamldoccode} \index{sempty@\verb`sempty`} \begin{ocamldocdescription} {\tt{sempty s}} {\bf Returns }an empty resizable array using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.empty}\begin{ocamldoccode} val empty : unit -> 'a t \end{ocamldoccode} \index{empty@\verb`empty`} \begin{ocamldocdescription} {\tt{empty ()}} same as {\tt{sempty}} but uses default strategy. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.screate}\begin{ocamldoccode} val screate : strategy -> int -> 'a -> 'a t \end{ocamldoccode} \index{screate@\verb`screate`} \begin{ocamldocdescription} {\tt{screate s n el}} {\bf Returns }a resizable array of length {\tt{n}} containing element {\tt{el}} only using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.create}\begin{ocamldoccode} val create : int -> 'a -> 'a t \end{ocamldoccode} \index{create@\verb`create`} \begin{ocamldocdescription} {\tt{create n el}} same as {\tt{screate}} but uses default strategy. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.smake}\begin{ocamldoccode} val smake : strategy -> int -> 'a -> 'a t \end{ocamldoccode} \index{smake@\verb`smake`} \begin{ocamldocdescription} {\tt{smake s n el}} same as {\tt{screate}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.make}\begin{ocamldoccode} val make : int -> 'a -> 'a t \end{ocamldoccode} \index{make@\verb`make`} \begin{ocamldocdescription} {\tt{make n el}} same as {\tt{create}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.sinit}\begin{ocamldoccode} val sinit : strategy -> int -> (int -> 'a) -> 'a t \end{ocamldoccode} \index{sinit@\verb`sinit`} \begin{ocamldocdescription} {\tt{sinit s n f}} {\bf Returns }an array of length {\tt{n}} containing elements that were created by applying function {\tt{f}} to the index, using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.init}\begin{ocamldoccode} val init : int -> (int -> 'a) -> 'a t \end{ocamldoccode} \index{init@\verb`init`} \begin{ocamldocdescription} {\tt{init n f}} sames as {\tt{sinit}} but uses default strategy. \end{ocamldocdescription} Strategy handling \label{val:Pres-underscoreintf.T.get-underscorestrategy}\begin{ocamldoccode} val get_strategy : 'a t -> strategy \end{ocamldoccode} \index{get-underscorestrategy@\verb`get_strategy`} \begin{ocamldocdescription} {\tt{get\_strategy ra}} {\bf Returns }the reallocation strategy used by resizable array {\tt{ra}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.set-underscorestrategy}\begin{ocamldoccode} val set_strategy : 'a t -> strategy -> unit \end{ocamldoccode} \index{set-underscorestrategy@\verb`set_strategy`} \begin{ocamldocdescription} {\tt{set\_strategy ra s}} sets the reallocation strategy of resizable array {\tt{ra}} to {\tt{s}}, possibly causing an immediate reallocation. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.put-underscorestrategy}\begin{ocamldoccode} val put_strategy : 'a t -> strategy -> unit \end{ocamldoccode} \index{put-underscorestrategy@\verb`put_strategy`} \begin{ocamldocdescription} {\tt{put\_strategy ra s}} sets the reallocation strategy of resizable array {\tt{ra}} to {\tt{s}}. Reallocation is only done at later changes in size. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.enforce-underscorestrategy}\begin{ocamldoccode} val enforce_strategy : 'a t -> unit \end{ocamldoccode} \index{enforce-underscorestrategy@\verb`enforce_strategy`} \begin{ocamldocdescription} {\tt{enforce\_strategy ra}} forces a reallocation if necessary (e.g. after a {\tt{put\_strategy}}. \end{ocamldocdescription} Matrix functions \label{val:Pres-underscoreintf.T.make-underscorematrix}\begin{ocamldoccode} val make_matrix : int -> int -> 'a -> 'a t t \end{ocamldoccode} \index{make-underscorematrix@\verb`make_matrix`} \begin{ocamldocdescription} {\tt{make\_matrix sx sy el}} creates a (resizable) matrix of dimensions {\tt{sx}} and {\tt{sy}} containing element {\tt{el}} only. Both dimensions are controlled by the default strategy. \end{ocamldocdescription} Copying, blitting and range extraction \label{val:Pres-underscoreintf.T.copy}\begin{ocamldoccode} val copy : 'a t -> 'a t \end{ocamldoccode} \index{copy@\verb`copy`} \begin{ocamldocdescription} {\tt{copy ra}} {\bf Returns }a copy of resizable array {\tt{ra}}. The two arrays share the same strategy! \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.sub}\begin{ocamldoccode} val sub : 'a t -> int -> int -> 'a t \end{ocamldoccode} \index{sub@\verb`sub`} \begin{ocamldocdescription} {\tt{sub ra ofs len}} {\bf Raises} {\tt{Invalid\_argument}} if parameters do not denote a correct subarray. {\bf Returns }a resizable subarray of length {\tt{len}} from resizable array {\tt{ra}} starting at offset {\tt{ofs}} using the default strategy. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.fill}\begin{ocamldoccode} val fill : 'a t -> int -> int -> 'a -> unit \end{ocamldoccode} \index{fill@\verb`fill`} \begin{ocamldocdescription} {\tt{fill ra ofs len el}} fills resizable array {\tt{ra}} from offset {\tt{ofs}} with {\tt{len}} elements {\tt{el}}, possibly adding elements at the end. Raises {\tt{Invalid\_argument}} if offset {\tt{ofs}} is larger than the length of the array. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.blit}\begin{ocamldoccode} val blit : 'a t -> int -> 'a t -> int -> int -> unit \end{ocamldoccode} \index{blit@\verb`blit`} \begin{ocamldocdescription} {\tt{blit ra1 ofs1 ra2 ofs2 len}} blits resizable array {\tt{ra1}} onto {\tt{ra2}} reading {\tt{len}} elements from offset {\tt{ofs1}} and writing them to {\tt{ofs2}}, possibly adding elements at the end of ra2. Raises {\tt{Invalid\_argument}} if {\tt{ofs1}} and {\tt{len}} do not designate a valid subarray of {\tt{ra1}} or if {\tt{ofs2}} is larger than the length of {\tt{ra2}}. \end{ocamldocdescription} Combining resizable arrays \label{val:Pres-underscoreintf.T.append}\begin{ocamldoccode} val append : 'a t -> 'a t -> 'a t \end{ocamldoccode} \index{append@\verb`append`} \begin{ocamldocdescription} {\tt{append ra1 ra2}} {\bf Returns }a new resizable array using the default strategy and copying {\tt{ra1}} and {\tt{ra2}} in this order onto it. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.concat}\begin{ocamldoccode} val concat : 'a t list -> 'a t \end{ocamldoccode} \index{concat@\verb`concat`} \begin{ocamldocdescription} {\tt{concat l}} {\bf Returns }a new resizable array using the default strategy and copying all resizable arrays in {\tt{l}} in their respective order onto it. \end{ocamldocdescription} Adding and removing elements \label{val:Pres-underscoreintf.T.add-underscoreone}\begin{ocamldoccode} val add_one : 'a t -> 'a -> unit \end{ocamldoccode} \index{add-underscoreone@\verb`add_one`} \begin{ocamldocdescription} {\tt{add\_one ra el}} adds element {\tt{el}} to resizable array {\tt{ra}}, possibly causing a reallocation. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.remove-underscoreone}\begin{ocamldoccode} val remove_one : 'a t -> unit \end{ocamldoccode} \index{remove-underscoreone@\verb`remove_one`} \begin{ocamldocdescription} {\tt{remove\_one ra}} removes the last element of resizable array {\tt{ra}}, possibly causing a reallocation. {\bf Raises} {\tt{Failure}} if the array is empty. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.remove-underscoren}\begin{ocamldoccode} val remove_n : 'a t -> int -> unit \end{ocamldoccode} \index{remove-underscoren@\verb`remove_n`} \begin{ocamldocdescription} {\tt{remove\_n ra n}} removes the last n elements of resizable array {\tt{ra}}, possibly causing a reallocation. {\bf Raises} {\tt{Invalid\_arg}} if there are not enough elements or {\tt{n < 0}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.remove-underscorerange}\begin{ocamldoccode} val remove_range : 'a t -> int -> int -> unit \end{ocamldoccode} \index{remove-underscorerange@\verb`remove_range`} \begin{ocamldocdescription} {\tt{remove\_range ra ofs len}} removes {\tt{len}} elements from resizable array {\tt{ra}} starting at {\tt{ofs}} and possibly causing a reallocation. {\bf Raises} {\tt{Invalid\_argument}} if range is invalid. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.clear}\begin{ocamldoccode} val clear : 'a t -> unit \end{ocamldoccode} \index{clear@\verb`clear`} \begin{ocamldocdescription} {\tt{clear ra}} removes all elements from resizable array {\tt{ra}}, possibly causing a reallocation. \end{ocamldocdescription} Swapping \label{val:Pres-underscoreintf.T.swap}\begin{ocamldoccode} val swap : 'a t -> int -> int -> unit \end{ocamldoccode} \index{swap@\verb`swap`} \begin{ocamldocdescription} {\tt{swap ra n m}} swaps elements at indices {\tt{n}} and {\tt{m}}. {\bf Raises} {\tt{Invalid\_argument}} if any index is out of range. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.swap-underscorein-underscorelast}\begin{ocamldoccode} val swap_in_last : 'a t -> int -> unit \end{ocamldoccode} \index{swap-underscorein-underscorelast@\verb`swap_in_last`} \begin{ocamldocdescription} {\tt{swap\_in\_last ra n}} swaps the last element with the one at position {\tt{n}}. {\bf Raises} {\tt{Invalid\_argument}} if index {\tt{n}} is out of range. \end{ocamldocdescription} Array conversions \label{val:Pres-underscoreintf.T.to-underscorearray}\begin{ocamldoccode} val to_array : 'a t -> 'a array \end{ocamldoccode} \index{to-underscorearray@\verb`to_array`} \begin{ocamldocdescription} {\tt{to\_array ra}} converts a resizable array to a standard one. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.sof-underscorearray}\begin{ocamldoccode} val sof_array : strategy -> 'a array -> 'a t \end{ocamldoccode} \index{sof-underscorearray@\verb`sof_array`} \begin{ocamldocdescription} {\tt{sof\_array s ar}} converts a standard array to a resizable one, using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.of-underscorearray}\begin{ocamldoccode} val of_array : 'a array -> 'a t \end{ocamldoccode} \index{of-underscorearray@\verb`of_array`} \begin{ocamldocdescription} {\tt{of\_array ar}} converts a standard array to a resizable one using the default strategy. \end{ocamldocdescription} List conversions \label{val:Pres-underscoreintf.T.to-underscorelist}\begin{ocamldoccode} val to_list : 'a t -> 'a list \end{ocamldoccode} \index{to-underscorelist@\verb`to_list`} \begin{ocamldocdescription} {\tt{to\_list ra}} converts resizable array {\tt{ra}} to a list. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.sof-underscorelist}\begin{ocamldoccode} val sof_list : strategy -> 'a list -> 'a t \end{ocamldoccode} \index{sof-underscorelist@\verb`sof_list`} \begin{ocamldocdescription} {\tt{sof\_list s l}} creates a resizable array using strategy {\tt{s}} and the elements in list {\tt{l}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.of-underscorelist}\begin{ocamldoccode} val of_list : 'a list -> 'a t \end{ocamldoccode} \index{of-underscorelist@\verb`of_list`} \begin{ocamldocdescription} {\tt{of\_list l}} creates a resizable array using the default strategy and the elements in list {\tt{l}}. \end{ocamldocdescription} Iterators \label{val:Pres-underscoreintf.T.iter}\begin{ocamldoccode} val iter : ('a -> unit) -> 'a t -> unit \end{ocamldoccode} \index{iter@\verb`iter`} \begin{ocamldocdescription} {\tt{iter f ra}} applies the unit-function {\tt{f}} to each element in resizable array {\tt{ra}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.map}\begin{ocamldoccode} val map : ('a -> 'b) -> 'a t -> 'b t \end{ocamldoccode} \index{map@\verb`map`} \begin{ocamldocdescription} {\tt{map f ra}} {\bf Returns }a resizable array using the strategy of {\tt{ra}} and mapping each element in {\tt{ra}} to its corresponding position in the new array using function {\tt{f}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.iteri}\begin{ocamldoccode} val iteri : (int -> 'a -> unit) -> 'a t -> unit \end{ocamldoccode} \index{iteri@\verb`iteri`} \begin{ocamldocdescription} {\tt{iteri f ra}} applies the unit-function {\tt{f}} to each index and element in resizable array {\tt{ra}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.mapi}\begin{ocamldoccode} val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t \end{ocamldoccode} \index{mapi@\verb`mapi`} \begin{ocamldocdescription} {\tt{mapi f ra}} {\bf Returns }a resizable array using the strategy of {\tt{ra}} and mapping each element in {\tt{ra}} to its corresponding position in the new array using function {\tt{f}} and the index position. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.fold-underscoreleft}\begin{ocamldoccode} val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a \end{ocamldoccode} \index{fold-underscoreleft@\verb`fold_left`} \begin{ocamldocdescription} {\tt{fold\_left f a ra}} left-folds values in resizable array {\tt{ra}} using function {\tt{f}} and start accumulator {\tt{a}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.fold-underscoreright}\begin{ocamldoccode} val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b \end{ocamldoccode} \index{fold-underscoreright@\verb`fold_right`} \begin{ocamldocdescription} {\tt{fold\_right f a ra}} right-folds values in resizable array {\tt{ra}} using function {\tt{f}} and start accumulator {\tt{a}}. \end{ocamldocdescription} Scanning of resizable arrays \label{val:Pres-underscoreintf.T.for-underscoreall}\begin{ocamldoccode} val for_all : ('a -> bool) -> 'a t -> bool \end{ocamldoccode} \index{for-underscoreall@\verb`for_all`} \begin{ocamldocdescription} {\tt{for\_all p ra}} {\bf Returns }{\tt{true}} if all elements in resizable array {\tt{ra}} satisfy the predicate {\tt{p}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.exists}\begin{ocamldoccode} val exists : ('a -> bool) -> 'a t -> bool \end{ocamldoccode} \index{exists@\verb`exists`} \begin{ocamldocdescription} {\tt{exists p ra}} {\bf Returns }{\tt{true}} if at least one element in resizable array {\tt{ra}} satisfies the predicate {\tt{p}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.mem}\begin{ocamldoccode} val mem : 'a -> 'a t -> bool \end{ocamldoccode} \index{mem@\verb`mem`} \begin{ocamldocdescription} {\tt{mem el ra}} {\bf Returns }{\tt{true}} if element {\tt{el}} is logically equal to any element in resizable array {\tt{ra}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.memq}\begin{ocamldoccode} val memq : 'a -> 'a t -> bool \end{ocamldoccode} \index{memq@\verb`memq`} \begin{ocamldocdescription} {\tt{memq el ra}} {\bf Returns }{\tt{true}} if element {\tt{el}} is physically equal to any element in resizable array {\tt{ra}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.pos}\begin{ocamldoccode} val pos : 'a -> 'a t -> int option \end{ocamldoccode} \index{pos@\verb`pos`} \begin{ocamldocdescription} {\tt{pos el ra}} {\bf Returns }{\tt{Some index}} if {\tt{el}} is logically equal to the element at {\tt{index}} in {\tt{ra}}, {\tt{None}} otherwise. {\tt{index}} is the index of the first element that matches. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.posq}\begin{ocamldoccode} val posq : 'a -> 'a t -> int option \end{ocamldoccode} \index{posq@\verb`posq`} \begin{ocamldocdescription} {\tt{posq el ra}} {\bf Returns }{\tt{Some index}} if {\tt{el}} is physically equal to the element at {\tt{index}} in {\tt{ra}}, {\tt{None}} otherwise. {\tt{index}} is the index of the first element that matches. \end{ocamldocdescription} Searching of resizable arrays \label{val:Pres-underscoreintf.T.find}\begin{ocamldoccode} val find : ('a -> bool) -> 'a t -> 'a \end{ocamldoccode} \index{find@\verb`find`} \begin{ocamldocdescription} {\tt{find p ra}} {\bf Raises} {\tt{Not\_found}} if there is no such element. {\bf Returns }the first element in resizable array {\tt{ra}} that satisfies predicate {\tt{p}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.find-underscoreindex}\begin{ocamldoccode} val find_index : ('a -> bool) -> 'a t -> int -> int \end{ocamldoccode} \index{find-underscoreindex@\verb`find_index`} \begin{ocamldocdescription} {\tt{find\_index p ra pos}} {\bf Raises} \begin{itemize} \item {\tt{Not\_found}} if there is no such element or if {\tt{pos}} is larger than the highest index. \item {\tt{Invalid\_argument}} if {\tt{pos}} is negative. \end{itemize} {\bf Returns }the index of the first element that satisfies predicate {\tt{p}} in resizable array {\tt{ra}}, starting search at index {\tt{pos}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.filter}\begin{ocamldoccode} val filter : ('a -> bool) -> 'a t -> 'a t \end{ocamldoccode} \index{filter@\verb`filter`} \begin{ocamldocdescription} {\tt{filter p ra}} {\bf Returns }a new resizable array by filtering out all elements in {\tt{ra}} that satisfy predicate {\tt{p}} using the same strategy as {\tt{ra}}. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.find-underscoreall}\begin{ocamldoccode} val find_all : ('a -> bool) -> 'a t -> 'a t \end{ocamldoccode} \index{find-underscoreall@\verb`find_all`} \begin{ocamldocdescription} {\tt{find\_all p ra}} is the same as {\tt{filter}} \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.filter-underscorein-underscoreplace}\begin{ocamldoccode} val filter_in_place : ('a -> bool) -> 'a t -> unit \end{ocamldoccode} \index{filter-underscorein-underscoreplace@\verb`filter_in_place`} \begin{ocamldocdescription} {\tt{filter\_in\_place p ra}} as {\tt{filter}}, but filters in place. \end{ocamldocdescription} \label{val:Pres-underscoreintf.T.partition}\begin{ocamldoccode} val partition : ('a -> bool) -> 'a t -> 'a t * 'a t \end{ocamldoccode} \index{partition@\verb`partition`} \begin{ocamldocdescription} {\tt{partition p ra}} {\bf Returns }a pair of resizable arrays, the left part containing only elements of {\tt{ra}} that satisfy predicate {\tt{p}}, the right one only those that do not satisfy it. Both returned arrays are created using the strategy of {\tt{ra}}. \end{ocamldocdescription} {\bf UNSAFE STUFF - USE WITH CAUTION!} \label{val:Pres-underscoreintf.T.unsafe-underscoreget}\begin{ocamldoccode} val unsafe_get : 'a t -> int -> 'a \end{ocamldoccode} \index{unsafe-underscoreget@\verb`unsafe_get`} \label{val:Pres-underscoreintf.T.unsafe-underscoreset}\begin{ocamldoccode} val unsafe_set : 'a t -> int -> 'a -> unit \end{ocamldoccode} \index{unsafe-underscoreset@\verb`unsafe_set`} \label{val:Pres-underscoreintf.T.unsafe-underscoresub}\begin{ocamldoccode} val unsafe_sub : 'a t -> int -> int -> 'a t \end{ocamldoccode} \index{unsafe-underscoresub@\verb`unsafe_sub`} \label{val:Pres-underscoreintf.T.unsafe-underscorefill}\begin{ocamldoccode} val unsafe_fill : 'a t -> int -> int -> 'a -> unit \end{ocamldoccode} \index{unsafe-underscorefill@\verb`unsafe_fill`} \label{val:Pres-underscoreintf.T.unsafe-underscoreblit}\begin{ocamldoccode} val unsafe_blit : 'a t -> int -> 'a t -> int -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreblit@\verb`unsafe_blit`} \label{val:Pres-underscoreintf.T.unsafe-underscoreremove-underscoreone}\begin{ocamldoccode} val unsafe_remove_one : 'a t -> unit \end{ocamldoccode} \index{unsafe-underscoreremove-underscoreone@\verb`unsafe_remove_one`} \label{val:Pres-underscoreintf.T.unsafe-underscoreremove-underscoren}\begin{ocamldoccode} val unsafe_remove_n : 'a t -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreremove-underscoren@\verb`unsafe_remove_n`} \label{val:Pres-underscoreintf.T.unsafe-underscoreswap}\begin{ocamldoccode} val unsafe_swap : 'a t -> int -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreswap@\verb`unsafe_swap`} \label{val:Pres-underscoreintf.T.unsafe-underscoreswap-underscorein-underscorelast}\begin{ocamldoccode} val unsafe_swap_in_last : 'a t -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreswap-underscorein-underscorelast@\verb`unsafe_swap_in_last`} \end{ocamldocsigend} \section{Module {\tt{Nopres\_intf}} : Interfaces to unparameterized resizable arrays and buffers} \label{module:Nopres-underscoreintf}\index{Nopres-underscoreintf@\verb`Nopres_intf`} \ocamldocvspace{0.5cm} \begin{ocamldoccode} {\tt{module type }}{\tt{T}}{\tt{ = }}\end{ocamldoccode} \label{moduletype:Nopres-underscoreintf.T}\index{T@\verb`T`} \begin{ocamldocsigend} Signatures and types \begin{ocamldoccode} {\tt{module }}{\tt{Strategy}}{\tt{ : }}\end{ocamldoccode} \label{module:Nopres-underscoreintf.T.Strategy}\index{Strategy@\verb`Strategy`} {\tt{Strat.T}}{\tt{ }}{\tt{}} \begin{ocamldocdescription} Module implementing the reallocation strategy \end{ocamldocdescription} \label{type:Nopres-underscoreintf.T.strategy}\begin{ocamldoccode} type strategy = Strategy.t \end{ocamldoccode} \index{strategy@\verb`strategy`} \begin{ocamldocdescription} Type of reallocation strategy \end{ocamldocdescription} \label{type:Nopres-underscoreintf.T.t}\begin{ocamldoccode} type t \end{ocamldoccode} \index{t@\verb`t`} \begin{ocamldocdescription} Type of resizable arrays \end{ocamldocdescription} \label{type:Nopres-underscoreintf.T.el}\begin{ocamldoccode} type el \end{ocamldoccode} \index{el@\verb`el`} \begin{ocamldocdescription} Type of the elements in the resizable array \end{ocamldocdescription} Index and length information \label{val:Nopres-underscoreintf.T.length}\begin{ocamldoccode} val length : t -> int \end{ocamldoccode} \index{length@\verb`length`} \begin{ocamldocdescription} {\tt{length ra}} {\bf Returns }(virtual) length of resizable array {\tt{ra}} excluding the reserved space. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.lix}\begin{ocamldoccode} val lix : t -> int \end{ocamldoccode} \index{lix@\verb`lix`} \begin{ocamldocdescription} {\tt{lix ra}} {\bf Returns }(virtual) last index of resizable array {\tt{ra}} excluding the reserved space. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.real-underscorelength}\begin{ocamldoccode} val real_length : t -> int \end{ocamldoccode} \index{real-underscorelength@\verb`real_length`} \begin{ocamldocdescription} {\tt{real\_length ra}} {\bf Returns }(real) length of resizable array {\tt{ra}} including the reserved space. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.real-underscorelix}\begin{ocamldoccode} val real_lix : t -> int \end{ocamldoccode} \index{real-underscorelix@\verb`real_lix`} \begin{ocamldocdescription} {\tt{real\_lix ra}} {\bf Returns }(real) last index of resizable array {\tt{ra}} including the reserved space. \end{ocamldocdescription} Getting and setting \label{val:Nopres-underscoreintf.T.get}\begin{ocamldoccode} val get : t -> int -> el \end{ocamldoccode} \index{get@\verb`get`} \begin{ocamldocdescription} {\tt{get ra n}} {\bf Raises} {\tt{Invalid\_argument}} if index out of bounds. {\bf Returns }the {\tt{n}}th element of {\tt{ra}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.set}\begin{ocamldoccode} val set : t -> int -> el -> unit \end{ocamldoccode} \index{set@\verb`set`} \begin{ocamldocdescription} {\tt{set ra n}} sets the {\tt{n}}th element of {\tt{ra}}. {\bf Raises} {\tt{Invalid\_argument}} if index out of bounds. \end{ocamldocdescription} Creation of resizable arrays \label{val:Nopres-underscoreintf.T.sempty}\begin{ocamldoccode} val sempty : strategy -> t \end{ocamldoccode} \index{sempty@\verb`sempty`} \begin{ocamldocdescription} {\tt{sempty s}} {\bf Returns }an empty resizable array using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.empty}\begin{ocamldoccode} val empty : unit -> t \end{ocamldoccode} \index{empty@\verb`empty`} \begin{ocamldocdescription} {\tt{empty ()}} same as {\tt{sempty}} but uses default strategy. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.screate}\begin{ocamldoccode} val screate : strategy -> int -> t \end{ocamldoccode} \index{screate@\verb`screate`} \begin{ocamldocdescription} {\tt{screate s n}} {\bf Returns }a resizable array with strategy {\tt{s}} containing {\tt{n}} arbitrary elements. {\em Attention: the contents is {\bf not} specified!} \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.create}\begin{ocamldoccode} val create : int -> t \end{ocamldoccode} \index{create@\verb`create`} \begin{ocamldocdescription} {\tt{create n}} same as {\tt{screate}} but uses default strategy. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.smake}\begin{ocamldoccode} val smake : strategy -> int -> el -> t \end{ocamldoccode} \index{smake@\verb`smake`} \begin{ocamldocdescription} {\tt{smake s n el}} {\bf Returns }a resizable array of length {\tt{n}} containing element {\tt{el}} only using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.make}\begin{ocamldoccode} val make : int -> el -> t \end{ocamldoccode} \index{make@\verb`make`} \begin{ocamldocdescription} {\tt{make n el}} same as {\tt{smake}} but uses default strategy. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.sinit}\begin{ocamldoccode} val sinit : strategy -> int -> (int -> el) -> t \end{ocamldoccode} \index{sinit@\verb`sinit`} \begin{ocamldocdescription} {\tt{sinit s n f}} {\bf Returns }an array of length {\tt{n}} containing elements that were created by applying function {\tt{f}} to the index, using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.init}\begin{ocamldoccode} val init : int -> (int -> el) -> t \end{ocamldoccode} \index{init@\verb`init`} \begin{ocamldocdescription} {\tt{init n f}} sames as {\tt{sinit}} but uses default strategy. \end{ocamldocdescription} Strategy handling \label{val:Nopres-underscoreintf.T.get-underscorestrategy}\begin{ocamldoccode} val get_strategy : t -> strategy \end{ocamldoccode} \index{get-underscorestrategy@\verb`get_strategy`} \begin{ocamldocdescription} {\tt{get\_strategy ra}} {\bf Returns }the reallocation strategy used by resizable array {\tt{ra}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.set-underscorestrategy}\begin{ocamldoccode} val set_strategy : t -> strategy -> unit \end{ocamldoccode} \index{set-underscorestrategy@\verb`set_strategy`} \begin{ocamldocdescription} {\tt{set\_strategy ra s}} sets the reallocation strategy of resizable array {\tt{ra}} to {\tt{s}}, possibly causing an immediate reallocation. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.put-underscorestrategy}\begin{ocamldoccode} val put_strategy : t -> strategy -> unit \end{ocamldoccode} \index{put-underscorestrategy@\verb`put_strategy`} \begin{ocamldocdescription} {\tt{put\_strategy ra s}} sets the reallocation strategy of resizable array {\tt{ra}} to {\tt{s}}. Reallocation is only done at later changes in size. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.enforce-underscorestrategy}\begin{ocamldoccode} val enforce_strategy : t -> unit \end{ocamldoccode} \index{enforce-underscorestrategy@\verb`enforce_strategy`} \begin{ocamldocdescription} {\tt{enforce\_strategy ra}} forces a reallocation if necessary (e.g. after a {\tt{put\_strategy}}. \end{ocamldocdescription} Copying, blitting and range extraction \label{val:Nopres-underscoreintf.T.copy}\begin{ocamldoccode} val copy : t -> t \end{ocamldoccode} \index{copy@\verb`copy`} \begin{ocamldocdescription} {\tt{copy ra}} {\bf Returns }a copy of resizable array {\tt{ra}}. The two arrays share the same strategy! \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.sub}\begin{ocamldoccode} val sub : t -> int -> int -> t \end{ocamldoccode} \index{sub@\verb`sub`} \begin{ocamldocdescription} {\tt{sub ra ofs len}} {\bf Raises} {\tt{Invalid\_argument}} if parameters do not denote a correct subarray. {\bf Returns }a resizable subarray of length {\tt{len}} from resizable array {\tt{ra}} starting at offset {\tt{ofs}} using the default strategy. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.fill}\begin{ocamldoccode} val fill : t -> int -> int -> el -> unit \end{ocamldoccode} \index{fill@\verb`fill`} \begin{ocamldocdescription} {\tt{fill ra ofs len el}} fills resizable array {\tt{ra}} from offset {\tt{ofs}} with {\tt{len}} elements {\tt{el}}, possibly adding elements at the end. Raises {\tt{Invalid\_argument}} if offset {\tt{ofs}} is larger than the length of the array. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.blit}\begin{ocamldoccode} val blit : t -> int -> t -> int -> int -> unit \end{ocamldoccode} \index{blit@\verb`blit`} \begin{ocamldocdescription} {\tt{blit ra1 ofs1 ra2 ofs2 len}} blits resizable array {\tt{ra1}} onto {\tt{ra2}} reading {\tt{len}} elements from offset {\tt{ofs1}} and writing them to {\tt{ofs2}}, possibly adding elements at the end of ra2. Raises {\tt{Invalid\_argument}} if {\tt{ofs1}} and {\tt{len}} do not designate a valid subarray of {\tt{ra1}} or if {\tt{ofs2}} is larger than the length of {\tt{ra2}}. \end{ocamldocdescription} Combining resizable arrays \label{val:Nopres-underscoreintf.T.append}\begin{ocamldoccode} val append : t -> t -> t \end{ocamldoccode} \index{append@\verb`append`} \begin{ocamldocdescription} {\tt{append ra1 ra2}} {\bf Returns }a new resizable array using the default strategy and copying {\tt{ra1}} and {\tt{ra2}} in this order onto it. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.concat}\begin{ocamldoccode} val concat : t list -> t \end{ocamldoccode} \index{concat@\verb`concat`} \begin{ocamldocdescription} {\tt{concat l}} {\bf Returns }a new resizable array using the default strategy and copying all resizable arrays in {\tt{l}} in their respective order onto it. \end{ocamldocdescription} Adding and removing elements \label{val:Nopres-underscoreintf.T.add-underscoreone}\begin{ocamldoccode} val add_one : t -> el -> unit \end{ocamldoccode} \index{add-underscoreone@\verb`add_one`} \begin{ocamldocdescription} {\tt{add\_one ra el}} adds element {\tt{el}} to resizable array {\tt{ra}}, possibly causing a reallocation. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.remove-underscoreone}\begin{ocamldoccode} val remove_one : t -> unit \end{ocamldoccode} \index{remove-underscoreone@\verb`remove_one`} \begin{ocamldocdescription} {\tt{remove\_one ra}} removes the last element of resizable array {\tt{ra}}, possibly causing a reallocation. {\bf Raises} {\tt{Failure}} if the array is empty. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.remove-underscoren}\begin{ocamldoccode} val remove_n : t -> int -> unit \end{ocamldoccode} \index{remove-underscoren@\verb`remove_n`} \begin{ocamldocdescription} {\tt{remove\_n ra n}} removes the last n elements of resizable array {\tt{ra}}, possibly causing a reallocation. {\bf Raises} {\tt{Invalid\_arg}} if there are not enough elements or {\tt{n < 0}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.remove-underscorerange}\begin{ocamldoccode} val remove_range : t -> int -> int -> unit \end{ocamldoccode} \index{remove-underscorerange@\verb`remove_range`} \begin{ocamldocdescription} {\tt{remove\_range ra ofs len}} removes {\tt{len}} elements from resizable array {\tt{ra}} starting at {\tt{ofs}} and possibly causing a reallocation. {\bf Raises} {\tt{Invalid\_argument}} if range is invalid. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.clear}\begin{ocamldoccode} val clear : t -> unit \end{ocamldoccode} \index{clear@\verb`clear`} \begin{ocamldocdescription} {\tt{clear ra}} removes all elements from resizable array {\tt{ra}}, possibly causing a reallocation. \end{ocamldocdescription} Swapping \label{val:Nopres-underscoreintf.T.swap}\begin{ocamldoccode} val swap : t -> int -> int -> unit \end{ocamldoccode} \index{swap@\verb`swap`} \begin{ocamldocdescription} {\tt{swap ra n m}} swaps elements at indices {\tt{n}} and {\tt{m}}. {\bf Raises} {\tt{Invalid\_argument}} if any index is out of range. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.swap-underscorein-underscorelast}\begin{ocamldoccode} val swap_in_last : t -> int -> unit \end{ocamldoccode} \index{swap-underscorein-underscorelast@\verb`swap_in_last`} \begin{ocamldocdescription} {\tt{swap\_in\_last ra n}} swaps the last element with the one at position {\tt{n}}. {\bf Raises} {\tt{Invalid\_argument}} if index {\tt{n}} is out of range. \end{ocamldocdescription} Array conversions \label{val:Nopres-underscoreintf.T.to-underscorearray}\begin{ocamldoccode} val to_array : t -> el array \end{ocamldoccode} \index{to-underscorearray@\verb`to_array`} \begin{ocamldocdescription} {\tt{to\_array ra}} converts a resizable array to a standard one. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.sof-underscorearray}\begin{ocamldoccode} val sof_array : strategy -> el array -> t \end{ocamldoccode} \index{sof-underscorearray@\verb`sof_array`} \begin{ocamldocdescription} {\tt{sof\_array s ar}} converts a standard array to a resizable one, using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.of-underscorearray}\begin{ocamldoccode} val of_array : el array -> t \end{ocamldoccode} \index{of-underscorearray@\verb`of_array`} \begin{ocamldocdescription} {\tt{of\_array ar}} converts a standard array to a resizable one using the default strategy. \end{ocamldocdescription} List conversions \label{val:Nopres-underscoreintf.T.to-underscorelist}\begin{ocamldoccode} val to_list : t -> el list \end{ocamldoccode} \index{to-underscorelist@\verb`to_list`} \begin{ocamldocdescription} {\tt{to\_list ra}} converts resizable array {\tt{ra}} to a list. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.sof-underscorelist}\begin{ocamldoccode} val sof_list : strategy -> el list -> t \end{ocamldoccode} \index{sof-underscorelist@\verb`sof_list`} \begin{ocamldocdescription} {\tt{sof\_list s l}} creates a resizable array using strategy {\tt{s}} and the elements in list {\tt{l}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.of-underscorelist}\begin{ocamldoccode} val of_list : el list -> t \end{ocamldoccode} \index{of-underscorelist@\verb`of_list`} \begin{ocamldocdescription} {\tt{of\_list l}} creates a resizable array using the default strategy and the elements in list {\tt{l}}. \end{ocamldocdescription} Iterators \label{val:Nopres-underscoreintf.T.iter}\begin{ocamldoccode} val iter : (el -> unit) -> t -> unit \end{ocamldoccode} \index{iter@\verb`iter`} \begin{ocamldocdescription} {\tt{iter f ra}} applies the unit-function {\tt{f}} to each element in resizable array {\tt{ra}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.map}\begin{ocamldoccode} val map : (el -> el) -> t -> t \end{ocamldoccode} \index{map@\verb`map`} \begin{ocamldocdescription} {\tt{map f ra}} {\bf Returns }a resizable array using the strategy of {\tt{ra}} and mapping each element in {\tt{ra}} to its corresponding position in the new array using function {\tt{f}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.iteri}\begin{ocamldoccode} val iteri : (int -> el -> unit) -> t -> unit \end{ocamldoccode} \index{iteri@\verb`iteri`} \begin{ocamldocdescription} {\tt{iteri f ra}} applies the unit-function {\tt{f}} to each index and element in resizable array {\tt{ra}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.mapi}\begin{ocamldoccode} val mapi : (int -> el -> el) -> t -> t \end{ocamldoccode} \index{mapi@\verb`mapi`} \begin{ocamldocdescription} {\tt{mapi f ra}} {\bf Returns }a resizable array using the strategy of {\tt{ra}} and mapping each element in {\tt{ra}} to its corresponding position in the new array using function {\tt{f}} and the index position. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.fold-underscoreleft}\begin{ocamldoccode} val fold_left : ('a -> el -> 'a) -> 'a -> t -> 'a \end{ocamldoccode} \index{fold-underscoreleft@\verb`fold_left`} \begin{ocamldocdescription} {\tt{fold\_left f a ra}} left-folds values in resizable array {\tt{ra}} using function {\tt{f}} and start accumulator {\tt{a}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.fold-underscoreright}\begin{ocamldoccode} val fold_right : (el -> 'a -> 'a) -> t -> 'a -> 'a \end{ocamldoccode} \index{fold-underscoreright@\verb`fold_right`} \begin{ocamldocdescription} {\tt{fold\_right f a ra}} right-folds values in resizable array {\tt{ra}} using function {\tt{f}} and start accumulator {\tt{a}}. \end{ocamldocdescription} Scanning of resizable arrays \label{val:Nopres-underscoreintf.T.for-underscoreall}\begin{ocamldoccode} val for_all : (el -> bool) -> t -> bool \end{ocamldoccode} \index{for-underscoreall@\verb`for_all`} \begin{ocamldocdescription} {\tt{for\_all p ra}} {\bf Returns }{\tt{true}} if all elements in resizable array {\tt{ra}} satisfy the predicate {\tt{p}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.exists}\begin{ocamldoccode} val exists : (el -> bool) -> t -> bool \end{ocamldoccode} \index{exists@\verb`exists`} \begin{ocamldocdescription} {\tt{exists p ra}} {\bf Returns }{\tt{true}} if at least one element in resizable array {\tt{ra}} satisfies the predicate {\tt{p}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.mem}\begin{ocamldoccode} val mem : el -> t -> bool \end{ocamldoccode} \index{mem@\verb`mem`} \begin{ocamldocdescription} {\tt{mem el ra}} {\bf Returns }{\tt{true}} if element {\tt{el}} is logically equal to any element in resizable array {\tt{ra}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.memq}\begin{ocamldoccode} val memq : el -> t -> bool \end{ocamldoccode} \index{memq@\verb`memq`} \begin{ocamldocdescription} {\tt{memq el ra}} {\bf Returns }{\tt{true}} if element {\tt{el}} is physically equal to any element in resizable array {\tt{ra}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.pos}\begin{ocamldoccode} val pos : el -> t -> int option \end{ocamldoccode} \index{pos@\verb`pos`} \begin{ocamldocdescription} {\tt{pos el ra}} {\bf Returns }{\tt{Some index}} if {\tt{el}} is logically equal to the element at {\tt{index}} in {\tt{ra}}, {\tt{None}} otherwise. {\tt{index}} is the index of the first element that matches. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.posq}\begin{ocamldoccode} val posq : el -> t -> int option \end{ocamldoccode} \index{posq@\verb`posq`} \begin{ocamldocdescription} {\tt{posq el ra}} {\bf Returns }{\tt{Some index}} if {\tt{el}} is physically equal to the element at {\tt{index}} in {\tt{ra}}, {\tt{None}} otherwise. {\tt{index}} is the index of the first element that matches. \end{ocamldocdescription} Searching of resizable arrays \label{val:Nopres-underscoreintf.T.find}\begin{ocamldoccode} val find : (el -> bool) -> t -> el \end{ocamldoccode} \index{find@\verb`find`} \begin{ocamldocdescription} {\tt{find p ra}} {\bf Raises} {\tt{Not\_found}} if there is no such element. {\bf Returns }the first element in resizable array {\tt{ra}} that satisfies predicate {\tt{p}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.find-underscoreindex}\begin{ocamldoccode} val find_index : (el -> bool) -> t -> int -> int \end{ocamldoccode} \index{find-underscoreindex@\verb`find_index`} \begin{ocamldocdescription} {\tt{find\_index p ra pos}} {\bf Raises} \begin{itemize} \item {\tt{Not\_found}} if there is no such element or if {\tt{pos}} is larger than the highest index. \item {\tt{Invalid\_argument}} if {\tt{pos}} is negative. \end{itemize} {\bf Returns }the index of the first element that satisfies predicate {\tt{p}} in resizable array {\tt{ra}}, starting search at index {\tt{pos}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.filter}\begin{ocamldoccode} val filter : (el -> bool) -> t -> t \end{ocamldoccode} \index{filter@\verb`filter`} \begin{ocamldocdescription} {\tt{filter p ra}} {\bf Returns }a new resizable array by filtering out all elements in {\tt{ra}} that satisfy predicate {\tt{p}} using the same strategy as {\tt{ra}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.find-underscoreall}\begin{ocamldoccode} val find_all : (el -> bool) -> t -> t \end{ocamldoccode} \index{find-underscoreall@\verb`find_all`} \begin{ocamldocdescription} {\tt{find\_all p ra}} is the same as {\tt{filter}} \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.filter-underscorein-underscoreplace}\begin{ocamldoccode} val filter_in_place : (el -> bool) -> t -> unit \end{ocamldoccode} \index{filter-underscorein-underscoreplace@\verb`filter_in_place`} \begin{ocamldocdescription} {\tt{filter\_in\_place p ra}} as {\tt{filter}}, but filters in place. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.T.partition}\begin{ocamldoccode} val partition : (el -> bool) -> t -> t * t \end{ocamldoccode} \index{partition@\verb`partition`} \begin{ocamldocdescription} {\tt{partition p ra}} {\bf Returns }a pair of resizable arrays, the left part containing only elements of {\tt{ra}} that satisfy predicate {\tt{p}}, the right one only those that do not satisfy it. Both returned arrays are created using the strategy of {\tt{ra}}. \end{ocamldocdescription} {\bf UNSAFE STUFF - USE WITH CAUTION!} \label{val:Nopres-underscoreintf.T.unsafe-underscoreget}\begin{ocamldoccode} val unsafe_get : t -> int -> el \end{ocamldoccode} \index{unsafe-underscoreget@\verb`unsafe_get`} \label{val:Nopres-underscoreintf.T.unsafe-underscoreset}\begin{ocamldoccode} val unsafe_set : t -> int -> el -> unit \end{ocamldoccode} \index{unsafe-underscoreset@\verb`unsafe_set`} \label{val:Nopres-underscoreintf.T.unsafe-underscoresub}\begin{ocamldoccode} val unsafe_sub : t -> int -> int -> t \end{ocamldoccode} \index{unsafe-underscoresub@\verb`unsafe_sub`} \label{val:Nopres-underscoreintf.T.unsafe-underscorefill}\begin{ocamldoccode} val unsafe_fill : t -> int -> int -> el -> unit \end{ocamldoccode} \index{unsafe-underscorefill@\verb`unsafe_fill`} \label{val:Nopres-underscoreintf.T.unsafe-underscoreblit}\begin{ocamldoccode} val unsafe_blit : t -> int -> t -> int -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreblit@\verb`unsafe_blit`} \label{val:Nopres-underscoreintf.T.unsafe-underscoreremove-underscoreone}\begin{ocamldoccode} val unsafe_remove_one : t -> unit \end{ocamldoccode} \index{unsafe-underscoreremove-underscoreone@\verb`unsafe_remove_one`} \label{val:Nopres-underscoreintf.T.unsafe-underscoreremove-underscoren}\begin{ocamldoccode} val unsafe_remove_n : t -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreremove-underscoren@\verb`unsafe_remove_n`} \label{val:Nopres-underscoreintf.T.unsafe-underscoreswap}\begin{ocamldoccode} val unsafe_swap : t -> int -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreswap@\verb`unsafe_swap`} \label{val:Nopres-underscoreintf.T.unsafe-underscoreswap-underscorein-underscorelast}\begin{ocamldoccode} val unsafe_swap_in_last : t -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreswap-underscorein-underscorelast@\verb`unsafe_swap_in_last`} \end{ocamldocsigend} \begin{ocamldocdescription} Interface to unparameterized resizable arrays \end{ocamldocdescription} \begin{ocamldoccode} {\tt{module type }}{\tt{Buffer}}{\tt{ = }}\end{ocamldoccode} \label{moduletype:Nopres-underscoreintf.Buffer}\index{Buffer@\verb`Buffer`} \begin{ocamldocsigend} {\tt{include }}{\tt{Nopres\_intf.T}} Includes all functions that exist in non-parameterized arrays. String conversions \label{val:Nopres-underscoreintf.Buffer.sof-underscorestring}\begin{ocamldoccode} val sof_string : strategy -> string -> t \end{ocamldoccode} \index{sof-underscorestring@\verb`sof_string`} \begin{ocamldocdescription} {\tt{sof\_string s ar}} converts a string to a resizable buffer using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.Buffer.of-underscorestring}\begin{ocamldoccode} val of_string : string -> t \end{ocamldoccode} \index{of-underscorestring@\verb`of_string`} \begin{ocamldocdescription} {\tt{of\_string ar}} converts a string to a resizable buffer using the default strategy. \end{ocamldocdescription} Functions found in the standard {\tt{Buffer}}-module Note that the function {\tt{create n}} ignores the parameter {\tt{n}} and uses the default strategy instead. You can supply a different strategy with {\tt{creates s n}} as described above. \label{val:Nopres-underscoreintf.Buffer.contents}\begin{ocamldoccode} val contents : t -> string \end{ocamldoccode} \index{contents@\verb`contents`} \begin{ocamldocdescription} {\tt{contents b}} {\bf Returns }a copy of the current contents of the buffer {\tt{b}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.Buffer.reset}\begin{ocamldoccode} val reset : t -> unit \end{ocamldoccode} \index{reset@\verb`reset`} \begin{ocamldocdescription} {\tt{reset b}} just clears the buffer, possibly resizing it. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.Buffer.add-underscorechar}\begin{ocamldoccode} val add_char : t -> char -> unit \end{ocamldoccode} \index{add-underscorechar@\verb`add_char`} \begin{ocamldocdescription} {\tt{add\_char b c}} appends the character {\tt{c}} at the end of the buffer {\tt{b}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.Buffer.add-underscorestring}\begin{ocamldoccode} val add_string : t -> string -> unit \end{ocamldoccode} \index{add-underscorestring@\verb`add_string`} \begin{ocamldocdescription} {\tt{add\_string b s}} appends the string {\tt{s}} at the end of the buffer {\tt{b}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.Buffer.add-underscoresubstring}\begin{ocamldoccode} val add_substring : t -> string -> int -> int -> unit \end{ocamldoccode} \index{add-underscoresubstring@\verb`add_substring`} \begin{ocamldocdescription} {\tt{add\_substring b s ofs len}} takes {\tt{len}} characters from offset {\tt{ofs}} in string {\tt{s}} and appends them at the end of the buffer {\tt{b}}. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.Buffer.add-underscorebuffer}\begin{ocamldoccode} val add_buffer : t -> t -> unit \end{ocamldoccode} \index{add-underscorebuffer@\verb`add_buffer`} \begin{ocamldocdescription} {\tt{add\_buffer b1 b2}} appends the current contents of buffer {\tt{b2}} at the end of buffer {\tt{b1}}. {\tt{b2}} is not modified. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.Buffer.add-underscorechannel}\begin{ocamldoccode} val add_channel : t -> Pervasives.in_channel -> int -> unit \end{ocamldoccode} \index{add-underscorechannel@\verb`add_channel`} \begin{ocamldocdescription} {\tt{add\_channel b ic n}} reads exactly {\tt{n}} character from the input channel {\tt{ic}} and stores them at the end of buffer {\tt{b}}. {\bf Raises} {\tt{End\_of\_file}} if the channel contains fewer than {\tt{n}} characters. \end{ocamldocdescription} \label{val:Nopres-underscoreintf.Buffer.output-underscorebuffer}\begin{ocamldoccode} val output_buffer : Pervasives.out_channel -> t -> unit \end{ocamldoccode} \index{output-underscorebuffer@\verb`output_buffer`} \begin{ocamldocdescription} {\tt{output\_buffer oc b}} writes the current contents of buffer {\tt{b}} on the output channel {\tt{oc}}. \end{ocamldocdescription} Additional buffer functions \label{val:Nopres-underscoreintf.Buffer.add-underscorefull-underscorechannel}\begin{ocamldoccode} val add_full_channel : t -> Pervasives.in_channel -> unit \end{ocamldoccode} \index{add-underscorefull-underscorechannel@\verb`add_full_channel`} \label{val:Nopres-underscoreintf.Buffer.add-underscorefull-underscorechannel-underscoref}\begin{ocamldoccode} val add_full_channel_f : t -> Pervasives.in_channel -> int -> (int -> int) -> unit \end{ocamldoccode} \index{add-underscorefull-underscorechannel-underscoref@\verb`add_full_channel_f`} \end{ocamldocsigend} \begin{ocamldocdescription} Extended interface to buffers (resizable strings) \end{ocamldocdescription} \section{Module {\tt{Weak\_intf}} : Interface to weak resizable arrays} \label{module:Weak-underscoreintf}\index{Weak-underscoreintf@\verb`Weak_intf`} \ocamldocvspace{0.5cm} \begin{ocamldoccode} {\tt{module type }}{\tt{T}}{\tt{ = }}\end{ocamldoccode} \label{moduletype:Weak-underscoreintf.T}\index{T@\verb`T`} \begin{ocamldocsigend} Signatures and types \begin{ocamldoccode} {\tt{module }}{\tt{Strategy}}{\tt{ : }}\end{ocamldoccode} \label{module:Weak-underscoreintf.T.Strategy}\index{Strategy@\verb`Strategy`} {\tt{Strat.T}}{\tt{ }}{\tt{}} \begin{ocamldocdescription} Module implementing the reallocation strategy \end{ocamldocdescription} \label{type:Weak-underscoreintf.T.strategy}\begin{ocamldoccode} type strategy = Strategy.t \end{ocamldoccode} \index{strategy@\verb`strategy`} \begin{ocamldocdescription} Type of reallocation strategy \end{ocamldocdescription} \label{type:Weak-underscoreintf.T.t}\begin{ocamldoccode} type 'a t \end{ocamldoccode} \index{t@\verb`t`} \begin{ocamldocdescription} Type of parameterized resizable arrays \end{ocamldocdescription} Index and length information \label{val:Weak-underscoreintf.T.length}\begin{ocamldoccode} val length : 'a t -> int \end{ocamldoccode} \index{length@\verb`length`} \begin{ocamldocdescription} {\tt{length ra}} {\bf Returns }(virtual) length of resizable array {\tt{ra}} excluding the reserved space. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.lix}\begin{ocamldoccode} val lix : 'a t -> int \end{ocamldoccode} \index{lix@\verb`lix`} \begin{ocamldocdescription} {\tt{lix ra}} {\bf Returns }(virtual) last index of resizable array {\tt{ra}} excluding the reserved space. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.real-underscorelength}\begin{ocamldoccode} val real_length : 'a t -> int \end{ocamldoccode} \index{real-underscorelength@\verb`real_length`} \begin{ocamldocdescription} {\tt{real\_length ra}} {\bf Returns }(real) length of resizable array {\tt{ra}} including the reserved space. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.real-underscorelix}\begin{ocamldoccode} val real_lix : 'a t -> int \end{ocamldoccode} \index{real-underscorelix@\verb`real_lix`} \begin{ocamldocdescription} {\tt{real\_lix ra}} {\bf Returns }(real) last index of resizable array {\tt{ra}} including the reserved space. \end{ocamldocdescription} Getting, setting and checking \label{val:Weak-underscoreintf.T.get}\begin{ocamldoccode} val get : 'a t -> int -> 'a option \end{ocamldoccode} \index{get@\verb`get`} \begin{ocamldocdescription} {\tt{get ra n}} {\bf Raises} {\tt{Invalid\_argument}} if index out of bounds. {\bf Returns }the {\tt{n}}th element of {\tt{ra}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.get-underscorecopy}\begin{ocamldoccode} val get_copy : 'a t -> int -> 'a option \end{ocamldoccode} \index{get-underscorecopy@\verb`get_copy`} \begin{ocamldocdescription} {\tt{get\_copy ra n}} see documentation of module {\tt{Weak}} in the standard distribution. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.check}\begin{ocamldoccode} val check : 'a t -> int -> bool \end{ocamldoccode} \index{check@\verb`check`} \begin{ocamldocdescription} {\tt{check ra n}} {\bf Returns }{\tt{true}} if the {\tt{n}}th cell of {\tt{ra}} is full, {\tt{false}} if it is empty. Note that even if {\tt{check ar n}} returns {\tt{true}}, a subsequent {\tt{Weak\_intf.T.get}}[\ref{val:Weak-underscoreintf.T.get}]{\tt{ ar n}} can return {\tt{None}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.set}\begin{ocamldoccode} val set : 'a t -> int -> 'a option -> unit \end{ocamldoccode} \index{set@\verb`set`} \begin{ocamldocdescription} {\tt{set ra n}} sets the {\tt{n}}th element of {\tt{ra}}. {\bf Raises} {\tt{Invalid\_argument}} if index out of bounds. \end{ocamldocdescription} Creation of resizable arrays \label{val:Weak-underscoreintf.T.sempty}\begin{ocamldoccode} val sempty : strategy -> 'a t \end{ocamldoccode} \index{sempty@\verb`sempty`} \begin{ocamldocdescription} {\tt{sempty s}} {\bf Returns }an empty resizable array using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.empty}\begin{ocamldoccode} val empty : unit -> 'a t \end{ocamldoccode} \index{empty@\verb`empty`} \begin{ocamldocdescription} {\tt{empty ()}} same as {\tt{sempty}} but uses default strategy. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.screate}\begin{ocamldoccode} val screate : strategy -> int -> 'a t \end{ocamldoccode} \index{screate@\verb`screate`} \begin{ocamldocdescription} {\tt{screate s n el}} {\bf Returns }a resizable array of length {\tt{n}} using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.create}\begin{ocamldoccode} val create : int -> 'a t \end{ocamldoccode} \index{create@\verb`create`} \begin{ocamldocdescription} {\tt{create n}} same as {\tt{screate}} but uses default strategy. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.sinit}\begin{ocamldoccode} val sinit : strategy -> int -> (int -> 'a option) -> 'a t \end{ocamldoccode} \index{sinit@\verb`sinit`} \begin{ocamldocdescription} {\tt{sinit s n f}} {\bf Returns }an array of length {\tt{n}} containing elements that were created by applying function {\tt{f}} to the index, using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.init}\begin{ocamldoccode} val init : int -> (int -> 'a option) -> 'a t \end{ocamldoccode} \index{init@\verb`init`} \begin{ocamldocdescription} {\tt{init n f}} sames as {\tt{sinit}} but uses default strategy. \end{ocamldocdescription} Strategy handling \label{val:Weak-underscoreintf.T.get-underscorestrategy}\begin{ocamldoccode} val get_strategy : 'a t -> strategy \end{ocamldoccode} \index{get-underscorestrategy@\verb`get_strategy`} \begin{ocamldocdescription} {\tt{get\_strategy ra}} {\bf Returns }the reallocation strategy used by resizable array {\tt{ra}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.set-underscorestrategy}\begin{ocamldoccode} val set_strategy : 'a t -> strategy -> unit \end{ocamldoccode} \index{set-underscorestrategy@\verb`set_strategy`} \begin{ocamldocdescription} {\tt{set\_strategy ra s}} sets the reallocation strategy of resizable array {\tt{ra}} to {\tt{s}}, possibly causing an immediate reallocation. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.put-underscorestrategy}\begin{ocamldoccode} val put_strategy : 'a t -> strategy -> unit \end{ocamldoccode} \index{put-underscorestrategy@\verb`put_strategy`} \begin{ocamldocdescription} {\tt{put\_strategy ra s}} sets the reallocation strategy of resizable array {\tt{ra}} to {\tt{s}}. Reallocation is only done at later changes in size. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.enforce-underscorestrategy}\begin{ocamldoccode} val enforce_strategy : 'a t -> unit \end{ocamldoccode} \index{enforce-underscorestrategy@\verb`enforce_strategy`} \begin{ocamldocdescription} {\tt{enforce\_strategy ra}} forces a reallocation if necessary (e.g. after a {\tt{put\_strategy}}. \end{ocamldocdescription} Copying, blitting and range extraction \label{val:Weak-underscoreintf.T.copy}\begin{ocamldoccode} val copy : 'a t -> 'a t \end{ocamldoccode} \index{copy@\verb`copy`} \begin{ocamldocdescription} {\tt{copy ra}} {\bf Returns }a copy of resizable array {\tt{ra}}. The two arrays share the same strategy! \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.sub}\begin{ocamldoccode} val sub : 'a t -> int -> int -> 'a t \end{ocamldoccode} \index{sub@\verb`sub`} \begin{ocamldocdescription} {\tt{sub ra ofs len}} {\bf Raises} {\tt{Invalid\_argument}} if parameters do not denote a correct subarray. {\bf Returns }a resizable subarray of length {\tt{len}} from resizable array {\tt{ra}} starting at offset {\tt{ofs}} using the default strategy. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.fill}\begin{ocamldoccode} val fill : 'a t -> int -> int -> 'a option -> unit \end{ocamldoccode} \index{fill@\verb`fill`} \begin{ocamldocdescription} {\tt{fill ra ofs len el}} fills resizable array {\tt{ra}} from offset {\tt{ofs}} with {\tt{len}} elements {\tt{el}}, possibly adding elements at the end. Raises {\tt{Invalid\_argument}} if offset {\tt{ofs}} is larger than the length of the array. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.blit}\begin{ocamldoccode} val blit : 'a t -> int -> 'a t -> int -> int -> unit \end{ocamldoccode} \index{blit@\verb`blit`} \begin{ocamldocdescription} {\tt{blit ra1 ofs1 ra2 ofs2 len}} blits resizable array {\tt{ra1}} onto {\tt{ra2}} reading {\tt{len}} elements from offset {\tt{ofs1}} and writing them to {\tt{ofs2}}, possibly adding elements at the end of ra2. Raises {\tt{Invalid\_argument}} if {\tt{ofs1}} and {\tt{len}} do not designate a valid subarray of {\tt{ra1}} or if {\tt{ofs2}} is larger than the length of {\tt{ra2}}. \end{ocamldocdescription} Combining resizable arrays \label{val:Weak-underscoreintf.T.append}\begin{ocamldoccode} val append : 'a t -> 'a t -> 'a t \end{ocamldoccode} \index{append@\verb`append`} \begin{ocamldocdescription} {\tt{append ra1 ra2}} {\bf Returns }a new resizable array using the default strategy and copying {\tt{ra1}} and {\tt{ra2}} in this order onto it. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.concat}\begin{ocamldoccode} val concat : 'a t list -> 'a t \end{ocamldoccode} \index{concat@\verb`concat`} \begin{ocamldocdescription} {\tt{concat l}} {\bf Returns }a new resizable array using the default strategy and copying all resizable arrays in {\tt{l}} in their respective order onto it. \end{ocamldocdescription} Adding and removing elements \label{val:Weak-underscoreintf.T.add-underscoreone}\begin{ocamldoccode} val add_one : 'a t -> 'a option -> unit \end{ocamldoccode} \index{add-underscoreone@\verb`add_one`} \begin{ocamldocdescription} {\tt{add\_one ra el}} adds element {\tt{el}} to resizable array {\tt{ra}}, possibly causing a reallocation. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.remove-underscoreone}\begin{ocamldoccode} val remove_one : 'a t -> unit \end{ocamldoccode} \index{remove-underscoreone@\verb`remove_one`} \begin{ocamldocdescription} {\tt{remove\_one ra}} removes the last element of resizable array {\tt{ra}}, possibly causing a reallocation. {\bf Raises} {\tt{Failure}} if the array is empty. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.remove-underscoren}\begin{ocamldoccode} val remove_n : 'a t -> int -> unit \end{ocamldoccode} \index{remove-underscoren@\verb`remove_n`} \begin{ocamldocdescription} {\tt{remove\_n ra n}} removes the last n elements of resizable array {\tt{ra}}, possibly causing a reallocation. {\bf Raises} {\tt{Invalid\_arg}} if there are not enough elements or {\tt{n < 0}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.remove-underscorerange}\begin{ocamldoccode} val remove_range : 'a t -> int -> int -> unit \end{ocamldoccode} \index{remove-underscorerange@\verb`remove_range`} \begin{ocamldocdescription} {\tt{remove\_range ra ofs len}} removes {\tt{len}} elements from resizable array {\tt{ra}} starting at {\tt{ofs}} and possibly causing a reallocation. {\bf Raises} {\tt{Invalid\_argument}} if range is invalid. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.clear}\begin{ocamldoccode} val clear : 'a t -> unit \end{ocamldoccode} \index{clear@\verb`clear`} \begin{ocamldocdescription} {\tt{clear ra}} removes all elements from resizable array {\tt{ra}}, possibly causing a reallocation. \end{ocamldocdescription} Swapping \label{val:Weak-underscoreintf.T.swap}\begin{ocamldoccode} val swap : 'a t -> int -> int -> unit \end{ocamldoccode} \index{swap@\verb`swap`} \begin{ocamldocdescription} {\tt{swap ra n m}} swaps elements at indices {\tt{n}} and {\tt{m}}. {\bf Raises} {\tt{Invalid\_argument}} if any index is out of range. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.swap-underscorein-underscorelast}\begin{ocamldoccode} val swap_in_last : 'a t -> int -> unit \end{ocamldoccode} \index{swap-underscorein-underscorelast@\verb`swap_in_last`} \begin{ocamldocdescription} {\tt{swap\_in\_last ra n}} swaps the last element with the one at position {\tt{n}}. {\bf Raises} {\tt{Invalid\_argument}} if index {\tt{n}} is out of range. \end{ocamldocdescription} Standard conversions \label{val:Weak-underscoreintf.T.to-underscorestd}\begin{ocamldoccode} val to_std : 'a t -> 'a Weak.t \end{ocamldoccode} \index{to-underscorestd@\verb`to_std`} \begin{ocamldocdescription} {\tt{to\_std ra}} converts a resizable weak array to a standard one. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.sof-underscorestd}\begin{ocamldoccode} val sof_std : strategy -> 'a Weak.t -> 'a t \end{ocamldoccode} \index{sof-underscorestd@\verb`sof_std`} \begin{ocamldocdescription} {\tt{sof\_std s ar}} converts a standard weak array to a resizable one, using strategy {\tt{s}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.of-underscorestd}\begin{ocamldoccode} val of_std : 'a Weak.t -> 'a t \end{ocamldoccode} \index{of-underscorestd@\verb`of_std`} \begin{ocamldocdescription} {\tt{of\_std ar}} converts a standard weak array to a resizable one using the default strategy. \end{ocamldocdescription} List conversions \label{val:Weak-underscoreintf.T.to-underscorelist}\begin{ocamldoccode} val to_list : 'a t -> 'a option list \end{ocamldoccode} \index{to-underscorelist@\verb`to_list`} \begin{ocamldocdescription} {\tt{to\_list ra}} converts resizable array {\tt{ra}} to a list. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.of-underscorelist}\begin{ocamldoccode} val of_list : 'a option list -> 'a t \end{ocamldoccode} \index{of-underscorelist@\verb`of_list`} \begin{ocamldocdescription} {\tt{of\_list l}} creates a resizable array using the default strategy and the elements in list {\tt{l}}. \end{ocamldocdescription} Iterators \label{val:Weak-underscoreintf.T.iter}\begin{ocamldoccode} val iter : ('a option -> unit) -> 'a t -> unit \end{ocamldoccode} \index{iter@\verb`iter`} \begin{ocamldocdescription} {\tt{iter f ra}} applies the unit-function {\tt{f}} to each element in resizable array {\tt{ra}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.iteri}\begin{ocamldoccode} val iteri : (int -> 'a option -> unit) -> 'a t -> unit \end{ocamldoccode} \index{iteri@\verb`iteri`} \begin{ocamldocdescription} {\tt{iteri f ra}} applies the unit-function {\tt{f}} to each index and element in resizable array {\tt{ra}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.fold-underscoreleft}\begin{ocamldoccode} val fold_left : ('a -> 'b option -> 'a) -> 'a -> 'b t -> 'a \end{ocamldoccode} \index{fold-underscoreleft@\verb`fold_left`} \begin{ocamldocdescription} {\tt{fold\_left f a ra}} left-folds values in resizable array {\tt{ra}} using function {\tt{f}} and start accumulator {\tt{a}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.fold-underscoreright}\begin{ocamldoccode} val fold_right : ('a option -> 'b -> 'b) -> 'a t -> 'b -> 'b \end{ocamldoccode} \index{fold-underscoreright@\verb`fold_right`} \begin{ocamldocdescription} {\tt{fold\_right f a ra}} right-folds values in resizable array {\tt{ra}} using function {\tt{f}} and start accumulator {\tt{a}}. \end{ocamldocdescription} Scanning of resizable arrays \label{val:Weak-underscoreintf.T.for-underscoreall}\begin{ocamldoccode} val for_all : ('a option -> bool) -> 'a t -> bool \end{ocamldoccode} \index{for-underscoreall@\verb`for_all`} \begin{ocamldocdescription} {\tt{for\_all p ra}} {\bf Returns }{\tt{true}} if all elements in resizable array {\tt{ra}} satisfy the predicate {\tt{p}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.exists}\begin{ocamldoccode} val exists : ('a option -> bool) -> 'a t -> bool \end{ocamldoccode} \index{exists@\verb`exists`} \begin{ocamldocdescription} {\tt{exists p ra}} {\bf Returns }{\tt{true}} if at least one element in resizable array {\tt{ra}} satisfies the predicate {\tt{p}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.mem}\begin{ocamldoccode} val mem : 'a option -> 'a t -> bool \end{ocamldoccode} \index{mem@\verb`mem`} \begin{ocamldocdescription} {\tt{mem el ra}} {\bf Returns }{\tt{true}} if element {\tt{el}} is logically equal to any element in resizable array {\tt{ra}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.memq}\begin{ocamldoccode} val memq : 'a option -> 'a t -> bool \end{ocamldoccode} \index{memq@\verb`memq`} \begin{ocamldocdescription} {\tt{memq el ra}} {\bf Returns }{\tt{true}} if element {\tt{el}} is physically equal to any element in resizable array {\tt{ra}}, {\tt{false}} otherwise. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.pos}\begin{ocamldoccode} val pos : 'a option -> 'a t -> int option \end{ocamldoccode} \index{pos@\verb`pos`} \begin{ocamldocdescription} {\tt{pos el ra}} {\bf Returns }{\tt{Some index}} if {\tt{el}} is logically equal to the element at {\tt{index}} in {\tt{ra}}, {\tt{None}} otherwise. {\tt{index}} is the index of the first element that matches. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.posq}\begin{ocamldoccode} val posq : 'a option -> 'a t -> int option \end{ocamldoccode} \index{posq@\verb`posq`} \begin{ocamldocdescription} {\tt{posq el ra}} {\bf Returns }{\tt{Some index}} if {\tt{el}} is physically equal to the element at {\tt{index}} in {\tt{ra}}, {\tt{None}} otherwise. {\tt{index}} is the index of the first element that matches. \end{ocamldocdescription} Searching of resizable arrays \label{val:Weak-underscoreintf.T.find}\begin{ocamldoccode} val find : ('a option -> bool) -> 'a t -> 'a option \end{ocamldoccode} \index{find@\verb`find`} \begin{ocamldocdescription} {\tt{find p ra}} {\bf Raises} {\tt{Not\_found}} if there is no such element. {\bf Returns }the first element in resizable array {\tt{ra}} that satisfies predicate {\tt{p}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.find-underscoreindex}\begin{ocamldoccode} val find_index : ('a option -> bool) -> 'a t -> int -> int \end{ocamldoccode} \index{find-underscoreindex@\verb`find_index`} \begin{ocamldocdescription} {\tt{find\_index p ra pos}} {\bf Raises} \begin{itemize} \item {\tt{Not\_found}} if there is no such element or if {\tt{pos}} is larger than the highest index. \item {\tt{Invalid\_argument}} if {\tt{pos}} is negative. \end{itemize} {\bf Returns }the index of the first element that satisfies predicate {\tt{p}} in resizable array {\tt{ra}}, starting search at index {\tt{pos}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.filter}\begin{ocamldoccode} val filter : ('a option -> bool) -> 'a t -> 'a t \end{ocamldoccode} \index{filter@\verb`filter`} \begin{ocamldocdescription} {\tt{filter p ra}} {\bf Returns }a new resizable array by filtering out all elements in {\tt{ra}} that satisfy predicate {\tt{p}} using the same strategy as {\tt{ra}}. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.find-underscoreall}\begin{ocamldoccode} val find_all : ('a option -> bool) -> 'a t -> 'a t \end{ocamldoccode} \index{find-underscoreall@\verb`find_all`} \begin{ocamldocdescription} {\tt{find\_all p ra}} is the same as {\tt{filter}} \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.filter-underscorein-underscoreplace}\begin{ocamldoccode} val filter_in_place : ('a option -> bool) -> 'a t -> unit \end{ocamldoccode} \index{filter-underscorein-underscoreplace@\verb`filter_in_place`} \begin{ocamldocdescription} {\tt{filter\_in\_place p ra}} as {\tt{filter}}, but filters in place. \end{ocamldocdescription} \label{val:Weak-underscoreintf.T.partition}\begin{ocamldoccode} val partition : ('a option -> bool) -> 'a t -> 'a t * 'a t \end{ocamldoccode} \index{partition@\verb`partition`} \begin{ocamldocdescription} {\tt{partition p ra}} {\bf Returns }a pair of resizable arrays, the left part containing only elements of {\tt{ra}} that satisfy predicate {\tt{p}}, the right one only those that do not satisfy it. Both returned arrays are created using the strategy of {\tt{ra}}. \end{ocamldocdescription} {\bf UNSAFE STUFF - USE WITH CAUTION!} \label{val:Weak-underscoreintf.T.unsafe-underscoreget}\begin{ocamldoccode} val unsafe_get : 'a t -> int -> 'a option \end{ocamldoccode} \index{unsafe-underscoreget@\verb`unsafe_get`} \label{val:Weak-underscoreintf.T.unsafe-underscoreset}\begin{ocamldoccode} val unsafe_set : 'a t -> int -> 'a option -> unit \end{ocamldoccode} \index{unsafe-underscoreset@\verb`unsafe_set`} \label{val:Weak-underscoreintf.T.unsafe-underscoresub}\begin{ocamldoccode} val unsafe_sub : 'a t -> int -> int -> 'a t \end{ocamldoccode} \index{unsafe-underscoresub@\verb`unsafe_sub`} \label{val:Weak-underscoreintf.T.unsafe-underscorefill}\begin{ocamldoccode} val unsafe_fill : 'a t -> int -> int -> 'a option -> unit \end{ocamldoccode} \index{unsafe-underscorefill@\verb`unsafe_fill`} \label{val:Weak-underscoreintf.T.unsafe-underscoreblit}\begin{ocamldoccode} val unsafe_blit : 'a t -> int -> 'a t -> int -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreblit@\verb`unsafe_blit`} \label{val:Weak-underscoreintf.T.unsafe-underscoreremove-underscoreone}\begin{ocamldoccode} val unsafe_remove_one : 'a t -> unit \end{ocamldoccode} \index{unsafe-underscoreremove-underscoreone@\verb`unsafe_remove_one`} \label{val:Weak-underscoreintf.T.unsafe-underscoreremove-underscoren}\begin{ocamldoccode} val unsafe_remove_n : 'a t -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreremove-underscoren@\verb`unsafe_remove_n`} \label{val:Weak-underscoreintf.T.unsafe-underscoreswap}\begin{ocamldoccode} val unsafe_swap : 'a t -> int -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreswap@\verb`unsafe_swap`} \label{val:Weak-underscoreintf.T.unsafe-underscoreswap-underscorein-underscorelast}\begin{ocamldoccode} val unsafe_swap_in_last : 'a t -> int -> unit \end{ocamldoccode} \index{unsafe-underscoreswap-underscorein-underscorelast@\verb`unsafe_swap_in_last`} \end{ocamldocsigend} \section{Module {\tt{Res}} : Global module for resizable datastructures and default implementations} \label{module:Res}\index{Res@\verb`Res`} \ocamldocvspace{0.5cm} Default strategies \begin{ocamldoccode} {\tt{module }}{\tt{DefStrat}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.DefStrat}\index{DefStrat@\verb`DefStrat`} {\tt{Strat.T}}{\tt{ }}{\tt{ with type t = float * float * int}} \begin{ocamldocdescription} Default strategy for resizable datastructures {\tt{type t}} is a triple {\tt{waste, shrink\_trig, min\_size}}, where {\tt{waste}} (default: 1.5) indicates by how much the array should be grown in excess when reallocation is triggered, {\tt{shrink\_trig}} (default: 0.5) at which percentage of excess elements it should be shrinked and {\tt{min\_size}} (default: 16 elements) is the minimum size of the resizable array. \end{ocamldocdescription} \begin{ocamldoccode} {\tt{module }}{\tt{BitDefStrat}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.BitDefStrat}\index{BitDefStrat@\verb`BitDefStrat`} {\tt{Strat.T}}{\tt{ }}{\tt{ with type t = float * float * int}} \begin{ocamldocdescription} Same as {\tt{DefStrat}}, but the minimum size is 1024 elements (bits). \end{ocamldocdescription} Default instantiation of standard resizable datastructures \begin{ocamldoccode} {\tt{module }}{\tt{Array}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.Array}\index{Array@\verb`Array`} {\tt{Pres\_intf.T}}{\tt{ }}{\tt{ with module Strategy = DefStrat}} \begin{ocamldocdescription} Resizable parameterized array using the default reallocation strategy. \end{ocamldocdescription} \begin{ocamldoccode} {\tt{module }}{\tt{Floats}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.Floats}\index{Floats@\verb`Floats`} {\tt{Nopres\_intf.T}}{\tt{ }}{\tt{ with module Strategy = DefStrat and type el = float}} \begin{ocamldocdescription} Resizable float array using the default reallocation strategy. \end{ocamldocdescription} \begin{ocamldoccode} {\tt{module }}{\tt{Bits}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.Bits}\index{Bits@\verb`Bits`} {\tt{Nopres\_intf.T}}{\tt{ }}{\tt{ with module Strategy = BitDefStrat and type el = bool}} \begin{ocamldocdescription} Resizable bit vector using the default reallocation strategy. \end{ocamldocdescription} \begin{ocamldoccode} {\tt{module }}{\tt{Weak}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.Weak}\index{Weak@\verb`Weak`} {\tt{Weak\_intf.T}}{\tt{ }}{\tt{ with module Strategy = DefStrat}} \begin{ocamldocdescription} Resizable weak array using the default reallocation strategy. \end{ocamldocdescription} \begin{ocamldoccode} {\tt{module }}{\tt{Buffer}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.Buffer}\index{Buffer@\verb`Buffer`} {\tt{Nopres\_intf.Buffer}}{\tt{ }}{\tt{ with module Strategy = DefStrat and type el = char}} \begin{ocamldocdescription} Resizable buffer using the default reallocation strategy. \end{ocamldocdescription} Functors for creating standard resizable datastructures from strategies \begin{ocamldoccode} {\tt{module }}{\tt{MakeArray}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.MakeArray}\index{MakeArray@\verb`MakeArray`} {\tt{functor (}}{\tt{S}}{\tt{ : }}{\tt{Strat.T}}{\tt{) -> }}{\tt{Pres\_intf.T}}{\tt{ }}{\tt{ with module Strategy = S}} \begin{ocamldocdescription} Functor that creates resizable parameterized arrays from reallocation strategies. \end{ocamldocdescription} \begin{ocamldoccode} {\tt{module }}{\tt{MakeFloats}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.MakeFloats}\index{MakeFloats@\verb`MakeFloats`} {\tt{functor (}}{\tt{S}}{\tt{ : }}{\tt{Strat.T}}{\tt{) -> }}{\tt{Nopres\_intf.T}}{\tt{ }}{\tt{ with module Strategy = S and type el = float}} \begin{ocamldocdescription} Functor that creates resizable float arrays from reallocation strategies. \end{ocamldocdescription} \begin{ocamldoccode} {\tt{module }}{\tt{MakeBits}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.MakeBits}\index{MakeBits@\verb`MakeBits`} {\tt{functor (}}{\tt{S}}{\tt{ : }}{\tt{Strat.T}}{\tt{) -> }}{\tt{Nopres\_intf.T}}{\tt{ }}{\tt{ with module Strategy = S and type el = bool}} \begin{ocamldocdescription} Functor that creates resizable bit vectors from reallocation strategies. \end{ocamldocdescription} \begin{ocamldoccode} {\tt{module }}{\tt{MakeWeak}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.MakeWeak}\index{MakeWeak@\verb`MakeWeak`} {\tt{functor (}}{\tt{S}}{\tt{ : }}{\tt{Strat.T}}{\tt{) -> }}{\tt{Weak\_intf.T}}{\tt{ }}{\tt{ with module Strategy = S}} \begin{ocamldocdescription} Functor that creates resizable weak arrays from reallocation strategies. \end{ocamldocdescription} \begin{ocamldoccode} {\tt{module }}{\tt{MakeBuffer}}{\tt{ : }}\end{ocamldoccode} \label{module:Res.MakeBuffer}\index{MakeBuffer@\verb`MakeBuffer`} {\tt{functor (}}{\tt{S}}{\tt{ : }}{\tt{Strat.T}}{\tt{) -> }}{\tt{Nopres\_intf.Buffer}}{\tt{ }}{\tt{ with module Strategy = S and type el = char}} \begin{ocamldocdescription} Functor that creates resizable buffers ($=$string arrays) from reallocation strategies. \end{ocamldocdescription} \end{document}