1997-02-24 11:24:39 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml *)
|
|
|
|
(* *)
|
1997-02-25 06:39:02 -08:00
|
|
|
(* Damien Doligez, projet Para, INRIA Rocquencourt *)
|
1997-02-24 11:24:39 -08:00
|
|
|
(* *)
|
1997-02-25 06:39:02 -08:00
|
|
|
(* Copyright 1997 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the GNU Library General Public License. *)
|
1997-02-24 11:24:39 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
(* Weak array operations *)
|
|
|
|
|
1997-03-13 08:24:05 -08:00
|
|
|
type 'a t;;
|
1997-02-24 11:24:39 -08:00
|
|
|
|
|
|
|
external create: int -> 'a t = "weak_create";;
|
|
|
|
|
1997-03-05 06:38:24 -08:00
|
|
|
let length x = Obj.size(Obj.repr x) - 1;;
|
1997-02-24 11:24:39 -08:00
|
|
|
|
|
|
|
external set : 'a t -> int -> 'a option -> unit = "weak_set";;
|
|
|
|
|
|
|
|
external get: 'a t -> int -> 'a option = "weak_get";;
|
|
|
|
|
2000-08-23 10:10:41 -07:00
|
|
|
external get_copy: 'a t -> int -> 'a option = "weak_get_copy";;
|
|
|
|
|
1998-11-13 15:42:11 -08:00
|
|
|
external check: 'a t -> int -> bool = "weak_check";;
|
|
|
|
|
1997-02-24 11:24:39 -08:00
|
|
|
let fill ar ofs len x =
|
2000-05-08 10:53:58 -07:00
|
|
|
if ofs < 0 || len < 0 || ofs + len > length ar
|
1997-02-24 11:24:39 -08:00
|
|
|
then raise (Invalid_argument "Weak.fill")
|
|
|
|
else begin
|
|
|
|
for i = ofs to (ofs + len - 1) do
|
1997-03-08 04:14:57 -08:00
|
|
|
set ar i x
|
1997-02-24 11:24:39 -08:00
|
|
|
done
|
|
|
|
end
|
|
|
|
;;
|
|
|
|
|
|
|
|
let blit ar1 of1 ar2 of2 len =
|
|
|
|
if of1 < 0 || of1 + len > length ar1 || of2 < 0 || of2 + len > length ar2
|
|
|
|
then raise (Invalid_argument "Weak.blit")
|
|
|
|
else begin
|
|
|
|
if of2 > of1 then begin
|
|
|
|
for i = 0 to len - 1 do
|
1997-03-08 04:14:57 -08:00
|
|
|
set ar2 (of2 + i) (get ar1 (of1 + i))
|
1997-02-24 11:24:39 -08:00
|
|
|
done
|
|
|
|
end else begin
|
|
|
|
for i = len - 1 downto 0 do
|
1997-03-08 04:14:57 -08:00
|
|
|
set ar2 (of2 + i) (get ar1 (of1 + i))
|
1997-02-24 11:24:39 -08:00
|
|
|
done
|
|
|
|
end
|
|
|
|
end
|
|
|
|
;;
|