deps/kb_meme/meme-5.0.1/src/alph-in.c
/*
 * merge_aliases
 * This merges the fields of the aliases and stores it in the merged tree.
 */
merge_aliases
This merges the fields of the aliases and stores it in the merged tree.
merge_aliases This merges the fields of the aliases and stores it in the merged tree .
static void merge_aliases(ALPH_READER_T *reader) {
  ALPH_SYM_T *sym;
  RBNODE_T *node, *node2;
  ARRAYLST_T *aliases;
  RBTREE_T *alts;
  int i, j, k;
  alts = rbtree_create(rbtree_charcmp, rbtree_charcpy, free, NULL, NULL);
  for (i = 0, node = rbtree_first(reader->aliases); node != NULL; node = rbtree_next(node), i++) {
    ALPH_SYM_T *sym, *alias;
    if (i != 0) rbtree_clear(alts); 
    sym = mm_malloc(sizeof(ALPH_SYM_T));
    aliases = (ARRAYLST_T*)rbtree_value(node);
    arraylst_qsort(alph_sym_p_compare, aliases);
    alias = (ALPH_SYM_T*)arraylst_get(0, aliases);
    sym->symbol = alias->symbol;
    sym->complement = alias->complement;
    sym->comprise = (alias->comprise != NULL ? strdup(alias->comprise) : NULL);
    sym->name = NULL;
    sym->colour = -1;
    sym->aliases = NULL;
    for (j = 0; j < arraylst_size(aliases); j++) {
      alias = (ALPH_SYM_T*)arraylst_get(j, aliases);
      rbtree_make(alts, &(alias->symbol), NULL);
      if (alias->name != NULL && sym->name == NULL) sym->name = strdup(alias->name);
      if (alias->colour != -1 && sym->colour == -1) sym->colour = alias->colour;
      if (alias->aliases != NULL) {
        for (k = 0; alias->aliases[k]; k++) {
          rbtree_make(alts, &(alias->aliases[k]), NULL);
        }
      }
    }
    rbtree_remove(alts, &(sym->symbol));
    sym->aliases = mm_malloc(sizeof(char) * (rbtree_size(alts) + 1));
    for (j = 0, node2 = rbtree_first(alts); node2 != NULL; node2 = rbtree_next(node2), j++) {
      sym->aliases[j] = *((char*)rbtree_key(node2));
    }
    sym->aliases[j] = '\0';
    qsort(sym->aliases, rbtree_size(alts), sizeof(char), alph_sym_cmp);
    rbtree_put(reader->merged, rbtree_key(node), sym);
  }
  rbtree_destroy(alts);
}
static void merge_aliases ( ALPH_READER_T * reader ) { ALPH_SYM_T * sym ; RBNODE_T * node , * node2 ; ARRAYLST_T * aliases ; RBTREE_T * alts ; int i , j , k ; alts = rbtree_create ( rbtree_charcmp , rbtree_charcpy , free , NULL , NULL ) ; for ( i = 0 , node = rbtree_first ( reader -> aliases ) ; node != NULL ; node = rbtree_next ( node ) , i ++ ) { ALPH_SYM_T * sym , * alias ; if ( i != 0 ) rbtree_clear ( alts ) ; sym = mm_malloc ( sizeof ( ALPH_SYM_T ) ) ; aliases = ( ARRAYLST_T * ) rbtree_value ( node ) ; arraylst_qsort ( alph_sym_p_compare , aliases ) ; alias = ( ALPH_SYM_T * ) arraylst_get ( 0 , aliases ) ; sym -> symbol = alias -> symbol ; sym -> complement = alias -> complement ; sym -> comprise = ( alias -> comprise != NULL ? strdup ( alias -> comprise ) : NULL ) ; sym -> name = NULL ; sym -> colour = -1 ; sym -> aliases = NULL ; for ( j = 0 ; j < arraylst_size ( aliases ) ; j ++ ) { alias = ( ALPH_SYM_T * ) arraylst_get ( j , aliases ) ; rbtree_make ( alts , & ( alias -> symbol ) , NULL ) ; if ( alias -> name != NULL && sym -> name == NULL ) sym -> name = strdup ( alias -> name ) ; if ( alias -> colour != -1 && sym -> colour == -1 ) sym -> colour = alias -> colour ; if ( alias -> aliases != NULL ) { for ( k = 0 ; alias -> aliases [ k ] ; k ++ ) { rbtree_make ( alts , & ( alias -> aliases [ k ] ) , NULL ) ; } } } rbtree_remove ( alts , & ( sym -> symbol ) ) ; sym -> aliases = mm_malloc ( sizeof ( char ) * ( rbtree_size ( alts ) + 1 ) ) ; for ( j = 0 , node2 = rbtree_first ( alts ) ; node2 != NULL ; node2 = rbtree_next ( node2 ) , j ++ ) { sym -> aliases [ j ] = * ( ( char * ) rbtree_key ( node2 ) ) ; } sym -> aliases [ j ] = ' \0 ' ; qsort ( sym -> aliases , rbtree_size ( alts ) , sizeof ( char ) , alph_sym_cmp ) ; rbtree_put ( reader -> merged , rbtree_key ( node ) , sym ) ; } rbtree_destroy ( alts ) ; }
merge_aliases
 This merges the fields of the aliases and stores it in the merged tree.
merge_aliases This merges the fields of the aliases and stores it in the merged tree .
// reset the alts set // remove the main symbol from the alternate symbol set // flatten the tree set into a list of characters. // sort the alt symbols // finally put the merged symbol into the lookup