Beispiel #1
0
/**
  Inserts an element into a minimizing priority queue.

  @param min_pq a minimizing priority queue
  @param data the data to be inserted
  @param key the key to be associated with \a data

  @return Returns 0 on success or 1 on failure.
*/
int minpq_insert( struct min_pq* min_pq, void* data, int key )
{
  int n = min_pq->n;

  /* double array allocation if necessary */
  if( min_pq->nallocd == n )
    {
      min_pq->nallocd = array_double( (void**)&min_pq->pq_array,
				      min_pq->nallocd,
				      sizeof( struct pq_node ) );
      if( ! min_pq->nallocd )
	{
	  fprintf( stderr, "Warning: unable to allocate memory, %s, line %d\n",
		   __FILE__, __LINE__ );
	  return 1;
	}
    }

  min_pq->pq_array[n].data = data;
  min_pq->pq_array[n].key = INT_MAX;
  decrease_pq_node_key( min_pq->pq_array, min_pq->n, key );
  min_pq->n++;

  return 0;
}
Beispiel #2
0
maf_array_parser get_array_parser(FILE *maf_file,char *filename){
	char buffer[3000];
	assert(buffer != NULL);
	maf_array_parser parser = malloc(sizeof(*parser));
	assert(parser != NULL);
        parser->maf_file = maf_file;
        parser->filename = strdup(filename);
        assert(parser->filename != NULL);
        parser->curr_block=0;
        parser->size = 0;
        parser->alignment_blocks = malloc(2*sizeof(int));
        assert(parser->alignment_blocks != NULL);
        parser->max = 2;
	int pos;
	while(!feof(maf_file)){
		pos = ftell(maf_file);
		char *check = fgets(buffer,3000,maf_file);
		if(ferror(maf_file) != 0){
			fprintf(stderr, "File stream error: %s\nError: %s",
					filename,strerror(errno));
			return NULL;
		}
		if(buffer[0]=='a'){
			if(parser->size == parser->max)
                           array_double(parser);
                        parser->alignment_blocks[parser->size++]=pos;
		}
	}
	return parser;
}