.
[SXSI/xpathcomp.git] / timeXMLTree.cpp
index aef9731..ed721cd 100644 (file)
@@ -11,6 +11,9 @@ using std::right;
 
 static clock_t tFirstChild = 0;
 static clock_t tNextSibling = 0;
+static clock_t tParent = 0;
+static clock_t tTaggedAncestor = 0;
+static clock_t tTaggedChild = 0;
 static clock_t tTaggedDesc = 0;
 static clock_t tTaggedFoll = 0;
 static clock_t tParentNode = 0;
@@ -19,11 +22,16 @@ static clock_t tTag = 0;
 static clock_t tMyText = 0;
 static clock_t tPrevText = 0;
 static clock_t tNextText = 0;
+static clock_t tDocIds = 0;
+
 static clock_t tFullTraversal = 0;
 static clock_t tJumpTraversal = 0;
 
 static unsigned int cFirstChild = 0;
 static unsigned int cNextSibling = 0;
+static unsigned int cParent = 0;
+static unsigned int cTaggedAncestor = 0;
+static unsigned int cTaggedChild = 0;
 static unsigned int cTaggedDesc = 0;
 static unsigned int cTaggedFoll = 0;
 static unsigned int cParentNode = 0;
@@ -32,9 +40,13 @@ static unsigned int cTag = 0;
 static unsigned int cMyText = 0;
 static unsigned int cPrevText = 0;
 static unsigned int cNextText = 0;
+static unsigned int cDocIds = 0;
+
 static unsigned int cFullTraversal = 0;
 static unsigned int cJumpTraversal = 0;
 
+
+
 static clock_t tmp;
 
 static TagType target_tag = -1;
@@ -42,7 +54,7 @@ static TagType target_tag = -1;
 #define STARTTIMER()   (tmp= clock())
 #define STOPTIMER(x)   do {  (t##x) = (t##x) + (clock() - tmp); (c##x)= (c##x)+1;  } while (0)
 #define PRINTSTATS(x)  do {                                            \
-    std::cout.width(11);                                               \
+    std::cout.width(15);                                               \
     std::cout << std::left << #x;                                      \
     std::cout << " : ";                                                        \
     std::cout.width(8);                                                        \
@@ -63,8 +75,10 @@ void traversal(XMLTree * tree, treeNode node,unsigned char* targettagname){
   treeNode res1,res2;
   TagType tag;
   DocID id1,id2,id3;
+  range rg;
   const unsigned char * tagname;
   if (node != NULLT){
+
     STARTTIMER();
     tag = tree->Tag(node);
     STOPTIMER(Tag);
@@ -74,12 +88,28 @@ void traversal(XMLTree * tree, treeNode node,unsigned char* targettagname){
        target_tag = tag;
     };
     STARTTIMER();
+    res1 = tree->Parent(node);
+    STOPTIMER(Parent);
+    /*
+    STARTTIMER();
+    res1 = tree->TaggedChild(node,0,tag);
+    STOPTIMER(TaggedChild);
+
+    STARTTIMER();
+    res1 = tree->TaggedAncestor(node,tag);
+    STOPTIMER(TaggedAncestor);
+    */
+    STARTTIMER();
     res1 = tree->TaggedDesc(node,tag);
     STOPTIMER(TaggedDesc);
 
     STARTTIMER();
     res1 = tree->TaggedFoll(node,tag);
     STOPTIMER(TaggedFoll);
+    
+    STARTTIMER();
+    rg = tree->DocIds(node);
+    STOPTIMER(DocIds);
 
     STARTTIMER();
     id1 = tree->MyText(node);
@@ -110,6 +140,7 @@ void traversal(XMLTree * tree, treeNode node,unsigned char* targettagname){
     STARTTIMER();
     res2 = tree->NextSibling(node);
     STOPTIMER(NextSibling);
+
     traversal(tree,res1,targettagname);
     traversal(tree,res2,targettagname);
     
@@ -117,40 +148,44 @@ void traversal(XMLTree * tree, treeNode node,unsigned char* targettagname){
   
 }
 
-unsigned int time_traversal(XMLTree *tree,treeNode node,unsigned int count){
+/* This simulates the run function of the automata */
+
+unsigned int time_traversal(XMLTree *tree,treeNode node){
   TagType tag;
   if (node != NULLT) {
     cFullTraversal++;
     tag = tree->Tag(node);
-    if (tag == target_tag)
-      count = count + 1;
-    return time_traversal(tree,tree->NextSibling(node), 
-                         time_traversal(tree,tree->FirstChild(node),count));
+    if (tag == target_tag)      
+      return 1 + 
+       time_traversal(tree,tree->FirstChild(node)) +
+       time_traversal(tree,tree->NextSibling(node)); 
+    else
+      return time_traversal(tree,tree->FirstChild(node)) +
+       time_traversal(tree,tree->NextSibling(node));
 
   }
   else 
-    return count;
+    return 0;
 }
 
-
-unsigned int time_jump(XMLTree* tree, treeNode node,unsigned int count,treeNode root){
+/* This simulates the run function of the jumping automata*/
+unsigned int time_jump(XMLTree* tree, treeNode node,treeNode root){
   TagType tag;
   if (node != NULLT) {
     cJumpTraversal++;
     tag = tree->Tag(node);
     if (tag == target_tag)
-      count = count + 1;
-    return time_jump(tree,
-                         tree->TaggedFollBelow(node,target_tag,root), 
-                         time_jump(tree,
-                                   tree->TaggedDesc(node,target_tag),
-                                   count,
-                                   node),
-                    root);
-    
+
+      return 1 + 
+       time_jump(tree, tree->TaggedDesc(node,target_tag),node) +
+       time_jump(tree, tree->TaggedFollBelow(node,target_tag,root),  root);
+
+    else
+      return time_jump(tree, tree->TaggedDesc(node,target_tag),node) +
+       time_jump(tree, tree->TaggedFollBelow(node,target_tag,root),  root);
   }
   else 
-    return count;
+    return 0;
 }
 
 
@@ -172,15 +207,19 @@ int main(int argc, char ** argv){
   traversal(tree,tree->Root(),tagname);
 
   STARTTIMER();
-  count1 = time_traversal(tree,tree->Root(),0);
+  count1 = time_traversal(tree,tree->Root());
   STOPTIMER(FullTraversal);
 
-  count2 = time_jump(tree,tree->Root(),0,tree->Root());
+  count2 = time_jump(tree,tree->Root(),tree->Root());
   STOPTIMER(JumpTraversal);
-  
+
+  PRINTSTATS(Tag);
   PRINTSTATS(FirstChild);
   PRINTSTATS(NextSibling);
-  PRINTSTATS(Tag);
+  PRINTSTATS(Parent);
+  PRINTSTATS(TaggedAncestor);
+  PRINTSTATS(TaggedChild);
+  PRINTSTATS(DocIds);
   PRINTSTATS(TaggedDesc);
   PRINTSTATS(TaggedFoll);
   PRINTSTATS(PrevText);