2 * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * @author Christian Wuerdig
24 * @brief Implementation of a priority queue. This is the ported version of
25 the original Java implementation by Matthias Braun.
27 #ifndef FIRM_ADT_PQUEUE_H
28 #define FIRM_ADT_PQUEUE_H
34 * @defgroup pqueue Priority Queue
36 * Implementation based on a heap datastructure
41 typedef struct pqueue_t pqueue_t;
44 * Creates a new priority queue.
45 * @return A priority queue of initial length 0.
47 FIRM_API pqueue_t *new_pqueue(void);
50 * Frees all memory allocated by the priority queue.
51 * @param q The priority queue to destroy.
53 FIRM_API void del_pqueue(pqueue_t *q);
56 * Inserts a new element into a priority queue.
57 * @param q The priority queue the element should be inserted to.
58 * @param data The actual data which should be stored in the queue.
59 * @param priority The priority for the data.
61 FIRM_API void pqueue_put(pqueue_t *q, void *data, int priority);
64 * Returns and removes the first element, ie. that one with the highest priority, from the queue.
65 * @param q The priority queue.
66 * @return The first element of the queue. Asserts if queue is empty.
68 FIRM_API void *pqueue_pop_front(pqueue_t *q);
71 * Get the length of the priority queue.
72 * @param q The priority queue.
73 * @return The length of the queue.
75 FIRM_API size_t pqueue_length(const pqueue_t *q);
78 * Returns true if queue is empty.
79 * @param q The priority queue.
80 * @return 1 if the queue is empty, 0 otherwise.
82 FIRM_API int pqueue_empty(const pqueue_t *q);