Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file nopres_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408(*
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
*)(** Interfaces to unparameterized resizable arrays and buffers *)(** Interface to unparameterized resizable arrays *)moduletypeT=sig(** {6 Signatures and types} *)(** Module implementing the reallocation strategy *)moduleStrategy:Strat.Ttypestrategy=Strategy.t(** Type of reallocation strategy *)typet(** Type of resizable arrays *)typeel(** Type of the elements in the resizable array *)(** {6 Index and length information} *)vallength:t->int(** [length ra] @return (virtual) length of resizable array [ra]
excluding the reserved space. *)vallix:t->int(** [lix ra] @return (virtual) last index of resizable array [ra]
excluding the reserved space. *)valreal_length:t->int(** [real_length ra] @return (real) length of resizable array [ra]
including the reserved space. *)valreal_lix:t->int(** [real_lix ra] @return (real) last index of resizable array [ra]
including the reserved space. *)(** {6 Getting and setting} *)valget:t->int->el(** [get ra n] @return the [n]th element of [ra].
@raise Invalid_argument if index out of bounds. *)valset:t->int->el->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->t(** [sempty s] @return an empty resizable array using strategy [s]. *)valempty:unit->t(** [empty ()] same as [sempty] but uses default strategy. *)valscreate:strategy->int->t(** [screate s n] @return a resizable array with strategy [s]
containing [n] arbitrary elements.
{e Attention: the contents is {b not} specified!} *)valcreate:int->t(** [create n] same as [screate] but uses default strategy. *)valsmake:strategy->int->el->t(** [smake s n el] @return a resizable array of length [n]
containing element [el] only using strategy [s]. *)valmake:int->el->t(** [make n el] same as [smake] but uses default strategy. *)valsinit:strategy->int->(int->el)->t(** [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->el)->t(** [init n f] sames as [sinit] but uses default strategy. *)(** {6 Strategy handling} *)valget_strategy:t->strategy(** [get_strategy ra] @return the reallocation strategy used by
resizable array [ra]. *)valset_strategy:t->strategy->unit(** [set_strategy ra s] sets the reallocation strategy of
resizable array [ra] to [s], possibly causing an immediate
reallocation. *)valput_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. *)valenforce_strategy:t->unit(** [enforce_strategy ra] forces a reallocation if necessary
(e.g. after a [put_strategy]. *)(** {6 Copying, blitting and range extraction} *)valcopy:t->t(** [copy ra] @return a copy of resizable array [ra]. The two
arrays share the same strategy! *)valsub:t->int->int->t(** [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: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. *)valblit: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]. *)(** {6 Combining resizable arrays} *)valappend:t->t->t(** [append ra1 ra2] @return a new resizable array using the
default strategy and copying [ra1] and [ra2] in this order onto
it. *)valconcat:tlist->t(** [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:t->el->unit(** [add_one ra el] adds element [el] to resizable array [ra],
possibly causing a reallocation. *)valremove_one:t->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:t->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:t->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:t->unit(** [clear ra] removes all elements from resizable array [ra],
possibly causing a reallocation. *)(** {6 Swapping} *)valswap:t->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:t->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:t->elarray(** [to_array ra] converts a resizable array to a standard one. *)valsof_array:strategy->elarray->t(** [sof_array s ar] converts a standard array to a resizable one,
using strategy [s]. *)valof_array:elarray->t(** [of_array ar] converts a standard array to a resizable one
using the default strategy. *)(** {6 List conversions} *)valto_list:t->ellist(** [to_list ra] converts resizable array [ra] to a list. *)valsof_list:strategy->ellist->t(** [sof_list s l] creates a resizable array using strategy [s] and
the elements in list [l]. *)valof_list:ellist->t(** [of_list l] creates a resizable array using the default
strategy and the elements in list [l]. *)(** {6 Iterators} *)valiter:(el->unit)->t->unit(** [iter f ra] applies the unit-function [f] to each element in
resizable array [ra]. *)valmap:(el->el)->t->t(** [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->el->unit)->t->unit(** [iteri f ra] applies the unit-function [f] to each index and
element in resizable array [ra]. *)valmapi:(int->el->el)->t->t(** [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:('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]. *)valfold_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]. *)(** {6 Scanning of resizable arrays} *)valfor_all:(el->bool)->t->bool(** [for_all p ra] @return [true] if all elements in resizable
array [ra] satisfy the predicate [p], [false] otherwise. *)valexists:(el->bool)->t->bool(** [exists p ra] @return [true] if at least one element in
resizable array [ra] satisfies the predicate [p], [false]
otherwise. *)valmem:el->t->bool(** [mem el ra] @return [true] if element [el] is logically equal
to any element in resizable array [ra], [false] otherwise. *)valmemq:el->t->bool(** [memq el ra] @return [true] if element [el] is physically equal
to any element in resizable array [ra], [false] otherwise. *)valpos:el->t->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:el->t->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:(el->bool)->t->el(** [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:(el->bool)->t->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:(el->bool)->t->t(** [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:(el->bool)->t->t(** [find_all p ra] is the same as [filter] *)valfilter_in_place:(el->bool)->t->unit(** [filter_in_place p ra] as [filter], but filters in place. *)valpartition:(el->bool)->t->t*t(** [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:t->int->elvalunsafe_set:t->int->el->unitvalunsafe_sub:t->int->int->tvalunsafe_fill:t->int->int->el->unitvalunsafe_blit:t->int->t->int->int->unitvalunsafe_remove_one:t->unitvalunsafe_remove_n:t->int->unitvalunsafe_swap:t->int->int->unitvalunsafe_swap_in_last:t->int->unitend(** Extended interface to buffers (resizable strings) *)moduletypeBuffer=sigincludeT(** Includes all functions that exist in non-parameterized arrays. *)(** {6 String conversions} *)valsof_string:strategy->string->t(** [sof_string s ar] converts a string to a resizable buffer
using strategy [s]. *)valof_string:string->t(** [of_string ar] converts a string to a resizable buffer using
the default strategy. *)(** {6 Functions found in the standard [Buffer]-module} *)(** Note that the function [create n] ignores the parameter [n] and
uses the default strategy instead. You can supply a different
strategy with [creates s n] as described above. *)valcontents:t->string(** [contents b] @return a copy of the current contents of the
buffer [b]. *)valreset:t->unit(** [reset b] just clears the buffer, possibly resizing it. *)valadd_char:t->char->unit(** [add_char b c] appends the character [c] at the end of
the buffer [b]. *)valadd_string:t->string->unit(** [add_string b s] appends the string [s] at the end of
the buffer [b]. *)valadd_substring:t->string->int->int->unit(** [add_substring b s ofs len] takes [len] characters from offset
[ofs] in string [s] and appends them at the end of the buffer
[b]. *)valadd_buffer:t->t->unit(** [add_buffer b1 b2] appends the current contents of buffer [b2]
at the end of buffer [b1]. [b2] is not modified. *)valadd_channel:t->in_channel->int->unit(** [add_channel b ic n] reads exactly [n] character from the
input channel [ic] and stores them at the end of buffer [b].
@raise End_of_file if the channel contains fewer than [n]
characters. *)valoutput_buffer:out_channel->t->unit(** [output_buffer oc b] writes the current contents of buffer [b]
on the output channel [oc]. *)(** {6 Additional buffer functions} *)valadd_full_channel:t->in_channel->unit(* [add_full_channel b ic] reads the whole channel [ic] into
buffer [b]. *)valadd_full_channel_f:t->in_channel->int->(int->int)->unit(* [add_full_channel_f b ic n f] reads the whole channel [ic] into
buffer [b], starting with read-ahead [n] and using function [f] to
calculate the next read-ahead if end-of-file was still not found. *)end