X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Fcache.ml;h=68cae6760c9cf2cf6f6f2371004130a8043640f8;hb=823e05eb9a6629e6dc89aac333af8724dc37139a;hp=d65df68d1a2682092c9df13ec0a227f58439a3e8;hpb=d7c0e0d3ae22f01c69f0352a25db3eaaab02406f;p=SXSI%2Fxpathcomp.git diff --git a/src/cache.ml b/src/cache.ml index d65df68..68cae67 100644 --- a/src/cache.ml +++ b/src/cache.ml @@ -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 @@ -57,6 +64,15 @@ struct let dummy a = a.dummy + let iteri f a = + let line = a.line in + if a.offset == ~-1 then () else + for i = 0 to Array.length line - 1 do + let v = line.(i) in + f (i+a.offset) v (v==a.dummy) + done + + end @@ -75,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 @@ -89,6 +106,14 @@ struct let dummy c = c.Lvl1.dummy.Lvl1.dummy + let iteri f a = + let line = a.Lvl1.line in + if a.Lvl1.offset == ~-1 then () else + for i = 0 to Array.length line - 1 do + Lvl1.iteri (f i) line.(i) + done + + end module Lvl3 = @@ -96,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; @@ -118,5 +143,11 @@ struct let dummy a = Lvl2.dummy a.Lvl1.dummy + let iteri f a = + let line = a.Lvl1.line in + if a.Lvl1.offset == ~-1 then () else + for i = 0 to Array.length line - 1 do + Lvl2.iteri (f i) line.(i) + done end