Main MRPT website > C++ reference for MRPT 1.9.9
minpq.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #ifndef MINPQ_H
11 #define MINPQ_H
12 
13 #include <stdlib.h>
14 
15 /******************************* Defs and macros *****************************/
16 
17 /* initial # of priority queue elements for which to allocate space */
18 #define MINPQ_INIT_NALLOCD 512
19 
20 /********************************** Structures *******************************/
21 
22 /** an element in a minimizing priority queue */
23 struct pq_node
24 {
25  void* data;
26  int key;
27 };
28 
29 /** a minimizing priority queue */
30 struct min_pq
31 {
32  struct pq_node* pq_array; /* array containing priority queue */
33  int nallocd; /* number of elements allocated */
34  int n; /**< number of elements in pq */
35 };
36 
37 /*************************** Function Prototypes *****************************/
38 
39 /**
40 Creates a new minimizing priority queue.
41 */
42 extern struct min_pq* minpq_init();
43 
44 /**
45 Inserts an element into a minimizing priority queue.
46 
47 @param min_pq a minimizing priority queue
48 @param data the data to be inserted
49 @param key the key to be associated with \a data
50 
51 @return Returns 0 on success or 1 on failure.
52 */
53 extern int minpq_insert(struct min_pq* min_pq, void* data, int key);
54 
55 /**
56 Returns the element of a minimizing priority queue with the smallest key
57 without removing it from the queue.
58 
59 @param min_pq a minimizing priority queue
60 
61 @return Returns the element of \a min_pq with the smallest key or NULL
62  if \a min_pq is empty
63 */
64 extern void* minpq_get_min(struct min_pq* min_pq);
65 
66 /**
67 Removes and returns the element of a minimizing priority queue with the
68 smallest key.
69 
70 @param min_pq a minimizing priority queue
71 
72 @return Returns the element of \a min_pq with the smallest key of NULL
73  if \a min_pq is empty
74 */
75 extern void* minpq_extract_min(struct min_pq* min_pq);
76 
77 /**
78 De-allocates the memory held by a minimizing priorioty queue
79 
80 @param min_pq pointer to a minimizing priority queue
81 */
82 extern void minpq_release(struct min_pq** min_pq);
83 
84 #endif
a minimizing priority queue
Definition: minpq.h:30
struct min_pq * minpq_init()
Creates a new minimizing priority queue.
int n
number of elements in pq
Definition: minpq.h:34
struct pq_node * pq_array
Definition: minpq.h:32
void * data
Definition: minpq.h:25
void minpq_release(struct min_pq **min_pq)
De-allocates the memory held by a minimizing priorioty queue
int minpq_insert(struct min_pq *min_pq, void *data, int key)
Inserts an element into a minimizing priority queue.
int nallocd
Definition: minpq.h:33
void * minpq_extract_min(struct min_pq *min_pq)
Removes and returns the element of a minimizing priority queue with the smallest key...
void * minpq_get_min(struct min_pq *min_pq)
Returns the element of a minimizing priority queue with the smallest key without removing it from th...
int key
Definition: minpq.h:26
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3546
an element in a minimizing priority queue
Definition: minpq.h:23



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019