package res
Module Res.MakeBuffer
Functor that creates resizable buffers (=string arrays) from reallocation strategies.
Parameters
Signature
Includes all functions that exist in non-parameterized arrays.
include Nopres_intf.T with module Strategy = S with type el = char
Signatures and types
module Strategy = SModule implementing the reallocation strategy
type strategy = Strategy.tType of reallocation strategy
Index and length information
val length : t -> intlength ra
val lix : t -> intlix ra
val real_length : t -> intreal_length ra
val real_lix : t -> intreal_lix ra
Getting and setting
Creation of resizable arrays
val empty : unit -> tempty () same as sempty but uses default strategy.
val create : int -> tcreate n same as screate but uses default strategy.
Strategy handling
set_strategy ra s sets the reallocation strategy of resizable array ra to s, possibly causing an immediate reallocation.
put_strategy ra s sets the reallocation strategy of resizable array ra to s. Reallocation is only done at later changes in size.
val enforce_strategy : t -> unitenforce_strategy ra forces a reallocation if necessary (e.g. after a put_strategy.
Copying, blitting and range extraction
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.
blit ra1 ofs1 ra2 ofs2 len blits resizable array ra1 onto ra2 reading len elements from offset ofs1 and writing them to ofs2, possibly adding elements at the end of ra2. Raises Invalid_argument if ofs1 and len do not designate a valid subarray of ra1 or if ofs2 is larger than the length of ra2.
Combining resizable arrays
Adding and removing elements
add_one ra el adds element el to resizable array ra, possibly causing a reallocation.
val remove_one : t -> unitremove_one ra removes the last element of resizable array ra, possibly causing a reallocation.
val remove_n : t -> int -> unitremove_n ra n removes the last n elements of resizable array ra, possibly causing a reallocation.
val remove_range : t -> int -> int -> unitremove_range ra ofs len removes len elements from resizable array ra starting at ofs and possibly causing a reallocation.
val clear : t -> unitclear ra removes all elements from resizable array ra, possibly causing a reallocation.
Swapping
val swap : t -> int -> int -> unitswap ra n m swaps elements at indices n and m.
val swap_in_last : t -> int -> unitswap_in_last ra n swaps the last element with the one at position n.
Array conversions
sof_array s ar converts a standard array to a resizable one, using strategy s.
of_array ar converts a standard array to a resizable one using the default strategy.
List conversions
sof_list s l creates a resizable array using strategy s and the elements in list l.
of_list l creates a resizable array using the default strategy and the elements in list l.
Iterators
iter f ra applies the unit-function f to each element in resizable array ra.
iteri f ra applies the unit-function f to each index and element in resizable array ra.
fold_left f a ra left-folds values in resizable array ra using function f and start accumulator a.
fold_right f a ra right-folds values in resizable array ra using function f and start accumulator a.
Scanning of resizable arrays
Searching of resizable arrays
filter_in_place p ra as filter, but filters in place.
UNSAFE STUFF - USE WITH CAUTION!
val unsafe_remove_one : t -> unitval unsafe_remove_n : t -> int -> unitval unsafe_swap : t -> int -> int -> unitval unsafe_swap_in_last : t -> int -> unitString conversions
sof_string s ar converts a string to a resizable buffer using strategy s.
val of_string : string -> tof_string ar converts a string to a resizable buffer using the default strategy.
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.
val contents : t -> stringcontents b
val reset : t -> unitreset b just clears the buffer, possibly resizing it.
val add_char : t -> char -> unitadd_char b c appends the character c at the end of the buffer b.
val add_string : t -> string -> unitadd_string b s appends the string s at the end of the buffer b.
val add_substring : t -> string -> int -> int -> unitadd_substring b s ofs len takes len characters from offset ofs in string s and appends them at the end of the buffer b.
add_buffer b1 b2 appends the current contents of buffer b2 at the end of buffer b1. b2 is not modified.
val add_channel : t -> in_channel -> int -> unitadd_channel b ic n reads exactly n character from the input channel ic and stores them at the end of buffer b.
val output_buffer : out_channel -> t -> unitoutput_buffer oc b writes the current contents of buffer b on the output channel oc.
Additional buffer functions
val add_full_channel : t -> in_channel -> unitval add_full_channel_f : t -> in_channel -> int -> (int -> int) -> unit