X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Fcache.ml;h=60301fe758dd310006e4bc2b0be95cc52830ddd7;hb=ecec752325cb3d207894a4f8d772936bd7ad9f4a;hp=3efe3dcde325bffb73eb0fa97a9db9385d5ab4b1;hpb=db0ad408721f202e33785958211fe6e4228fce8f;p=SXSI%2Fxpathcomp.git diff --git a/src/cache.ml b/src/cache.ml index 3efe3dc..60301fe 100644 --- a/src/cache.ml +++ b/src/cache.ml @@ -20,11 +20,21 @@ 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 = + TRACE("twopass", 2, __ "Before add (%i): %a\n%!" i print a); if a.offset == ~-1 then a.offset <- i; let offset = a.offset in let len = Array.length a.line in + let () = if i >= offset && i < offset + len then a.line.(i - offset) <- v else @@ -45,9 +55,11 @@ 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 + in + TRACE("twopass", 2, __ "After add (%i): %a\n%!" i print a) let find a i = let offset = a.offset in @@ -82,11 +94,13 @@ struct let add a i j v = + TRACE("twopass", 2, __ "Adding %i %i\n%!" i j); 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 + TRACE("twopass", 2, __ "Reallocating\n%!"); + Lvl1.add a i nline; + Lvl1.add nline j v else Lvl1.add line j v @@ -113,7 +127,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;