projects
/
SXSI
/
XMLTree.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed error: Syscall param write(buf) points to uninitialised byte(s)
[SXSI/XMLTree.git]
/
XMLTree.cpp
diff --git
a/XMLTree.cpp
b/XMLTree.cpp
index
2a1ca71
..
249143c
100644
(file)
--- a/
XMLTree.cpp
+++ b/
XMLTree.cpp
@@
-212,19
+212,18
@@
XMLTree *XMLTree::Load(unsigned char *filename, int sample_rate_text)
s_tree+= XML_Tree->Tags->size();
\r
\r
/// FIXME:UGLY tests!
\r
s_tree+= XML_Tree->Tags->size();
\r
\r
/// FIXME:UGLY tests!
\r
-
/*
uint * seq = new uint[XML_Tree->tags_len];
\r
+ uint * seq = new uint[XML_Tree->tags_len];
\r
for(uint i=0;i<XML_Tree->tags_len;i++)
\r
seq[i] = get_field(XML_Tree->tags_fix,XML_Tree->tags_blen,i);
\r
cout << "Tags test: " << XML_Tree->Tags->test(seq,XML_Tree->tags_len) << endl;
\r
for(uint i=0;i<XML_Tree->tags_len;i++)
\r
seq[i] = get_field(XML_Tree->tags_fix,XML_Tree->tags_blen,i);
\r
cout << "Tags test: " << XML_Tree->Tags->test(seq,XML_Tree->tags_len) << endl;
\r
- delete [] seq;
*/
\r
+ delete [] seq;
\r
/// End ugly tests
\r
\r
s_text = ftell(fp);
\r
\r
// loads the texts
\r
if (!XML_Tree->disable_tc){
\r
/// End ugly tests
\r
\r
s_text = ftell(fp);
\r
\r
// loads the texts
\r
if (!XML_Tree->disable_tc){
\r
- XML_Tree->Text = TextCollection::InitTextCollection(sample_rate_text);
\r
- XML_Tree->Text->Load(fp,sample_rate_text);
\r
+ XML_Tree->Text = TextCollection::Load(fp,sample_rate_text);
\r
int sst;
\r
int st;
\r
ufread(&sst, sizeof(int),1,fp);
\r
int sst;
\r
int st;
\r
ufread(&sst, sizeof(int),1,fp);
\r
@@
-284,7
+283,9
@@
XMLTree::~XMLTree()
Tags = NULL;
\r
\r
//Text->~TextCollection();
\r
Tags = NULL;
\r
\r
//Text->~TextCollection();
\r
- delete Text;
\r
+ delete TextBuilder;
\r
+ TextBuilder = NULL;
\r
+ delete Text;
\r
Text = NULL;
\r
\r
initialized = false;
\r
Text = NULL;
\r
\r
initialized = false;
\r
@@
-356,7
+357,9
@@
bool XMLTree::IsChild(treeNode x, treeNode y)
if (!is_ancestor(Par, x, y)) return false;
\r
return depth(Par, x) == (depth(Par, y) + 1);
\r
}
\r
if (!is_ancestor(Par, x, y)) return false;
\r
return depth(Par, x) == (depth(Par, y) + 1);
\r
}
\r
-
\r
+bool XMLTree::IsFirstChild(treeNode x){
\r
+ return ((x != NULLT)&&(x==Root() || prev_sibling(Par,x) == NULLT));
\r
+}
\r
// NumChildren(x): number of children of node x. Constant time with the data structure
\r
// of Sadakane.
\r
int XMLTree::NumChildren(treeNode x)
\r
// NumChildren(x): number of children of node x. Constant time with the data structure
\r
// of Sadakane.
\r
int XMLTree::NumChildren(treeNode x)
\r
@@
-498,6
+501,14
@@
treeNode XMLTree::FirstChild(treeNode x)
return first_child(Par, x);
\r
}
\r
\r
return first_child(Par, x);
\r
}
\r
\r
+treeNode XMLTree::LastChild(treeNode x)
\r
+{
\r
+ if (x == Root() || isleaf(Par,x) || x == NULLT)
\r
+ return x;
\r
+ else
\r
+ return find_open(Par,find_close(Par,parent(Par,x))-1);
\r
+}
\r
+
\r
// NextSibling(x): returns the next sibling of node x, assuming it exists.
\r
treeNode XMLTree::NextSibling(treeNode x)
\r
{
\r
// NextSibling(x): returns the next sibling of node x, assuming it exists.
\r
treeNode XMLTree::NextSibling(treeNode x)
\r
{
\r
@@
-1013,9
+1024,11
@@
int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text,bool dtc)
if (!indexing_empty_texts)
\r
empty_texts_aux = (unsigned int *)umalloc(sizeof(unsigned int));
\r
\r
if (!indexing_empty_texts)
\r
empty_texts_aux = (unsigned int *)umalloc(sizeof(unsigned int));
\r
\r
-
\r
-
\r
- Text = TextCollection::InitTextCollection((unsigned)sample_rate_text);
\r
+ if (disable_tc)
\r
+ TextBuilder = 0;
\r
+ else
\r
+ TextBuilder = new TextCollectionBuilder((unsigned)sample_rate_text);
\r
+ Text = 0;
\r
\r
return 1; // indicates success in the initialization of the data structure
\r
}
\r
\r
return 1; // indicates success in the initialization of the data structure
\r
}
\r
@@
-1044,9
+1057,9
@@
int XMLTree::CloseDocument()
uint max_tag = 0;
\r
for(uint i=0;i<(uint)npar-1;i++)
\r
max_tag = max(max_tag,tags_aux[i]);
\r
uint max_tag = 0;
\r
for(uint i=0;i<(uint)npar-1;i++)
\r
max_tag = max(max_tag,tags_aux[i]);
\r
- max_tag++;
\r
- tags_aux = (TagType *) urealloc(tags_aux, sizeof(TagType)*(npar + 1));
\r
- tags_aux[npar++] = max_tag;
\r
+
//
max_tag++;
\r
+
//
tags_aux = (TagType *) urealloc(tags_aux, sizeof(TagType)*(npar + 1));
\r
+
//
tags_aux[npar++] = max_tag;
\r
//int ntagsize = found_attributes ? 2*ntagnames-1 : 2*ntagnames - 2;
\r
int ntagsize = 2*ntagnames + 2;
\r
\r
//int ntagsize = found_attributes ? 2*ntagnames-1 : 2*ntagnames - 2;
\r
int ntagsize = 2*ntagnames + 2;
\r
\r
@@
-1073,10
+1086,16
@@
int XMLTree::CloseDocument()
//delete ssb;
\r
\r
\r
//delete ssb;
\r
\r
\r
-
// makes the text collection static
\r
+ // makes the text collection static
\r
if (!disable_tc)
\r
if (!disable_tc)
\r
- Text->MakeStatic();
\r
-
\r
+ {
\r
+ assert(Text == 0);
\r
+ assert(TextBuilder != 0);
\r
+ Text = TextBuilder->InitTextCollection();
\r
+ delete TextBuilder;
\r
+ TextBuilder = 0;
\r
+ }
\r
+
\r
// creates the data structure marking the non-empty texts (just in the case it is necessary)
\r
if (!indexing_empty_texts) {
\r
EBVector = new static_bitsequence_rrr02((uint *)empty_texts_aux,(ulong)npar,(uint)32);
\r
// creates the data structure marking the non-empty texts (just in the case it is necessary)
\r
if (!indexing_empty_texts) {
\r
EBVector = new static_bitsequence_rrr02((uint *)empty_texts_aux,(ulong)npar,(uint)32);
\r
@@
-1214,7
+1233,7
@@
int XMLTree::NewText(unsigned char *s)
bitset(empty_texts_aux, npar-1); // marks the non-empty text with a 1 in the bit vector
\r
}
\r
\r
bitset(empty_texts_aux, npar-1); // marks the non-empty text with a 1 in the bit vector
\r
}
\r
\r
- Text->InsertText(s);
\r
+ Text
Builder
->InsertText(s);
\r
string cpps = (char*) s;
\r
CachedText.push_back(cpps);
\r
\r
string cpps = (char*) s;
\r
CachedText.push_back(cpps);
\r
\r
@@
-1239,7
+1258,7
@@
int XMLTree::NewEmptyText()
\r
bitclean(empty_texts_aux, npar-1); // marks the empty text with a 0 in the bit vector
\r
}
\r
\r
bitclean(empty_texts_aux, npar-1); // marks the empty text with a 0 in the bit vector
\r
}
\r
- else Text->InsertText(&c); // we insert the empty text just in case we index all the texts
\r
+ else Text
Builder
->InsertText(&c); // we insert the empty text just in case we index all the texts
\r
\r
return 1; // success
\r
}
\r
\r
return 1; // success
\r
}
\r
@@
-1253,7
+1272,7
@@
TagType XMLTree::GetTagId(unsigned char *tagname)
// this should be changed for more efficient processing
\r
for (i=0; i<ntagnames; i++)
\r
if (strcmp((const char *)tagname,(const char *)TagName[i])==0) break;
\r
// this should be changed for more efficient processing
\r
for (i=0; i<ntagnames; i++)
\r
if (strcmp((const char *)tagname,(const char *)TagName[i])==0) break;
\r
- if (i==ntagnames) return ntagnames; //(TagType)NULLT; // tagname does not exists in the table
\r
+ if (i==ntagnames) return
(TagType)-1; //
ntagnames; //(TagType)NULLT; // tagname does not exists in the table
\r
else return i;
\r
}
\r
\r
else return i;
\r
}
\r
\r
@@
-1263,7
+1282,7
@@
TagType XMLTree::GetTagId(unsigned char *tagname)
unsigned char *XMLTree::GetTagName(TagType tagid)
\r
{
\r
unsigned char *s;
\r
unsigned char *XMLTree::GetTagName(TagType tagid)
\r
{
\r
unsigned char *s;
\r
-
\r
+ if(tagid==(uint)-1) return NULL;
\r
if (tagid >= ntagnames) return NULL; // invalid tag identifier
\r
s = (unsigned char *)umalloc((strlen((const char *)TagName[tagid])+1)*sizeof(unsigned char));
\r
strcpy((char *)s, (const char *)TagName[tagid]);
\r
if (tagid >= ntagnames) return NULL; // invalid tag identifier
\r
s = (unsigned char *)umalloc((strlen((const char *)TagName[tagid])+1)*sizeof(unsigned char));
\r
strcpy((char *)s, (const char *)TagName[tagid]);
\r
@@
-1275,6
+1294,7
@@
unsigned char *XMLTree::GetTagName(TagType tagid)
\r
const unsigned char *XMLTree::GetTagNameByRef(TagType tagid)
\r
{
\r
\r
const unsigned char *XMLTree::GetTagNameByRef(TagType tagid)
\r
{
\r
+ if(tagid==(uint)-1) return NULL;
\r
if (tagid >= ntagnames) return NULL; // invalid tag identifier
\r
return ((const unsigned char*) TagName[tagid]);
\r
}
\r
if (tagid >= ntagnames) return NULL; // invalid tag identifier
\r
return ((const unsigned char*) TagName[tagid]);
\r
}
\r