package sek

  1. Overview
  2. Docs

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 array * int * int) -> bool

is_valid (a, i, k) determines whether the index i and length k define a valid segment of the array a. is_valid is O(1).

val is_empty : ('a array * int * int) -> bool

is_empty seg determines whether the array segment seg is empty.

val iter : direction -> ('a array * int * int) -> ('a -> unit) -> unit

iter direction seg f applies the function f in turn to every element of the array segment seg. The direction of iteration is dictated by the parameter direction. If seg is of the form (a, i, k), then iter has complexity O(k), excluding the cost of the calls to f.

val iter2 : direction -> ('a array * int * int) -> ('b array * int * int) -> ('a -> 'b -> unit) -> unit

iter2 direction seg1 seg2 f applies the function f in turn to every pair of elements drawn synchronously from the the array segments seg1 and seg2. The two segments must have the same size. The direction of iteration is dictated by the parameter direction. iter2 has complexity O(n), excluding the cost of the calls to f, where n denotes the the size of the two segments.