Beispiel #1
0
int fc_solve_PQueuePush(
        PQUEUE *pq,
        fcs_state_extra_info_t * val,
        pq_rating_t r
        )
{
    uint32 i;
    pq_element_t * Elements = pq->Elements;

    int32 CurrentSize = pq->CurrentSize;

    if (CurrentSize == pq->MaxSize )
    {
        int new_size;
        new_size = pq->MaxSize + 256;
        pq->Elements = Elements = (pq_element_t *)realloc( Elements, sizeof(pq_element_t) * (new_size+1));
        pq->MaxSize = new_size;
    }

    {
        /* set i to the first unused element and increment CurrentSize */

        i = (++CurrentSize);

        /* while the parent of the space we're putting the new node into is worse than
           our new node, swap the space with the worse node. We keep doing that until we
           get to a worse node or until we get to the top

           note that we also can sort so that the minimum elements bubble up so we need to loops
           with the comparison operator flipped... */

        {

            while( ( i==PQ_FIRST_ENTRY ?
                     (PQUEUE_MaxRating) /* return biggest possible rating if first element */
                     :
                     (PGetRating(Elements[ PQ_PARENT_INDEX(i) ]) )
                   )
                   < r
                 )
            {
                Elements[ i ] = Elements[ PQ_PARENT_INDEX(i) ];

                i = PQ_PARENT_INDEX(i);
            }
        }

        /* then add the element at the space we created. */
        Elements[i].val = val;
        Elements[i].rating = r;
    }

    pq->CurrentSize = CurrentSize;

    return TRUE;

}
static inline void
pqueue_push (sweep_line_t *sweep, rectangle_t *rectangle)
{
    rectangle_t **elements;
    int i, parent;

    if (unlikely (sweep->pq.size + 1 == sweep->pq.max_size)) {
	if (unlikely (! pqueue_grow (&sweep->pq))) {
	    longjmp (sweep->unwind,
		     _cairo_error (CAIRO_STATUS_NO_MEMORY));
	}
    }

    elements = sweep->pq.elements;
    for (i = ++sweep->pq.size;
	 i != PQ_FIRST_ENTRY &&
	 rectangle_compare_stop (rectangle,
				 elements[parent = PQ_PARENT_INDEX (i)]) < 0;
	 i = parent)
    {
	elements[i] = elements[parent];
    }

    elements[i] = rectangle;
}
static inline cairo_status_t
_pqueue_push (pqueue_t *pq, cairo_bo_event_t *event)
{
    cairo_bo_event_t **elements;
    int i, parent;

    if (unlikely (pq->size + 1 == pq->max_size)) {
	cairo_status_t status;

	status = _pqueue_grow (pq);
	if (unlikely (status))
	    return status;
    }

    elements = pq->elements;

    for (i = ++pq->size;
	 i != PQ_FIRST_ENTRY &&
	 cairo_bo_event_compare (event,
				 elements[parent = PQ_PARENT_INDEX (i)]) < 0;
	 i = parent)
    {
	elements[i] = elements[parent];
    }

    elements[i] = event;

    return CAIRO_STATUS_SUCCESS;
}
static inline void
pqueue_push (sweep_line_t *sweep, rectangle_t *rectangle)
{
    rectangle_t **elements;
    int i, parent;

    elements = sweep->stop;
    for (i = ++sweep->stop_size;
	 i != PQ_FIRST_ENTRY &&
	 rectangle_compare_stop (rectangle,
				 elements[parent = PQ_PARENT_INDEX (i)]) < 0;
	 i = parent)
    {
	elements[i] = elements[parent];
    }

    elements[i] = rectangle;
}
Beispiel #5
0
int PQueuePush( PQUEUE *pq, pq_element_t item)
{
    uint32 i;

    if (pq->CurrentSize == pq->MaxSize )
    {
        int new_size;
        new_size = pq->MaxSize + 256;
        pq->Elements = (pq_element_t *)ourrealloc( pq->Elements, sizeof(pq_element_t) * (pq->MaxSize+1), sizeof(pq_element_t) * (new_size+1));
        pq->MaxSize = new_size;
    }
    
    {
        /* set i to the first unused element and increment CurrentSize */

        i = (pq->CurrentSize += 1);

        /* while the parent of the space we're putting the new node into is worse than
           our new node, swap the space with the worse node. We keep doing that until we
           get to a worse node or until we get to the top

           note that we also can sort so that the minimum elements bubble up so we need to loops
           with the comparison operator flipped... */

        if( pq->IsAscendingHeap == TRUE )
        {

#if 0            
            while( ( i==PQ_FIRST_ENTRY ?
                     (pq->MaxRating) /* return biggest possible rating if first element */
                     :
                     (pq->Elements[ PQ_PARENT_INDEX(i) ].rating )
                   ) 
                   < r 
                 )
#endif
            while ( (i == PQ_FIRST_ENTRY) ?
                        0 :
                        (pq->cmp(pq->Elements[ PQ_PARENT_INDEX(i) ], item, pq->context) < 0)
                  )
            {
                pq->Elements[ i ] = pq->Elements[ PQ_PARENT_INDEX(i) ];
            
                i = PQ_PARENT_INDEX(i);
            }
        }
        else
        {
#if 0            
            while( ( i==PQ_FIRST_ENTRY ?
                     (pq->MaxRating) /* return biggest possible rating if first element */
                     :
                     (pq->Elements[ PQ_PARENT_INDEX(i) ].rating )
                   ) 
                   > r 
                 )
#endif
            while ( (i == PQ_FIRST_ENTRY) ?
                    0 :
                    (pq->cmp(pq->Elements[ PQ_PARENT_INDEX(i) ], item, pq->context) > 0)
                  )
            {
                pq->Elements[ i ] = pq->Elements[ PQ_PARENT_INDEX(i) ];
            
                i = PQ_PARENT_INDEX(i);
            }
        }


        /* then add the element at the space we created. */
        pq->Elements[i] = item;
        /* pq->Elements[i].rating = r; */
    }

    return TRUE;

}