array.ml: changement a.(i) en get a i

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3100 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Damien Doligez 2000-04-17 15:15:59 +00:00
parent d31b28402c
commit 3568294679
2 changed files with 28 additions and 28 deletions

View File

@ -40,7 +40,7 @@ Native-code compiler:
- Better error message when linking incomplete/incorrectly ordered set
of .cmx files.
- Optimized scanning of global roots during GC, can reduce total running
time by up to 5% on GC-intensive programs.
time by up to 8% on GC-intensive programs.
Interactive toplevel:
- Better printing of exceptions, including arguments, when possible.
@ -52,7 +52,7 @@ Run-time system:
- Added support for "custom" heap blocks (heap blocks carrying
C functions for finalization, comparison, hashing, serialization
and deserialization).
- Support for finalization functions written in Caml.
- Support for finalisation functions written in Caml.
Standard library:
- New modules Int32, Int64, Nativeint for 32-bit, 64-bit and

View File

@ -177,48 +177,48 @@ let sort cmp a =
let i31 = i+i+i+1 in
let x = ref i31 in
if i31+2 < l then begin
if cmp a.(i31) a.(i31+1) < 0 then x := i31+1;
if cmp a.(!x) a.(i31+2) < 0 then x := i31+2;
if cmp (get a i31) (get a (i31+1)) < 0 then x := i31+1;
if cmp (get a !x) (get a (i31+2)) < 0 then x := i31+2;
!x
end else
if i31+1 < l && cmp a.(i31) a.(i31+1) < 0
if i31+1 < l && cmp (get a i31) (get a (i31+1)) < 0
then i31+1
else if i31 < l then i31 else raise (Bottom i)
in
let rec trickledown l i e =
let j = maxson l i in
if cmp a.(j) e > 0 then begin
a.(i) <- a.(j);
if cmp (get a j) e > 0 then begin
set a i (get a j);
trickledown l j e;
end else begin
a.(i) <- e;
set a i e;
end;
in
let rec trickle l i e = try trickledown l i e with Bottom i -> a.(i) <- e in
let rec trickle l i e = try trickledown l i e with Bottom i -> set a i e in
let rec bubbledown l i =
let j = maxson l i in
a.(i) <- a.(j);
set a i (get a j);
bubbledown l j;
in
let bubble l i = try bubbledown l i with Bottom i -> i in
let rec trickleup i e =
let father = (i - 1) / 3 in
assert (i <> father);
if cmp a.(father) e < 0 then begin
a.(i) <- a.(father);
if father > 0 then trickleup father e else a.(0) <- e;
if cmp (get a father) e < 0 then begin
set a i (get a father);
if father > 0 then trickleup father e else set a 0 e;
end else begin
a.(i) <- e;
set a i e;
end;
in
let l = length a in
for i = (l + 1) / 3 - 1 downto 0 do trickle l i a.(i); done;
for i = (l + 1) / 3 - 1 downto 0 do trickle l i (get a i); done;
for i = l - 1 downto 2 do
let e = a.(i) in
a.(i) <- a.(0);
let e = (get a i) in
set a i (get a 0);
trickleup (bubble i 0) e;
done;
if l > 1 then (let e = a.(1) in a.(1) <- a.(0); a.(0) <- e);
if l > 1 then (let e = (get a 1) in set a 1 (get a 0); set a 0 e);
;;
let cutoff = 5;;
@ -227,31 +227,31 @@ let stable_sort cmp a =
let src1r = src1ofs + src1len and src2r = src2ofs + src2len in
let rec loop i1 s1 i2 s2 d =
if cmp s1 s2 <= 0 then begin
dst.(d) <- s1;
set dst d s1;
let i1 = i1 + 1 in
if i1 < src1r then
loop i1 a.(i1) i2 s2 (d + 1)
loop i1 (get a i1) i2 s2 (d + 1)
else
blit src2 i2 dst (d + 1) (src2r - i2)
end else begin
dst.(d) <- s2;
set dst d s2;
let i2 = i2 + 1 in
if i2 < src2r then
loop i1 s1 i2 src2.(i2) (d + 1)
loop i1 s1 i2 (get src2 i2) (d + 1)
else
blit a i1 dst (d + 1) (src1r - i1)
end
in loop src1ofs a.(src1ofs) src2ofs src2.(src2ofs) dstofs;
in loop src1ofs (get a src1ofs) src2ofs (get src2 src2ofs) dstofs;
in
let isortto srcofs dst dstofs len =
for i = 0 to len - 1 do
let e = a.(srcofs + i) in
let e = (get a (srcofs + i)) in
let j = ref (dstofs + i - 1) in
while (!j >= dstofs && cmp dst.(!j) e > 0) do
dst.(!j + 1) <- dst.(!j);
while (!j >= dstofs && cmp (get dst !j) e > 0) do
set dst (!j + 1) (get dst !j);
decr j;
done;
dst.(!j + 1) <- e;
set dst (!j + 1) e;
done;
in
let rec sortto srcofs dst dstofs len =
@ -267,7 +267,7 @@ let stable_sort cmp a =
if l <= cutoff then isortto 0 a 0 l else begin
let l1 = l / 2 in
let l2 = l - l1 in
let t = make l2 a.(0) in
let t = make l2 (get a 0) in
sortto l1 t 0 l2;
sortto 0 a l2 l1;
merge l2 l1 t 0 l2 a 0;