Main MRPT website > C++ reference for MRPT 1.5.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 
11 #ifndef MINPQ_H
12 #define MINPQ_H
13 
14 #include <stdlib.h>
15 
16 
17 /******************************* Defs and macros *****************************/
18 
19 /* initial # of priority queue elements for which to allocate space */
20 #define MINPQ_INIT_NALLOCD 512
21 
22 /********************************** Structures *******************************/
23 
24 /** an element in a minimizing priority queue */
25 struct pq_node
26 {
27  void* data;
28  int key;
29 };
30 
31 
32 /** a minimizing priority queue */
33 struct min_pq
34 {
35  struct pq_node* pq_array; /* array containing priority queue */
36  int nallocd; /* number of elements allocated */
37  int n; /**< number of elements in pq */
38 };
39 
40 
41 /*************************** Function Prototypes *****************************/
42 
43 /**
44 Creates a new minimizing priority queue.
45 */
46 extern struct min_pq* minpq_init();
47 
48 
49 /**
50 Inserts an element into a minimizing priority queue.
51 
52 @param min_pq a minimizing priority queue
53 @param data the data to be inserted
54 @param key the key to be associated with \a data
55 
56 @return Returns 0 on success or 1 on failure.
57 */
58 extern int minpq_insert( struct min_pq* min_pq, void* data, int key );
59 
60 
61 /**
62 Returns the element of a minimizing priority queue with the smallest key
63 without removing it from the queue.
64 
65 @param min_pq a minimizing priority queue
66 
67 @return Returns the element of \a min_pq with the smallest key or NULL
68  if \a min_pq is empty
69 */
70 extern void* minpq_get_min( struct min_pq* min_pq );
71 
72 
73 /**
74 Removes and returns the element of a minimizing priority queue with the
75 smallest key.
76 
77 @param min_pq a minimizing priority queue
78 
79 @return Returns the element of \a min_pq with the smallest key of NULL
80  if \a min_pq is empty
81 */
82 extern void* minpq_extract_min( struct min_pq* min_pq );
83 
84 
85 /**
86 De-allocates the memory held by a minimizing priorioty queue
87 
88 @param min_pq pointer to a minimizing priority queue
89 */
90 extern void minpq_release( struct min_pq** min_pq );
91 
92 
93 #endif
a minimizing priority queue
Definition: minpq.h:33
struct min_pq * minpq_init()
Creates a new minimizing priority queue.
int n
number of elements in pq
Definition: minpq.h:37
struct pq_node * pq_array
Definition: minpq.h:35
void * data
Definition: minpq.h:27
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:36
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:28
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3520
an element in a minimizing priority queue
Definition: minpq.h:25



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020