Module SEK.Segment
The module Segment
offers facilities for working with array segments. An array segment is a triple of an array, a start index, and a length.
val is_valid : 'a segment -> bool
is_valid (a, i, k)
determines whether the indexi
and lengthk
define a valid segment of the arraya
.is_valid
is O(1).
val is_empty : 'a segment -> bool
is_empty seg
determines whether the array segmentseg
is empty.
val iter : direction -> 'a segment -> ('a -> unit) -> unit
iter direction seg f
applies the functionf
in turn to every element of the array segmentseg
. The direction of iteration is dictated by the parameterdirection
. Ifseg
is of the form(a, i, k)
, theniter
has complexity O(k), excluding the cost of the calls tof
.
val iter2 : direction -> 'a segment -> 'b segment -> ('a -> 'b -> unit) -> unit
iter2 direction seg1 seg2 f
applies the functionf
in turn to every pair of elements drawn synchronously from the the array segmentsseg1
andseg2
. The two segments must have the same size. The direction of iteration is dictated by the parameterdirection
.iter2
has complexity O(n), excluding the cost of the calls tof
, where n denotes the the size of the two segments.