Rename 'Tracer' module to 'Logger'.
[SXSI/xpathcomp.git] / src / cache.ml
index 3efe3dc..68cae67 100644 (file)
@@ -1,4 +1,3 @@
-INCLUDE "trace.ml"
 
 let realloc l old_size new_size dummy =
   let l' = Array.create new_size dummy in
@@ -20,6 +19,14 @@ struct
 
   }
 
+  let print fmt a =
+    Format.fprintf fmt "{ offset=%i;\n dummy=_;line=%a \n}\n%!"
+      a.offset
+      (Pretty.print_array ~sep:", " (fun fmt x ->
+       if x==a.dummy then
+         Format.fprintf fmt "%s" "D"
+       else
+         Format.fprintf fmt "%s" "E")) a.line
 
   let add a i v =
     if a.offset == ~-1 then a.offset <- i;
@@ -45,7 +52,7 @@ struct
        for j = 0 to len - 1 do
          narray.(j) <- a.line.(j);
        done;
-       narray.(i - offset + 1) <- v;
+       narray.(i - offset) <- v;
        a.line <- narray
       end
 
@@ -84,12 +91,13 @@ struct
   let add a i j v =
     let line = Lvl1.find a i in
     if line == a.Lvl1.dummy then
-      let nline =  { line with Lvl1.offset = ~-1 } in
-      Lvl1.add nline j v;
-      Lvl1.add a i nline
+      let nline = Lvl1.create 0 line.Lvl1.dummy in
+      Lvl1.add a i nline;
+      Lvl1.add nline j v
     else
       Lvl1.add line j v
 
+
   let find a i j =
     let v = Lvl1.find a i in
     if v == a.Lvl1.dummy then a.Lvl1.dummy.Lvl1.dummy
@@ -113,7 +121,7 @@ struct
   type 'a t = 'a Lvl2.t Lvl1.t
 
   let create n a =
-  let dummy1 = Lvl2.create 0 a in
+  let dummy1 = Lvl2.create 512 a in
     { Lvl1.line = Array.create n dummy1;
       Lvl1.offset = ~-1;
       Lvl1.dummy = dummy1;