X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=OCamlDriver.cpp;h=03f06d5dbe1ba42ec56fb824534e1e74c30409f7;hb=bf2b1a91300ace1e7e83bd78f868a269d86498f9;hp=c10edf11fe3d7f03abc181110f3983a776e24381;hpb=cad5e2e2831477cba1f6211c57b9a4cc5b58bd55;p=SXSI%2Fxpathcomp.git diff --git a/OCamlDriver.cpp b/OCamlDriver.cpp index c10edf1..03f06d5 100644 --- a/OCamlDriver.cpp +++ b/OCamlDriver.cpp @@ -255,13 +255,14 @@ extern "C" value caml_text_collection_count_lessthan(value tree,value str){ } static value sort_alloc_array(std::vector results, value resarray){ - std::sort(results.begin(), results.end(), docId_comp); + std::sort(results.begin(), results.end(), docId_comp); size_t s = results.size(); resarray = caml_alloc_tuple(s); for (size_t i = 0; i < s ;i++){ caml_initialize(&Field(resarray,i),Val_int(results[i])); }; - return resarray; + return resarray; + } /** @@ -769,34 +770,115 @@ extern "C" value caml_bit_vector_node_array(value vect){ } -void iterjump(XMLTree* tree, treeNode node, TagType tag){ +int iterjump(XMLTree* tree, treeNode node, TagType tag, treeNode anc){ if (node == NULLT) - return; + return 0; else { - iterjump(tree,tree->TaggedDescendant(node,tag),tag); - iterjump(tree,tree->TaggedFollowing(node,tag),tag); - return; + return /*1+iterjump(tree,tree->TaggedDescendant(node,tag),tag,node) + +*/ iterjump(tree,tree->TaggedFollowingBelow(node,tag,anc),tag,anc); }; } extern "C" value caml_benchmark_jump(value tree,value tag){ - iterjump(XMLTREE(tree),0, Int_val(tag)); + int count; + treeNode root = XMLTREE(tree)->FirstChild(0); + root = XMLTREE(tree)->FirstChild(root); + count = iterjump(XMLTREE(tree), root , Int_val(tag),0); + return Val_unit; +} + +int iterfcns(XMLTree* tree, treeNode node){ + if (node == NULLT) + return 0; + else { + int tmp = iterfcns(tree,tree->FirstElement(node)); + tmp += iterfcns(tree,tree->NextElement(node)); + return tmp+1; + }; +} + +extern "C" value caml_benchmark_fcns(value tree){ + int i = iterfcns(XMLTREE(tree),0); return Val_unit; + } -int iterfsns(XMLTree* tree, treeNode node){ +int iterlcps(XMLTree* tree, treeNode node){ if (node == NULLT) return 0; else { int x = tree->Tag(node); - x += iterfsns(tree,tree->FirstChild(node)); - x += iterfsns(tree,tree->NextSibling(node)); + x += iterlcps(tree,tree->LastChild(node)); + x += iterlcps(tree,tree->PrevSibling(node)); return x; }; } -extern "C" value caml_benchmark_fsns(value tree){ - iterfsns(XMLTREE(tree),0); +extern "C" value caml_benchmark_lcps(value tree){ + iterlcps(XMLTREE(tree),0); return Val_unit; } + +extern "C" { + + typedef struct dummy_node_ { + struct dummy_node_* first; + struct dummy_node_* next; + } dummy_node; + + + dummy_node * new_dummy_node () { + + dummy_node * node = (dummy_node*) malloc(sizeof(dummy_node)); + if (!node) + printf("%s","Cannot allocate memory\n"); + + return node; + } + + void free_tree(dummy_node * node){ + if (node){ + free_tree(node->first); + free_tree(node->next); + free(node); + }; + return; + } + + dummy_node * create_tree(XMLTree* tree, treeNode i){ + if (i == NULLT) + return NULL; + else { + dummy_node * f, *n, *r; + f = create_tree(tree,tree->FirstChild(i)); + n = create_tree(tree,tree->NextSibling(i)); + r = new_dummy_node(); + r->first = f; + r->next = n; + return r; + }; + } + + int iter_tree(dummy_node * n){ + if (n == NULL) + return 0; + else { + return (1+ iter_tree(n->next)+ iter_tree(n->first) ); + }; + } + +} +extern "C" value caml_build_pointers(value tree){ + return ((value) create_tree(XMLTREE(Field(tree,0)),0)); +} + +extern "C" value caml_iter_pointers (value node){ + return Val_int(iter_tree((dummy_node*) node)); + +} + +extern "C" value caml_free_pointers(value node){ + free_tree((dummy_node*) node); + return Val_unit; +}