queue.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*!
  2. Temelia - Queue interface.
  3. Copyright (C) 2008, 2009 Ceata (http://cod.ceata.org/proiecte/temelia).
  4. @author Dascalu Laurentiu
  5. This program is free software; you can redistribute it and
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 3
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17. #ifndef QUEUE_H_
  18. #define QUEUE_H_
  19. #include "platform.h"
  20. struct _queue_t;
  21. typedef struct _queue_t *queue_t;
  22. /*!
  23. * @brief Constructor - Allocates a queue with a given size. By default, queue won't adjust
  24. * the size then it's full, in order to do this the capacityIncrement to 1.
  25. * Complexity O(1)
  26. *
  27. * @param Queue size
  28. */
  29. DECLSPEC queue_t queue_new(int size);
  30. /*!
  31. * @brief Destructor - Frees memory occupied by queue.
  32. * Complexity O(n)
  33. *
  34. * @param Queue
  35. */
  36. DECLSPEC void queue_delete(queue_t queue);
  37. /*!
  38. * @brief Returns the keys number of queue.
  39. * Complexity O(1)
  40. *
  41. * @param Queue
  42. */
  43. DECLSPEC int queue_get_size(queue_t queue);
  44. /*!
  45. * @brief Returns the capacity ( maximum size ) of queue.
  46. * Complexity O(1)
  47. *
  48. * @param Queue
  49. */
  50. DECLSPEC int queue_get_capacity(queue_t queue);
  51. /*!
  52. * @brief Returns the capacity increment value; depending on it
  53. * the queue can increase it's size, by inserting keys, or not.
  54. * Complexity O(1)
  55. *
  56. * @param Queue
  57. */
  58. DECLSPEC int queue_get_capacity_increment(queue_t queue);
  59. /*!
  60. * @brief Sets increase variable in order to allow the insertions function to
  61. * reallocate when queue becomes full.
  62. * Complexity O(1)
  63. *
  64. * @param Queue
  65. * @param 1 if the size increasing operation is allowed and 0 otherwise
  66. */
  67. DECLSPEC void queue_set_capacity_increment(queue_t queue, int new_increase);
  68. /*!
  69. * @brief Returns 1 if the queue is empty and 0 if it isn't.
  70. * Complexity O(1)
  71. *
  72. * @param Queue
  73. */
  74. DECLSPEC int queue_is_empty(queue_t queue);
  75. /*!
  76. * @brief Returns 1 if the queue is full and 0 if it ins't.
  77. * Complexity O(1)
  78. *
  79. * @param Queue
  80. */
  81. DECLSPEC int queue_is_full(queue_t queue);
  82. /*!
  83. * @brief Inserts an key to front of queue.
  84. * Complexity O(1)
  85. *
  86. * @param Queue
  87. * @param Key
  88. */
  89. DECLSPEC void queue_push_front(queue_t queue, void *key);
  90. /*!
  91. * @brief Inserts an key to the end of queue.
  92. * Complexity O(1)
  93. *
  94. * @param Queue
  95. * @param Key
  96. */
  97. DECLSPEC void queue_push_back(queue_t queue, void *key);
  98. /*!
  99. * @brief Returns the reference to the first node of the queue;
  100. * you should cast this pointer to doubly_linked_list_iterator_t.
  101. * Complexity O(1)
  102. *
  103. * @param Queue
  104. */
  105. DECLSPEC void *queue_get_begin(queue_t queue);
  106. /*!
  107. * @brief Returns the reference to the last node of the queue;
  108. * you should cast this pointer to doubly_linked_list_iterator_t
  109. * Complexity O(1)
  110. *
  111. * @param Queue
  112. */
  113. DECLSPEC void *queue_get_end();
  114. /*!
  115. * @brief Sets a new first node for queue.
  116. * Complexity O(1)
  117. *
  118. * @param Queue
  119. */
  120. DECLSPEC void queue_set_begin(queue_t queue, void *begin);
  121. /*!
  122. * @brief Sets a new last node for queue.
  123. * Complexity O(1)
  124. *
  125. * @param Queue
  126. */
  127. DECLSPEC void queue_set_end(queue_t queue, void *end);
  128. /*!
  129. * @brief Returns the key from the peek of queue.
  130. * Complexity O(1)
  131. *
  132. * @param Queue
  133. */
  134. DECLSPEC void *queue_get_front(queue_t queue);
  135. /*!
  136. * @brief Returns the key from the end of queue.
  137. * Complexity O(1)
  138. *
  139. * @param Queue
  140. */
  141. DECLSPEC void *queue_get_back(queue_t queue);
  142. /*!
  143. * @brief Removes the front key.
  144. * Complexity O(1)
  145. *
  146. * @param Queue
  147. */
  148. DECLSPEC void queue_pop_front(queue_t queue);
  149. /*!
  150. * @brief Removes the key from the end of the queue.
  151. * Complexity O(1)
  152. *
  153. * @param Queue
  154. */
  155. DECLSPEC void queue_pop_back(queue_t queue);
  156. /*!
  157. * @brief Lists the keys from the queue in the given order. If order=1 the functions
  158. * prints the keys in the natural order (FIFO) and if order=-1 it prints the
  159. * keys in the reverse natural order.
  160. * Complexity O(n)
  161. *
  162. * @param Queue
  163. * @param Pointer to iterating function
  164. * @param Pointer to context
  165. * @param Printing order
  166. */
  167. DECLSPEC void queue_iterate(queue_t queue, void key_handler(void *key, void *context),
  168. void *context, int order);
  169. #endif /* QUEUE_H_ */