Hardcode "<@>" and "<$>" at position 0 and 1 in the TagName table.
authorkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Wed, 28 Jan 2009 00:06:34 +0000 (00:06 +0000)
committerkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Wed, 28 Jan 2009 00:06:34 +0000 (00:06 +0000)
These are used to denote attributes and PCDATA nodes.

git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@81 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

XMLTree.cpp
XMLTree.h

index 22ba4bb..fe01896 100644 (file)
@@ -574,9 +574,10 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text)
  {\r
     initialized = true;\r
     finished = false;\r
+    found_attributes = false;\r
     npar = 0;\r
     parArraySize = 1;\r
-    ntagnames = 0;    \r
+    ntagnames = 2;    \r
  \r
     indexing_empty_texts = empty_texts;\r
     \r
@@ -592,7 +593,28 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text)
        return NULLT;\r
     }\r
     \r
-    TagName = NULL;\r
+    TagName = (unsigned char **) malloc(2*sizeof(unsigned char*));\r
+    if (!TagName){\r
+       fprintf(stderr, "Error: not enough memory\n");\r
+       return NULLT;\r
+    }\r
+\r
+    TagName[0] = (unsigned char *) malloc(4*sizeof(unsigned char));\r
+    strcpy((char *) TagName[0], "<@>");\r
+\r
+    if (!TagName[0]){\r
+      fprintf(stderr, "Error: not enough memory\n");\r
+      return NULLT;\r
+    }\r
+\r
+    TagName[1] = (unsigned char *) malloc(4*sizeof(unsigned char));\r
+    if (!TagName[1]){\r
+      fprintf(stderr, "Error: not enough memory\n");\r
+      return NULLT;\r
+    }\r
+\r
+    strcpy((char *) TagName[1], "<$>");\r
+\r
 \r
     if (!indexing_empty_texts) {\r
        empty_texts_aux = (unsigned int *)malloc(sizeof(unsigned int));\r
@@ -633,7 +655,12 @@ int XMLTree::CloseDocument()
     static_permutation_builder * pmb = new static_permutation_builder_mrrr(PERM_SAMPLE, bmb);\r
     static_sequence_builder * ssb = new static_sequence_builder_gmr_chunk(bmb, pmb);\r
 \r
-    Tags = new static_sequence_gmr((uint *) tags_aux, (uint) npar-1,2*ntagnames, bmb, ssb);\r
+\r
+    // If we found an attribute then "<@>" is present in the tree\r
+    // if we didn't then it is not. "<$>" is never present in the tree\r
+    int ntagsize = found_attributes ? 2*ntagnames-1 : 2*ntagnames - 2;\r
+\r
+    Tags = new static_sequence_gmr((uint *) tags_aux, (uint) npar-1,ntagsize, bmb, ssb);\r
     \r
     delete bmb;\r
     delete pmb;\r
@@ -679,8 +706,13 @@ int XMLTree::NewOpenTag(unsigned char *tagname)
     // transforms the tagname into a tag identifier. If the tag is new, we insert\r
     // it in the table.\r
     for (i=0; i<ntagnames; i++)\r
-       if (strcmp((const char *)tagname,(const char *)TagName[i])==0) break;\r
+      if (strcmp((const char *)tagname,(const char *)TagName[i])==0) break;\r
  \r
+\r
+    // NewOpenTag("<@>") was called\r
+    if (i==0) \r
+      found_attributes=true;\r
+\r
     if (i==ntagnames) { // the tag is a new one, then we insert it\r
        TagName = (unsigned char **)realloc(TagName, sizeof(char *)*(ntagnames+1));\r
        \r
index 88aae9a..cc5f089 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
@@ -90,6 +90,7 @@ class XMLTree {
    int parArraySize;\r
    int ntagnames;\r
    unsigned int *empty_texts_aux;\r
+   bool found_attributes;\r
    \r
 public:\r
 \r