Exemple #1
0
void prune_tree(struct base_tree_node *n, int fasta_id)
{
   if (n->A != NULL)
   {
      if (n->A->fasta_id < fasta_id)
      {
         remove_subtree(n->A);
         n->A = NULL;
      }
      else
      {
         prune_tree(n->A, fasta_id);
      }
   }
   if (n->C != NULL)
   {
      if (n->C->fasta_id < fasta_id)
      {
         remove_subtree(n->C);
         n->C = NULL;
      }
      else
      {
         prune_tree(n->C, fasta_id);
      }
   }
   if (n->G != NULL)
   {
      if (n->G->fasta_id < fasta_id)
      {
         remove_subtree(n->G);
         n->G = NULL;
      }
      else
      {
         prune_tree(n->G, fasta_id);
      }
   }
   if (n->T != NULL)
   {
      if (n->T->fasta_id < fasta_id)
      {
         remove_subtree(n->T);
         n->T = NULL;
      }
      else
      {
         prune_tree(n->T, fasta_id);
      }
   }
}
static int
fco_invalidate(dev_info_t *ap, fco_handle_t rp, fc_ci_t *cp)
{
	dev_info_t *root, *child;
	struct fc_device_tree *subtree = fc_handle_to_dtree(rp);
	int configured = (rp->cdip_state == FC_CDIP_CONFIG);

	/*
	 * If we created any children, delete them. The root node is the
	 * config child, if one exists for this bus, otherwise it's the
	 * attachment point.
	 *
	 * Our copy of the subtree only contains records of nodes we created
	 * under the subtree root and contains the parent->child linkage
	 * that isn't yet established in the real device tree.
	 *
	 * XXX: What we don't do is restore the config child node to it's
	 * pre-interpretive state. (We may have added properties to
	 * that node. It's not clear if its necessary to clean them up.)
	 */
	root = rp->child ? rp->child : ap;

	while ((child = fc_child_node(root, subtree)) != NULL) {
		FC_DEBUG2(1, CE_CONT, "fco_invalidate: remove subtree "
		    "<%s> dip %p\n", ddi_node_name(child), child);
		remove_subtree(child, subtree);
	}

	if (configured)
		(void) ndi_devi_offline(root, NDI_UNCONFIG);

	cp->nresults = fc_int2cell(0);
	return (fc_success_op(ap, rp, cp));
}
void OIDTree::replace_subtree(OID root_oid, OIDMap update)
{
  _map_lock.lock();
  remove_subtree(root_oid);
  _oidmap.insert(update.begin(), update.end());

  _map_lock.unlock();
}
Exemple #4
0
void remove_subtree(struct base_tree_node *n)
{
   if (n->A != NULL)
   {
      remove_subtree(n->A);
   }
   if (n->C != NULL)
   {
      remove_subtree(n->C);
   }
   if (n->G != NULL)
   {
      remove_subtree(n->G);
   }
   if (n->T != NULL)
   {
      remove_subtree(n->T);
   }
   free_base_tree_node(n);
}
static void
remove_subtree(dev_info_t *root, struct fc_device_tree *subtree)
{
	dev_info_t *child;

	/*
	 * Remove the subtree, depth first. Each iterative
	 * call gets another child at each level of the tree
	 * until there are no more children.
	 */
	while ((child = fc_child_node(root, subtree)) != NULL)
		remove_subtree(child, subtree);

	/*
	 * Delete the subtree root and remove its record from our
	 * copy of the subtree.
	 */
	fc_remove_child(root, subtree);
	(void) ndi_devi_offline(root, NDI_UNCONFIG | NDI_DEVI_REMOVE);
}
Exemple #6
0
int main(void)
{
   FILE *f = fopen("data", "r");
   if (f == NULL) 
   {
      puts("Failed to open data file");
      return 1;
   }

   struct fasta_list fastas;
   fastas.head = NULL;
   fastas.current_node = NULL;

   ssize_t chars_read;
   char *current_line = NULL;
   size_t current_line_alloc = 0;
   while ((chars_read = getline(&current_line, &current_line_alloc, f)) > -1)
   {
      //printf("READ FROM FILE: %s\n", current_line);
      if (*current_line == '>')
      {
         // fasta name - skip '>' character
         char *name = malloc((chars_read-1)*sizeof(char));
         if (sscanf(current_line, ">%s\n", name) != 1)
         {
            puts("Failed to read line name");
            return 1;
         }
         //printf("%s\n", name);
         struct fasta_node *fn = new_fasta_node(name); 
         if (fastas.head == NULL)
         {
            // first entry
            fastas.current_node = fastas.head = fn;
         }
         else if (fastas.current_node->fasta.dna.len == 0)
         {
            puts("Found title line but current fasta is empty");
            return 1;
         }
         else
         {
            //printf("%s: %s", fastas.current_node->fasta.name, fastas.current_node->fasta.dna.data);
            fastas.current_node = fastas.current_node->next = fn;
         }
      }
      else
      {
         //printf("Adding chars to %s: %s", fastas.current_node->fasta.name, current_line);
         if (current_line[chars_read] == '\0'
           && current_line[chars_read-1] == '\n')
         {
            current_line[chars_read-1] = '\0';
         }
         else
         {
            puts("Failed end of dna string newline replacement");
            return 1;
         }
         append_chars(&(fastas.current_node->fasta.dna), current_line);
      }
   }
   free(current_line);
   fclose(f);

   struct base_tree_node *base = new_base_tree_node("", "");
   struct fasta_node *fn = fastas.head;
   int fasta_id = 0;
   while (fn != NULL)
   {
      //printf("%s\n%s\n", fn->fasta.name, fn->fasta.dna.data);
      char *start = fn->fasta.dna.data;
      while (*start != '\0')
      {
         //printf("next substring: %s\n", start);
         suffix_tree_add(start, base, fasta_id);
         start++;
      }

      prune_tree(base, fasta_id);
      
      fn = fn->next;
      fasta_id++;
   }

   char *longest = NULL;
   int longest_level=-1;
   find_longest_substring(base, 0, &longest, &longest_level);
   
   printf("%s\n", longest);

   remove_subtree(base);
   free_fasta_nodes(&fastas);
}