Exemple #1
0
int el_timer_process(eventloop_t *el) {
    int processed = 0, ret;
    uint32_t len = minheap_len(el->timers);

    while (len) {
        ev_timer_t *t = (ev_timer_t *) minheap_min(el->timers);
        if (!rr_dt_is_past(t->sec, t->ms)) break;

        t = (ev_timer_t *) minheap_pop(el->timers);
        long long millisecond = t->timer_cb(el, t->ud);
        /* if the timer is still active, push it back to heap */
        if (millisecond > 0) {
            rr_dt_expire_at(millisecond, &t->sec, &t->ms);
            ret = minheap_push(el->timers, t);
            assert(!ret);
        }
        processed++;
        len--;
    }
    return processed;
}
Exemple #2
0
int main()
{
        int32_t i; 
        u_char* ptr=NULL; 
        const char *a="a", *b="b", *c="c", *d="d", *e="e", *f="f", *g="g";
        minheap_t* heap = minheap_create(256);
        if (heap == NULL) {
                printf("malloc minheap memory error!\n");
        }
        
        minheap_insert(heap, 34, (u_char *)a);
        printf("index:%d\n", (int)minheap_insert(heap, 25, (u_char*)b));
        minheap_insert(heap, 89, (u_char *)c);
        minheap_insert(heap, 4,  (u_char *)d);
        minheap_insert(heap, 12, (u_char *)e);
        minheap_insert(heap, 25, (u_char *)b);
        minheap_insert(heap, 10, (u_char *)g);
     
         
        for(i=0; i<minheap_count(heap); i++) {
                printf("index:%d, weight:%d, ptr:%s\n", i,
                        heap->mh_nodes[i].mn_weight, (char *)heap->mh_nodes[i].mn_ptr);
        } 
       
        ptr = minheap_pop(heap);
        printf("minheap pop ptr:%p\n", ptr);
        printf("minheap pop ptr:%s\n", ptr);

        for(i=0; i<minheap_count(heap); i++) {
                printf("index:%d, weight:%d, ptr:%s\n", i,
                        heap->mh_nodes[i].mn_weight, (char *)heap->mh_nodes[i].mn_ptr);
        } 
        
        minheap_free(heap);
        
}
Exemple #3
0
/**

To get the effective area, we have to check what area a point results in when all smaller areas are eliminated
*/
static void tune_areas(EFFECTIVE_AREAS *ea, int avoid_collaps, int set_area, double trshld)
{
	LWDEBUG(2, "Entered  tune_areas");
	const double *P1;
	const double *P2;
	const double *P3;
	double area;
	int go_on=1;
	double check_order_min_area = 0;
	
	int npoints=ea->inpts->npoints;
	int i;
	int current, before_current, after_current;
	
	MINHEAP tree = initiate_minheap(npoints);
	
	int is3d = FLAGS_GET_Z(ea->inpts->flags);
	
	
	/*Add all keys (index in initial_arealist) into minheap array*/
	for (i=0;i<npoints;i++)
	{
		tree.key_array[i]=ea->initial_arealist+i;
		LWDEBUGF(2, "add nr %d, with area %lf, and %lf",i,ea->initial_arealist[i].area, tree.key_array[i]->area );
	}
	tree.usedSize=npoints;
	
	/*order the keys by area, small to big*/	
	qsort(tree.key_array, npoints, sizeof(void*), cmpfunc);
	
	/*We have to put references to our tree in our point-list*/
	for (i=0;i<npoints;i++)
	{
		 ((areanode*) tree.key_array[i])->treeindex=i;
		LWDEBUGF(4,"Check ordering qsort gives, area=%lf and belong to point %d",((areanode*) tree.key_array[i])->area, tree.key_array[i]-ea->initial_arealist);
	}
	/*Ok, now we have a minHeap, just need to keep it*/
	
	/*for (i=0;i<npoints-1;i++)*/
	i=0;
	while (go_on)
	{	
		/*Get a reference to the point with the currently smallest effective area*/
		current=minheap_pop(&tree, ea->initial_arealist)-ea->initial_arealist;
	
		/*We have found the smallest area. That is the resulting effective area for the "current" point*/
		if (i<npoints-avoid_collaps)
			ea->res_arealist[current]=ea->initial_arealist[current].area;
		else
			ea->res_arealist[current]=FLT_MAX;	
		
		if(ea->res_arealist[current]<check_order_min_area)
			lwerror("Oh no, this is a bug. For some reason the minHeap returned our points in the wrong order. Please file a ticket in PostGIS ticket system, or send a mial at the mailing list.Returned area = %lf, and last area = %lf",ea->res_arealist[current],check_order_min_area);
		
		check_order_min_area=ea->res_arealist[current];		
		
		/*The found smallest area point is now regarded as elimnated and we have to recalculate the area the adjacent (ignoring earlier elimnated points) points gives*/
		
		/*FInd point before and after*/
		before_current=ea->initial_arealist[current].prev;
		after_current=ea->initial_arealist[current].next;
		
		P2= (double*)getPoint_internal(ea->inpts, before_current);
		P3= (double*)getPoint_internal(ea->inpts, after_current);
		
		/*Check if point before current point is the first in the point array. */
		if(before_current>0)
		{		
					
			P1= (double*)getPoint_internal(ea->inpts, ea->initial_arealist[before_current].prev);
			if(is3d)
				area=triarea3d(P1, P2, P3);
			else
				area=triarea2d(P1, P2, P3);			
			
			ea->initial_arealist[before_current].area = FP_MAX(area,ea->res_arealist[current]);
			minheap_update(&tree, ea->initial_arealist, ea->initial_arealist[before_current].treeindex);
		}
		if(after_current<npoints-1)/*Check if point after current point is the last in the point array. */
		{
			P1=P2;
			P2=P3;	
			
			P3= (double*)getPoint_internal(ea->inpts, ea->initial_arealist[after_current].next);
			

			if(is3d)
				area=triarea3d(P1, P2, P3);
			else
				area=triarea2d(P1, P2, P3);	
		
				
			ea->initial_arealist[after_current].area = FP_MAX(area,ea->res_arealist[current]);
			minheap_update(&tree, ea->initial_arealist, ea->initial_arealist[after_current].treeindex);
		}
		
		/*rearrange the nodes so the eliminated point will be ingored on the next run*/
		ea->initial_arealist[before_current].next = ea->initial_arealist[current].next;
		ea->initial_arealist[after_current].prev = ea->initial_arealist[current].prev;
		
		/*Check if we are finnished*/
		if((!set_area && ea->res_arealist[current]>trshld) || (ea->initial_arealist[0].next==(npoints-1)))
			go_on=0;
		
		i++;
	};
	destroy_minheap(tree);
	return;	
}
Exemple #4
0
fts_doc_score_t *fts_iter_next(struct fts_iterator_t *it) {
    return minheap_pop(it->docs);
}