bottom up run works for text nodes
[SXSI/xpathcomp.git] / OCamlDriver.cpp
index 8603c11..78d3e15 100644 (file)
@@ -16,9 +16,28 @@ extern "C" {
 #include <caml/callback.h>
 #include <caml/fail.h>
 #include <caml/custom.h>
+
+
+#include <unistd.h>
+#include <sys/times.h>
+#include <time.h>
+#include <sys/stat.h>
+
+  struct tms t1;
+  struct tms t2;
+  double ticks = (double) sysconf(_SC_CLK_TCK)/1000;
   
+  void start_clock() {
+    times (&t1);
+  }
+
+
+  double stop_clock() {
+    times (&t2);
+    return (t2.tms_utime-t1.tms_utime)/ticks;
+  }
+} //extern C  
 
-} //extern C
 
 //#include "TextCollection/TextCollection.h"
 #include "XMLDocShredder.h"
@@ -146,14 +165,6 @@ extern "C" CAMLprim value caml_text_collection_get_cached_text(value tree, value
   CAMLreturn (str);
 }
 
-extern "C" CAMLprim value caml_text_collection_size(value tree){
-  CAMLparam1(tree);
-  //  CAMLreturn (Val_int( XMLTREE(tree)->CachedText.size()));
-  NOT_IMPLEMENTED("text_collection_size");
-  CAMLreturn (Val_unit);
-}
-
-
 
 extern "C" CAMLprim value caml_text_collection_empty_text(value tree,value id){
   CAMLparam2(tree,id);
@@ -194,6 +205,16 @@ extern "C" CAMLprim value caml_text_collection_contains(value tree,value str){
   };
   CAMLreturn (resarray);  
 }
+extern "C" CAMLprim value caml_text_collection_unsorted_contains(value tree,value str){
+  CAMLparam2(tree,str);
+  uchar * cstr = (uchar *) String_val(str);  
+  std::vector<DocID> results;
+  start_clock();
+  results = XMLTREE(tree)->Contains(cstr);
+  double d = stop_clock();
+  std::cerr << "Internal timing " << d <<" ms\n";
+  CAMLreturn (Val_unit);  
+}
 
 
 extern "C" CAMLprim value caml_xml_tree_root(value tree){
@@ -240,6 +261,15 @@ extern "C" CAMLprim value caml_xml_tree_unserialize(value filename){
   CAMLreturn(Val_unit);
 }
 
+extern "C" CAMLprim value caml_xml_tree_last_child(value tree, value id){
+  CAMLparam2(tree,id);
+  CAMLreturn(Val_int (XMLTREE(tree)->LastChild(TREENODEVAL(id))));
+}
+
+extern "C" CAMLprim value caml_xml_tree_is_first_child(value tree, value id){
+  CAMLparam2(tree,id);
+  CAMLreturn(Val_bool (XMLTREE(tree)->IsFirstChild(TREENODEVAL(id))));
+}
 
 extern "C" CAMLprim value caml_xml_tree_first_child(value tree, value id){
   CAMLparam2(tree,id);
@@ -274,9 +304,7 @@ extern "C" CAMLprim value caml_xml_tree_next_sibling(value tree, value id){
 
 extern "C" CAMLprim value caml_xml_tree_prev_text(value tree, value id){
   CAMLparam2(tree,id);
-  CAMLlocal1(res);
   CAMLreturn(Val_int((XMLTREE(tree)->PrevText(TREENODEVAL(id)))));
-  CAMLreturn(res);
 }
 extern "C" CAMLprim value caml_xml_tree_next_text(value tree, value id){
   CAMLparam2(tree,id);