示例#1
0
文件: lcp.c 项目: giavjeko/bio
// Compute lcp for given Wavelet tree with data
void compute_lcp(Wtree* wtree, int* dst, int len) {
  int i, begin, end, l;
  Queue* queue = queue_construct();
  List* list = list_construct();
  Element* element;

  dst[1] = -1;
  dst[len + 1] = -1;
  for (i = 2; i <= len; i++) {
    dst[i] = -2;
  }

  queue_push(queue, 1, len, 0);
  while(!queue_empty(queue)) {
    queue_pop(queue, &begin, &end, &l);
    list = wtree_get_intervals(wtree, begin, end);
    for (element = list->head; element; element=element->next) {
      if (dst[element->end + 1] == -2) {
        queue_push(queue, element->begin, element->end, l + 1);
        dst[element->end + 1] = l;
      }
    }
    list_destroy(list);
  }
}
示例#2
0
/**
	Reads the specified setup file, 
	building a list of strings containing the operations to simulate.<br>
	Assumes that the file has a correct structure.
	@param pathname The setup file's path
	@return The list of operations to compute
*/
static list* parse_file(const char *const pathname) {
	list *result = list_construct();
	char line[50];
	int len, fd;
	
	if(result == NULL) 
		exit(1);

	fd = open(pathname, O_RDONLY);
	if(fd == -1) {
		write_to_fd(2, "Failed to open setup file\n");
		exit(1);
	}
		
	do {
		len = read_line(fd, line, 50);
		if (len > 0)
			list_append(result, line);
	} while(len >= 0);
	
	if (close(fd) == -1) {
		write_to_fd(2, "Failed to close setup file\n");
		exit(1);
	}

	return result;
}
示例#3
0
文件: wtree.c 项目: giavjeko/bio
// Calculate sub-intervals for given interval in given wavelet tree
List* wtree_get_intervals(Wtree* wtree, int begin, int end) {
  List* list = list_construct();
  wtree_get_intervals_recursion(wtree, wtree->root, begin, end, &list);
  return list;
}
示例#4
0
int main(void)
{
    data_t *datap = NULL;
    list_t *Lptr = NULL;
   /***** 
    Lptr = list_construct(trte_compare, trte_route_rec_cleanup);
    
    // create one item to test list_insert
    datap = (data_t *) calloc(1,sizeof(data_t));
    datap->src_ip_addr = 555;
    datap->dest_ip_addr = 555;
    list_insert(Lptr, datap, LISTPOS_HEAD);
    datap = NULL;
    
    // add a second item to head  of the list
    datap = (data_t *) calloc(1,sizeof(data_t));
    datap->src_ip_addr = 444;
    datap->dest_ip_addr = 444;
    list_insert(Lptr, datap, LISTPOS_HEAD);
    datap = NULL;
    
    // add a 3rd item to tail of the list
    datap = (data_t *) calloc(1,sizeof(data_t));
    datap->src_ip_addr = 777;
    datap->dest_ip_addr = 777;
    list_insert(Lptr, datap, LISTPOS_TAIL);
    datap = NULL;
    
    // add a 4th item
    datap = (data_t *) calloc(1,sizeof(data_t));
    datap->src_ip_addr = 500;
    datap->dest_ip_addr = 500;
    list_insert(Lptr, datap, LISTPOS_TAIL);
    datap = NULL;
    
    // add a 4th item, sorted
    datap = (data_t *) calloc(1,sizeof(data_t));
    datap->src_ip_addr = 333;
    datap->dest_ip_addr = 333;
    list_insert_sorted(Lptr, datap);
    datap = NULL;
    
    // test list_access with one item in list
    datap = list_access(Lptr, LISTPOS_HEAD);
    printf("Should find 555 and found (%d)\n\n", datap->src_ip_addr);
    datap = NULL;
    
    
    // find all three and print
    datap = list_access(Lptr, 0);
    printf("Second test\nPosition 0 should find 555 and found (%d)\n", datap->src_ip_addr);
    datap = list_access(Lptr, 1);
    printf("Position 1 should find 555 and found (%d)\n", datap->src_ip_addr);
    datap = list_access(Lptr, 2);
    printf("Position 2 should find 777  and found (%d)\n", datap->src_ip_addr);
    datap = list_access(Lptr, 3);
    printf("Position 3 should find 777  and found (%d)\n", datap->src_ip_addr);
    datap = list_access(Lptr, 3);
    printf("Position 3 should find 777  and found (%d)\n", datap->src_ip_addr);
    
    //Next try to use list_debug_print
    printf("\nTest of list print\n\n");
    list_debug_print(Lptr);
    */
    
    // Uncomment this section to test list_elem_find
    /*********************************************************************
     data_t template;
     int my_index = -999;
     template.src_ip_addr = 444;
     template.dest_ip_addr = 444;
     data_t *foundp = list_elem_find(Lptr, &template, &my_index);
     printf("\nTest of list elem find\n");
     if (foundp != NULL)
     printf("looked for %d and found %d at index %d\n",
     template.src_ip_addr, foundp->src_ip_addr, my_index);
     else
     printf("looked for %d and did not find \n", template.src_ip_addr);
     foundp = NULL;
     
     */
    
    //list_destruct(Lptr);
    // End of tests with unsorted list
    
    // Uncomment this section to try some tests on a sorted list
    /*********************************************************************/
     list_t *Lsortptr = list_construct(trte_compare, trte_route_rec_cleanup);
     //Lsortptr->list_sorted_state = -7654321;
     datap = (data_t *) calloc(1,sizeof(data_t));
     datap->src_ip_addr = 23;
     datap->dest_ip_addr = 23;
     list_insert_sorted(Lsortptr, datap);
     datap = NULL;
     
     // add a second item
     datap = (data_t *) calloc(1,sizeof(data_t));
     datap->src_ip_addr = 7;
     datap->dest_ip_addr = 7;
     list_insert_sorted(Lsortptr, datap);
     datap = NULL;
     
     // add a third item
     datap = (data_t *) calloc(1,sizeof(data_t));
     datap->src_ip_addr = 15;
     datap->dest_ip_addr = 15;
     list_insert_sorted(Lsortptr, datap);
     datap = NULL;
     
     // add a fourth item
     datap = (data_t *) calloc(1,sizeof(data_t));
     datap->src_ip_addr = 8;
     datap->dest_ip_addr = 8;
     list_insert_sorted(Lsortptr, datap);
     datap = NULL;

    // add a fifth item
    datap = (data_t *) calloc(1,sizeof(data_t));
    datap->src_ip_addr = 28;
    datap->dest_ip_addr = 28;
    list_insert_sorted(Lsortptr, datap);
    datap = NULL;
    //print
    list_debug_print(Lsortptr);
    // remove an item
    data_t *temp = list_remove(Lsortptr, 3);       
    //print
    list_debug_print(Lsortptr);
    // add a sixth  item
    datap = (data_t *) calloc(1,sizeof(data_t));
    datap->src_ip_addr = 2;
    datap->dest_ip_addr = 2;
    list_insert_sorted(Lsortptr, datap);
    datap = NULL;
    
     list_reverse(Lsortptr);

     //print
     list_debug_print(Lsortptr);
     list_destruct(Lsortptr);
     
    
    return 0;
}