/* * Add a node the the Trie (should be kid or sibling of the root) * */ static int _faup_tld_tree_add_node(TLDNode **Tree, char *tld, int tld_len) { bool lastChar, nextIsDot, nextIsException; char *p; int ret; TLDNode *pNode = *Tree; int counter = 0; //printf("Adding the TLD:[%s]\n", tld); // Add the TLD to the Trie in reverse order p = tld + tld_len -1; while(counter < tld_len) { lastChar = (counter+1 == tld_len) ? true : false; if (counter+1 < tld_len) { nextIsDot = (*(p-1) == '.') ? true : false; nextIsException = (*(p-1) == '!') ? true : false; } else { nextIsDot = false; nextIsException = false; } // char does not exist in the Trie at that position if( pNode->kid == NULL ) { ret = _faup_tld_tree_allocate_kid(&pNode, *p, lastChar | nextIsDot | nextIsException, true); if( ret == -1 ) { return -1; } } // char may exist in the Trie else { pNode = pNode->kid; while( (pNode->sibling != NULL) && (pNode->c != *p) ) { pNode = pNode->sibling; } // char does not exist if( pNode->c != *p ) { ret = _faup_tld_tree_allocate_sibling(&pNode, *p, lastChar | nextIsDot | nextIsException, true); if( ret == -1 ) { return -1; } } // char already exist at that position but not necessary as an ended one. else if( lastChar || nextIsDot || nextIsException ) { pNode->EoT = true; } } counter++; p--; } return 0; }
/* * Add a node the the Trie (should be kid or sibling of the root) * */ static int _faup_tld_tree_add_node(TLDNode **Tree, char *TLD, int tLen) { bool lastChar, nextIsDot, nextIsException; char *p; int ret; TLDNode *pNode = *Tree; // Add the TLD to the Trie in reverse order p = TLD +tLen -1; while( *p ) { lastChar = *(p-1) ? false : true; nextIsDot = (*(p-1) == '.') ? true : false; nextIsException = (*(p-1) == '!') ? true : false; // char does not exist in the Trie at that position if( pNode->kid == NULL ) { ret = _faup_tld_tree_allocate_kid(&pNode, *p, lastChar | nextIsDot | nextIsException, true); if( ret == -1 ) return -1; } // char may exist in the Trie else { pNode = pNode->kid; while( (pNode->sibling != NULL) && (pNode->c != *p) ) pNode = pNode->sibling; // char does not exist if( pNode->c != *p ) { ret = _faup_tld_tree_allocate_sibling(&pNode, *p, lastChar | nextIsDot | nextIsException, true); if( ret == -1 ) return -1; } // char already exist at that position but not necessary as an ended one. else if( lastChar || nextIsDot || nextIsException ) pNode->EoT = true; } p--; } return 0; }