home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / cmlmcmpw.sit / Caml Light / Lib / cvect.mli < prev    next >
Encoding:
Text File  |  1991-05-01  |  3.6 KB  |  74 lines  |  [TEXT/MPS ]

  1. (* Operations on vectors, with sanity checks. *)
  2.  
  3. (* Special syntax to build a vector of length n, with elements e1, ..., en :
  4.       [| e1; ... ; en |].     *)
  5.  
  6. value vect_length : 'a vect -> int = 1 "vect_length"
  7.         (* Returns the length (number of elements) of the given vector. *)
  8. ;;
  9. value vect_item : 'a vect -> int -> 'a
  10.         (* "vect_item v n" returns element number n of vector v.
  11.            The first element has number 0.
  12.            The last element has number vect_length v - 1.
  13.            Raises Invalid_argument "vect_item" if n is outside the range
  14.            0 .. vect_length v - 1.
  15.            Special syntax is provided: "v.(n)" can be written in place of
  16.            "vect_item v n". *)
  17.   and vect_assign : 'a vect -> int -> 'a -> 'a
  18.         (* "vect_assign v n x" physically modifies vector v, replacing
  19.            element number n with element x.
  20.            Raises Invalid_argument "vect_assign" if n is outside the range
  21.            0 .. vect_length v - 1.
  22.            Special syntax is provided: "v.(n) <- x" can be written in place of
  23.            "vect_assign v n x". *)
  24. ;;
  25. value concat_vect : 'a vect -> 'a vect -> 'a vect
  26.         (* "concat_vect v1 v2" returns a fresh vector containing the
  27.            concatenation of vectors v1 and v2. *)
  28.   and sub_vect : 'a vect -> int -> int -> 'a vect
  29.         (* "sub_vect v start len" returns a fresh vector of length len,
  30.            containing elements number start through start + len - 1
  31.            of vector v.
  32.            Raises Invalid_argument "sub_vect" if start, len do not designate a
  33.            valid subvector of v; that is, if start < 0, or len > 0, or
  34.            start + len > vect_length v. *)
  35. ;;
  36. value make_vect : int -> 'a -> 'a vect
  37.         (* "make_vect n x" returns a fresh vector of length n,
  38.            initialized with n pointers to element x. *)
  39. ;;
  40. value fill_vect : 'a vect -> int -> int -> 'a -> 'a vect
  41.         (* "fill_vect v ofs len x" physically modifies vector v,
  42.            storing element x in elements number ofs through ofs + len - 1.
  43.            Raises Invalid_argument "fill_vect" if ofs, len do not designate
  44.            a valid subvector of v. *)
  45.   and blit_vect : 'a vect -> int -> 'a vect -> int -> int -> unit
  46.         (* "blit_vect v1 o1 v2 o2 len" copies len elements
  47.            from vector v1, starting at element number o1, to vector v2,
  48.            starting at element number o2. Works correctly even if v1 and v2
  49.            are the same vector, and the source chunk and destination chunk
  50.            overlap.
  51.            Raises Invalid_argument "blit_vector" if o1, len do not designate a
  52.            valid subvector of v1, or if o2, len do not designate a valid
  53.            subvector of v2. *)
  54. ;;
  55. value list_of_vect : 'a vect -> 'a list
  56.         (* "list_of_vect v" returns the list of all elements of v, that is:
  57.              [v.(0); v.(1); ...; v.(vect_length v - 1)]. *)
  58.   and vect_of_list : 'a list -> 'a vect
  59.         (* "vect_of_list l" returns a fresh vector containing the elements
  60.            of list l. *)
  61. ;;
  62. value do_vect : ('a -> 'b) -> 'a vect -> unit
  63.         (* "do_vect f v" applies function f in turn to all elements of v:
  64.               f v.(0); f v.(1); ...; f v.(vect_length v - 1). *)
  65.   and map_vect : ('a -> 'b) -> 'a vect -> 'b vect
  66.         (* "map_vect f v" applies function f to all elements of v, and builds
  67.            a vector with the results returned by f:
  68.               [| f v.(0); f v.(1); ...; f v.(vect_length v - 1) |]. *)
  69.   and map_vect_list : ('a -> 'b) -> 'a vect -> 'b list
  70.         (* "map_vect_list f v" applies function f to all elements of v,
  71.            and builds a list with the results returned by f:
  72.               [ f v.(0); f v.(1); ...; f v.(vect_length v - 1) ]. *)
  73. ;;
  74.