From: Matthias Braun Date: Wed, 24 Sep 2008 12:10:04 +0000 (+0000) Subject: cleanup pqueue a little bit X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=960fa89873d6fd56259d4b44d5ea9541335b0232;p=libfirm cleanup pqueue a little bit [r22235] --- diff --git a/include/libfirm/adt/pqueue.h b/include/libfirm/adt/pqueue.h index 7ee987338..05a0d3341 100644 --- a/include/libfirm/adt/pqueue.h +++ b/include/libfirm/adt/pqueue.h @@ -28,19 +28,19 @@ #ifndef FIRM_ADT_PQUEUE_H #define FIRM_ADT_PQUEUE_H -typedef struct _pqueue_t pqueue; +typedef struct _pqueue_t pqueue_t; /** * Creates a new priority queue. * @return A priority queue of initial length 0. */ -pqueue *new_pqueue(void); +pqueue_t *new_pqueue(void); /** * Frees all memory allocated by the priority queue. * @param q The priority queue to destroy. */ -void del_pqueue(pqueue *q); +void del_pqueue(pqueue_t *q); /** * Inserts a new element into a priority queue. @@ -48,27 +48,27 @@ void del_pqueue(pqueue *q); * @param data The actual data which should be stored in the queue. * @param key The priority for the data. */ -void pqueue_put(pqueue *q, void *data, int key); +void pqueue_put(pqueue_t *q, void *data, int key); /** * Returns and removes the first element, ie. that one with the highest priority, from the queue. * @param q The priority queue. * @return The first element of the queue. Asserts if queue is empty. */ -void *pqueue_get(pqueue *q); +void *pqueue_pop_front(pqueue_t *q); /** * Get the length of the priority queue. * @param q The priority queue. * @return The length of the queue. */ -int pqueue_length(pqueue *q); +int pqueue_length(const pqueue_t *q); /** * Returns true if queue is empty. * @param q The priority queue. * @return 1 if the queue is empty, 0 otherwise. */ -int pqueue_empty(pqueue *q); +int pqueue_empty(const pqueue_t *q); #endif diff --git a/ir/adt/pqueue.c b/ir/adt/pqueue.c index 6e43abf7c..3ce0f1e33 100644 --- a/ir/adt/pqueue.c +++ b/ir/adt/pqueue.c @@ -56,7 +56,7 @@ struct _pqueue_t { * Enforces the heap characteristics if the queue * starting from element at position @p pos. */ -static void pqueue_heapify(pqueue *q, unsigned pos) { +static void pqueue_heapify(pqueue_t *q, unsigned pos) { unsigned len = ARR_LEN(q->elems); while (pos * 2 < len) { @@ -85,7 +85,7 @@ static void pqueue_heapify(pqueue *q, unsigned pos) { /** * Sifts up a newly inserted element at position @p pos. */ -static void pqueue_sift_up(pqueue *q, unsigned pos) { +static void pqueue_sift_up(pqueue_t *q, unsigned pos) { while(q->elems[pos].key > q->elems[pos / 2].key) { pqueue_el_t tmp; @@ -97,32 +97,18 @@ static void pqueue_sift_up(pqueue *q, unsigned pos) { } } -/** - * Creates a new priority queue. - * @return A priority queue of initial length 0. - */ -pqueue *new_pqueue(void) { - pqueue *res = xmalloc(sizeof(*res)); +pqueue_t *new_pqueue(void) { + pqueue_t *res = xmalloc(sizeof(*res)); res->elems = NEW_ARR_F(pqueue_el_t, 0); return res; } -/** - * Frees all memory allocated by the priority queue. - * @param q The priority queue to destroy. - */ -void del_pqueue(pqueue *q) { +void del_pqueue(pqueue_t *q) { DEL_ARR_F(q->elems); free(q); } -/** - * Inserts a new element into a priority queue. - * @param q The priority queue the element should be inserted to. - * @param data The actual data which should be stored in the queue. - * @param key The priority for the data. - */ -void pqueue_put(pqueue *q, void *data, int key) { +void pqueue_put(pqueue_t *q, void *data, int key) { pqueue_el_t el; el.data = data; @@ -133,12 +119,7 @@ void pqueue_put(pqueue *q, void *data, int key) { pqueue_sift_up(q, ARR_LEN(q->elems) - 1); } -/** - * Returns and removes the first element, ie. that one with the highest priority, from the queue. - * @param q The priority queue. - * @return The first element of the queue. Asserts if queue is empty. - */ -void *pqueue_get(pqueue *q) { +void *pqueue_pop_front(pqueue_t *q) { switch(ARR_LEN(q->elems)) { case 0: assert(0 && "Attempt to retrieve element from empty priority queue."); @@ -161,20 +142,10 @@ void *pqueue_get(pqueue *q) { } } -/** - * Get the length of the priority queue. - * @param q The priority queue. - * @return The length of the queue. - */ -int pqueue_length(pqueue *q) { +int pqueue_length(const pqueue_t *q) { return ARR_LEN(q->elems); } -/** - * Returns true if queue is empty. - * @param q The priority queue. - * @return 1 if the queue is empty, 0 otherwise. - */ -int pqueue_empty(pqueue *q) { +int pqueue_empty(const pqueue_t *q) { return ARR_LEN(q->elems) == 0; } diff --git a/ir/be/becopyheur4.c b/ir/be/becopyheur4.c index 91243cc57..bfad18be7 100644 --- a/ir/be/becopyheur4.c +++ b/ir/be/becopyheur4.c @@ -119,7 +119,7 @@ typedef struct _co_mst_env_t { int k; /**< number of non-ignore registers in class */ bitset_t *ignore_regs; /**< set containing all global ignore registers */ ir_phase ph; /**< phase object holding data for nodes */ - pqueue *chunks; /**< priority queue for chunks */ + pqueue_t *chunks; /**< priority queue for chunks */ pset *chunkset; /**< set holding all chunks */ be_ifg_t *ifg; /**< the interference graph */ const arch_env_t *aenv; /**< the arch environment */ @@ -711,7 +711,7 @@ static void build_affinity_chunks(co_mst_env_t *env) { static __attribute__((unused)) void chunk_order_nodes(co_mst_env_t *env, aff_chunk_t *chunk) { - pqueue *grow = new_pqueue(); + pqueue_t *grow = new_pqueue(); const ir_node *max_node = NULL; int max_weight = 0; int i; @@ -746,7 +746,7 @@ static __attribute__((unused)) void chunk_order_nodes(co_mst_env_t *env, aff_chu bitset_remv_irn(visited, max_node); i = 0; while (!pqueue_empty(grow)) { - ir_node *irn = pqueue_get(grow); + ir_node *irn = pqueue_pop_front(grow); affinity_node_t *an = get_affinity_info(env->co, irn); neighb_t *neigh; @@ -1438,7 +1438,7 @@ int co_solve_heuristic_mst(copy_opt_t *co) { /* color chunks as long as there are some */ while (! pqueue_empty(mst_env.chunks)) { - aff_chunk_t *chunk = pqueue_get(mst_env.chunks); + aff_chunk_t *chunk = pqueue_pop_front(mst_env.chunks); color_aff_chunk(&mst_env, chunk); DB((dbg, LEVEL_4, "<<<====== Coloring chunk (%u) done\n", chunk->id));