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 *)
|
1997-02-24 11:24:39 -08:00
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $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";;
|
|
|
|
|
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 =
|
|
|
|
if ofs < 0 || ofs + len > length ar
|
|
|
|
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
|
|
|
|
;;
|