Esempio n. 1
0
File: trie.c Progetto: ahfx/misc
int printTrieNode(trieNode* node) {
    
    trieNode* firstChild = NULL;
    
    for(int i=0; i<MAX_CHILD_NODES; i++) {
        
        if (node->children[i] != NULL){
            
            if (firstChild == NULL)
                firstChild = node->children[i];
            
          printf("[");
          if (i == 26) printf("%c", 39);
          else printf("%c", i+97);
          
          if (node->children[i]->is_word) printf("w");
          printf("]");  
            
        } else
            printf("[]");
    }

    printf("\n");
    
    if (firstChild != NULL) printTrieNode(firstChild);

    return 0;

}
int sprintTriePath(CTXTdeclc char * buffer, BTNptr pLeaf) {

  BTNptr pRoot;
  int ctr = 0;

  if ( IsNULL(pLeaf) ) {
    return sprintf(buffer, "NULL");
  }

  if ( ! IsLeafNode(pLeaf) ) {
    fprintf(stderr, "printTriePath() called with non-Leaf node!\n");
    printTrieNode(stderr, pLeaf);
    return -1;
  }

  if  (IsEscapeNode(pLeaf) ) {
    //    printf("escape\n");
    pRoot = BTN_Parent(pLeaf);
    if ( IsNonNULL(pRoot) ) {
      ctr = ctr + sprintTrieSymbol(buffer+ctr, BTN_Symbol(pRoot));
      return ctr;
    }
    else {
      fprintf(stderr, "ESCAPE node");
      return 0;
    }
  }

  SymbolStack_ResetTOS;
  SymbolStack_PushPathRoot(pLeaf,pRoot);
  if ( IsTrieFunctor(BTN_Symbol(pRoot)) ) {
    //    printf("tf\n");
    SymbolStack_Push(BTN_Symbol(pRoot));
    ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE);
  }
  else {
    //    printf("nontf\n");
    ctr = ctr + sprintTrieSymbol(buffer+ctr,BTN_Symbol(pRoot));
    ctr = ctr + sprintf(buffer+ctr, "(");
    ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE);
    while ( ! SymbolStack_IsEmpty ) {
      ctr = ctr + sprintf(buffer+ctr, ",");
      ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE);
    }
        ctr = ctr + sprintf(buffer+ctr, ")");
  }
  return ctr;
}
Esempio n. 3
0
void printTriePath(FILE *fp, BTNptr pLeaf, xsbBool printLeafAddr) {

  BTNptr pRoot;

  if ( IsNULL(pLeaf) ) {
    fprintf(fp, "NULL");
    return;
  }

  if ( ! IsLeafNode(pLeaf) ) {
    fprintf(fp, "printTriePath() called with non-Leaf node!\n");
    printTrieNode(fp, pLeaf);
    return;
  }

  if ( printLeafAddr )
    fprintf(fp, "Leaf %p: ", pLeaf);

  if ( IsEscapeNode(pLeaf) ) {
    pRoot = BTN_Parent(pLeaf);
    if ( IsNonNULL(pRoot) )
      printTrieSymbol(fp, BTN_Symbol(pRoot));
    else
      fprintf(fp, "ESCAPE node");
    return;
  }

  SymbolStack_ResetTOS;
  SymbolStack_PushPathRoot(pLeaf,pRoot);
  if ( IsTrieFunctor(BTN_Symbol(pRoot)) ) {
    SymbolStack_Push(BTN_Symbol(pRoot));
    symstkPrintNextTerm(fp,FALSE);
  }
  else {
    printTrieSymbol(fp,BTN_Symbol(pRoot));
    fprintf(fp, "(");
    symstkPrintNextTerm(fp,FALSE);
    while ( ! SymbolStack_IsEmpty ) {
      fprintf(fp, ",");
      symstkPrintNextTerm(fp,FALSE);
    }
    fprintf(fp, ")");
  }
}
Esempio n. 4
0
File: trie.c Progetto: ahfx/misc
int printTrie() {
    return printTrieNode(TRIE_ROOT);
}