summaryrefslogtreecommitdiffstats
path: root/src/triestring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/triestring.cpp')
-rw-r--r--src/triestring.cpp68
1 files changed, 34 insertions, 34 deletions
diff --git a/src/triestring.cpp b/src/triestring.cpp
index 3c74fb5..2e40b22 100644
--- a/src/triestring.cpp
+++ b/src/triestring.cpp
@@ -46,7 +46,7 @@ struct KMPLAYER_NO_EXPORT TrieNode {
char * str;
unsigned short length;
unsigned short ref_count;
- TrieNode * tqparent;
+ TrieNode * parent;
TrieNode * first_child;
TrieNode * next_sibling;
};
@@ -70,7 +70,7 @@ KDE_NO_CDTOR_EXPORT TrieNode::TrieNode (const char * s)
: str (s ? strdup (s) : 0L),
length (s ? strlen (s) : 0),
ref_count (1),
- tqparent (0L),
+ parent (0L),
first_child (0L),
next_sibling (0L) {}
@@ -81,7 +81,7 @@ KDE_NO_CDTOR_EXPORT TrieNode::~TrieNode () {
KDE_NO_EXPORT void TrieNode::unref () {
if (--ref_count <= 0 && !first_child)
- tqparent->removeChild (this);
+ parent->removeChild (this);
}
KDE_NO_EXPORT void TrieNode::removeChild (TrieNode * node) {
@@ -95,10 +95,10 @@ KDE_NO_EXPORT void TrieNode::removeChild (TrieNode * node) {
}
}
delete node;
- if (!tqparent)
+ if (!parent)
return;
if (!ref_count && !first_child)
- tqparent->removeChild (this); // can this happen ?
+ parent->removeChild (this); // can this happen ?
else if (!ref_count && !first_child->next_sibling) { // merge with child
char * tmp = first_child->str;
first_child->length = first_child->length + length;
@@ -106,12 +106,12 @@ KDE_NO_EXPORT void TrieNode::removeChild (TrieNode * node) {
strcpy (first_child->str, str);
strcat (first_child->str, tmp);
free (tmp);
- first_child->tqparent = tqparent;
+ first_child->parent = parent;
first_child->next_sibling = next_sibling;
- if (tqparent->first_child == this) {
- tqparent->first_child = first_child;
+ if (parent->first_child == this) {
+ parent->first_child = first_child;
} else {
- for (TrieNode *n = tqparent->first_child; n; n = n->next_sibling)
+ for (TrieNode *n = parent->first_child; n; n = n->next_sibling)
if (n->next_sibling == this) {
n->next_sibling = first_child;
break;
@@ -123,9 +123,9 @@ KDE_NO_EXPORT void TrieNode::removeChild (TrieNode * node) {
static char * trieRetrieveString (TrieNode * node, int &len) {
char *buf;
- if (node->tqparent) {
+ if (node->parent) {
len += node->length;
- buf = trieRetrieveString (node->tqparent, len);
+ buf = trieRetrieveString (node->parent, len);
strcat (buf, node->str);
} else {
buf = (char *) malloc (len + 1);
@@ -138,8 +138,8 @@ static int trieStringCompare (TrieNode * node, const char * s, int &len) {
int cmp = 0;
if (!node)
return !!s;
- if (node->tqparent && node->tqparent != root_trie)
- cmp = trieStringCompare (node->tqparent, s, len);
+ if (node->parent && node->parent != root_trie)
+ cmp = trieStringCompare (node->parent, s, len);
if (!cmp) {
#ifdef TEST_TRIE
printf( "compare %s %s %d\n", node->str, s + len, node->length);
@@ -153,8 +153,8 @@ static int trieStringCompare (TrieNode * node, const char * s, int &len) {
static int trieStringCompare (TrieNode * n1, TrieNode * n2) {
// pre n1 && n2 on same depth and not NIL
int cmp = 0;
- if (n1->tqparent && n1->tqparent != root_trie)
- cmp = trieStringCompare (n1->tqparent, n2->tqparent);
+ if (n1->parent && n1->parent != root_trie)
+ cmp = trieStringCompare (n1->parent, n2->parent);
if (!cmp && n1 != n2) {
#ifdef TEST_TRIE
printf( "compare %s %s", n1->str, n2->str);
@@ -174,8 +174,8 @@ static int trieStringCompare (TrieNode * n1, TrieNode * n2) {
static int trieStringStarts (TrieNode * node, const char * s, int & pos) {
int cmp = -1; // -1 still matches, 0 no, 1 yes
- if (node->tqparent && node->tqparent != root_trie)
- cmp = trieStringStarts (node->tqparent, s, pos);
+ if (node->parent && node->parent != root_trie)
+ cmp = trieStringStarts (node->parent, s, pos);
if (cmp == -1) {
for (int i = 0; i < node->length; i++)
if (node->str[i] != s[pos + i])
@@ -190,8 +190,8 @@ static TrieNode * trieInsert (const char * s) {
root_trie = new TrieNode (0L);
//printf("trieInsert %s\n", s);
//dumpTrie();
- TrieNode * tqparent = root_trie;
- for (TrieNode * c = tqparent->first_child; c; c = c->first_child) {
+ TrieNode * parent = root_trie;
+ for (TrieNode * c = parent->first_child; c; c = c->first_child) {
TrieNode * prev = c;
for (TrieNode * n = prev; n; n = n->next_sibling) {
if (n->str[0] == s[0]) { // insert here
@@ -206,13 +206,13 @@ static TrieNode * trieInsert (const char * s) {
tmp[i] = 0;
TrieNode * node = new TrieNode (tmp);
free (tmp);
- node->tqparent = tqparent;
+ node->parent = parent;
node->next_sibling = n->next_sibling;
if (prev != n)
prev->next_sibling = node;
else
- tqparent->first_child = node;
- n->tqparent = node;
+ parent->first_child = node;
+ n->parent = node;
TrieNode * snode;
if (!s[i]) {
node->first_child = n;
@@ -220,7 +220,7 @@ static TrieNode * trieInsert (const char * s) {
snode = node; // s is complete in node
} else {
snode = new TrieNode (s+i);
- snode->tqparent = node;
+ snode->parent = node;
if (bigger) { // set n before snode
node->first_child = n;
n->next_sibling = snode;
@@ -244,28 +244,28 @@ static TrieNode * trieInsert (const char * s) {
return n;
} else if (n->str[0] > s[0]) { // insert before
TrieNode * node = new TrieNode (s);
- node->tqparent = tqparent;
+ node->parent = parent;
node->next_sibling = n;
if (prev != n)
prev->next_sibling = node;
else
- tqparent->first_child = node;
+ parent->first_child = node;
return node;
}
prev = n;
}
if (prev) { // insert after
TrieNode * node = new TrieNode (s);
- node->tqparent = tqparent;
+ node->parent = parent;
prev->next_sibling = node;
return node;
}
- tqparent = c;
+ parent = c;
}
// hit an empty first_child, add s as first_child
TrieNode * node = new TrieNode (s);
- tqparent->first_child = node;
- node->tqparent = tqparent;
+ parent->first_child = node;
+ node->parent = parent;
return node;
}
@@ -288,7 +288,7 @@ TrieString::~TrieString () {
}
bool TrieString::startsWith (const TrieString & s) const {
- for (TrieNode * n = node; n; n = n->tqparent)
+ for (TrieNode * n = node; n; n = n->parent)
if (n == s.node)
return true;
return s.node ? false : true;
@@ -342,11 +342,11 @@ bool TrieString::operator < (const TrieString & s) const {
if (node == s.node)
return false;
int depth1 = 0, depth2 = 0;
- for (TrieNode * n = node; n; n = n->tqparent)
+ for (TrieNode * n = node; n; n = n->parent)
depth1++;
if (!depth1)
return s.node ? true : false;
- for (TrieNode * n = s.node; n; n = n->tqparent)
+ for (TrieNode * n = s.node; n; n = n->parent)
depth2++;
if (!depth2)
return false;
@@ -355,13 +355,13 @@ bool TrieString::operator < (const TrieString & s) const {
while (depth1 > depth2) {
if (n1 == n2)
return false;
- n1 = n1->tqparent;
+ n1 = n1->parent;
depth1--;
}
while (depth2 > depth1) {
if (n1 == n2)
return true;
- n2 = n2->tqparent;
+ n2 = n2->parent;
depth2--;
}
int cmp = trieStringCompare (n1, n2);