예제 #1
0
unsigned long
trie_size (trie_t *t)
{
  if (t == NULL)
    return 0;
  else
    return 1 + trie_size (t->left) + trie_size (t->right);
}
예제 #2
0
/* Generates a trie containing a mapping from deligatured words back
   to their "real" worlds.  Returns 1 on success, otherwise 0. */
static Trie* find_ligatures( char* dictionary_file ) {
  FILE *words_file = fopen( dictionary_file, "r" );
  if ( words_file == NULL ) {
    return 0;
  }
  char *buf = NULL;
  size_t n_read, buf_size = 0;
  Trie *trie = trie_new( "", NULL );
  while ( ( n_read = getline( &buf, &buf_size, words_file ) ) != -1 ) {
    if ( buf[n_read - 1] == '\n' ) --n_read;
    buf[n_read] = 0;

    add_deligatured_word( buf, trie );

    /* For non-proper names (i.e., normal words) we want to add to
       our trie the deligaturization of the *capitalized* version of
       the word.  Consider, for example, that "fluffy" and "Fluffy"
       have different deligaturizations: "uy" and "Fluy",
       respectively. */
    if ( islower( buf[0] ) ) {
      buf[0] = toupper( buf[0] );
      // now find ligatures again, and add it if appropriate
      add_deligatured_word( buf, trie );
    }
  }
  free( buf );
  fclose( words_file );

  printf( "Trie size=%d\n", trie_size( trie ) );
/*   trie_display( trie ); */
/*   printf( "Trie size=%d\n", trie_size( words ) ); */
/*   trie_display( words ); */
/*   printf( "aunt=%d\n", trie_contains( words, "aunt" ) ); */

/*   char test_buf[100]; */
/*   strcpy( test_buf, "eect" ); */
/*   religature_word( test_buf, sizeof( test_buf ) ); */
/*   strcpy( test_buf, "Eect" ); */
/*   religature_word( test_buf, sizeof( test_buf ) ); */
/*   strcpy( test_buf, "uy" ); // fluffy */
/*   religature_word( test_buf, sizeof( test_buf ) ); */
/*   strcpy( test_buf, "Fluy" ); // Fluffy */
/*   religature_word( test_buf, sizeof( test_buf ) ); */
/*   strcpy( test_buf, "Flanagan" ); */
/*   religature_word( test_buf, sizeof( test_buf ) ); */
/*   strcpy( test_buf, "anagan" ); // no such word! (flanagan) */
/*   religature_word( test_buf, sizeof( test_buf ) ); */

  return trie;
}
예제 #3
0
파일: trie.c 프로젝트: iesl/rexa1-pstotext
int trie_size( Trie *t ) {
  int n = 0;
  int i;
  if ( t->children ) {
    Trie *child;
    for ( i = 0; i < TRIE_ALPHABET_SIZE; ++i ) {
      if ( ( child = t->children[i] )  != 0 ) {
        n += trie_size( child );
      }
    }
  }
  if ( t->is_end_of_string ) {
    return n + 1;
  } else {
    return n;
  }
}
예제 #4
0
파일: trie.c 프로젝트: cheuk-fung/C--
size_t trie_size(struct Trie_node *root)
{
    size_t size = 0;
    if (root->symbol) {
        struct Stab *symbol = root->symbol;
        if (symbol->funcno > 0 && symbol->type->kind != T_STRUCT && symbol->arysize_cnt) {
            size += symbol->size * symbol->arysize_list->size;
        } else {
            size += symbol->size;
        }
    }

    int i;
    for (i = 0; i < 53; i++) {
        if (root->next[i]) {
            size += trie_size(root->next[i]);
        }
    }

    return size;
}
예제 #5
0
파일: dictionary.c 프로젝트: manhtai/some-c
/**
 * Returns number of words in dictionary if loaded else 0 if not yet loaded.
 */
unsigned int size(void)
{
    return trie_size(&trie);
}