summaryrefslogtreecommitdiff
path: root/stdlib/weak.ml
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>1997-02-24 19:24:39 +0000
committerDamien Doligez <damien.doligez-inria.fr>1997-02-24 19:24:39 +0000
commitbb761824333f00a4387ec27100c22aad9ca9f8f9 (patch)
tree57e14a6434602c19a0b20df546556296ad5f040f /stdlib/weak.ml
parenta51911df34e20ef6ed4b67bcb788de5db0babc58 (diff)
downloadocaml-bb761824333f00a4387ec27100c22aad9ca9f8f9.tar.gz
ajout Weak
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1291 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'stdlib/weak.ml')
-rw-r--r--stdlib/weak.ml52
1 files changed, 52 insertions, 0 deletions
diff --git a/stdlib/weak.ml b/stdlib/weak.ml
new file mode 100644
index 0000000000..6b3ed6ea33
--- /dev/null
+++ b/stdlib/weak.ml
@@ -0,0 +1,52 @@
+(***********************************************************************)
+(* *)
+(* Objective Caml *)
+(* *)
+(* Damien Doligez, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* Automatique. Distributed only by permission. *)
+(* *)
+(***********************************************************************)
+
+(* $Id$ *)
+
+(* Weak array operations *)
+
+(* WARNING: the following declaration is not type-safe. *)
+
+type 'a t = 'a array;;
+
+external create: int -> 'a t = "weak_create";;
+
+let length x = Array.length x - 1;;
+
+external set : 'a t -> int -> 'a option -> unit = "weak_set";;
+
+external get: 'a t -> int -> 'a option = "weak_get";;
+
+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
+ set ar i x;
+ 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
+ set ar2 (of2 + i) (get ar1 (of1 + i));
+ done
+ end else begin
+ for i = len - 1 downto 0 do
+ set ar2 (of2 + i) (get ar1 (of1 + i));
+ done
+ end
+ end
+;;