X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=src%2Ftable.ml;fp=src%2Ftable.ml;h=f0e24ee1693a7da8004833aff549ae4a0581f6d0;hp=3d372eca395d5486d03342d0b6e717b432dcc2a8;hb=a7acc5b68cd4850b1bce020421087788a57b4eab;hpb=f0406bb418d8b742ffdb4b001ecd178f5b7d1271 diff --git a/src/table.ml b/src/table.ml index 3d372ec..f0e24ee 100644 --- a/src/table.ml +++ b/src/table.ml @@ -20,8 +20,41 @@ and query_tree = { } - - +module QTree = struct + type t = query_tree + let rec equal q1 q2 = + q1 == q2 || + (q1.id == q2.id && q1.id != -1) || + match q1.desc, q2.desc with + | Binop(op1,qt1,qt2),Binop(op2,qt3,qt4)-> op1==op2&& (equal qt1 qt3 && equal qt2 qt4) + + | Axis(a1,qt1),Axis(a2,qt2) -> compare_axis a1 a2 && equal qt1 qt2 + | Tag(t1,k1),Tag(t2,k2) -> t1==t2&& k1==k2 + | Dom,Dom | Start,Start -> true + | _,_ ->false + and compare_axis a1 a2 = + match a1,a2 with + Self ,Self | Attribute, Attribute | Child , Child | Parent , Parent + | FollowingSibling , FollowingSibling + | PrecedingSibling , PrecedingSibling + | Preceding , Preceding | Following , Following -> true + | Descendant b1, Descendant b2 -> b1==b2 + | Ancestor b1, Ancestor b2 -> b1==b2 + | _,_ -> false + + let rec hash q = + if q.hash != -1 then q.hash + else match q.desc with + Dom -> 1 + | Start -> 3 + | Tag(s,_) -> 5 + 17*QNameSet.hash s + | Axis(a,q) -> 7 + 17 * Hashtbl.hash a + 23* hash q + | Binop(op,q1,q2) -> 11 + 17* Hashtbl.hash op + 23* hash q1 + 27* hash q2 + +end + + +module QTreeHash = Hashtbl.Make(QTree)