iterator.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*!
  2. Temelia - Iterators interface; linked list iterator and doubly linked list iterator.
  3. Copyright (C) 2008 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 ITERATOR_H_
  18. #define ITERATOR_H_
  19. #include "platform.h"
  20. struct _linked_list_iterator_t;
  21. struct _doubly_linked_list_iterator_t;
  22. typedef struct _linked_list_iterator_t *linked_list_iterator_t;
  23. typedef struct _doubly_linked_list_iterator_t *doubly_linked_list_iterator_t;
  24. /*!
  25. * @brief Returns an iterator having default key and default next pointer.
  26. * Complexity O(1)
  27. *
  28. * @param Key
  29. * @param Next
  30. */
  31. DECLSPEC linked_list_iterator_t linked_list_iterator_new(void *default_key,
  32. linked_list_iterator_t default_next);
  33. /*!
  34. * @brief Frees the memory occuppied by iterator.
  35. * Complexity O(1)
  36. *
  37. * @param Iterator
  38. */
  39. DECLSPEC void linked_list_iterator_delete(linked_list_iterator_t it);
  40. /*!
  41. * @brief Returns the key from iterator.
  42. * Complexity O(1)
  43. *
  44. * @param Iterator
  45. */
  46. DECLSPEC void *linked_list_iterator_get_key(linked_list_iterator_t it);
  47. /*!
  48. * @brief Returns the next iterator pointer.
  49. * Complexity O(1)
  50. *
  51. * @param Iterator
  52. */
  53. DECLSPEC linked_list_iterator_t linked_list_iterator_get_next(
  54. linked_list_iterator_t it);
  55. /*!
  56. * @brief Sets the key from iterator.
  57. * Complexity O(1)
  58. *
  59. * @param Iterator
  60. * @param New key
  61. */
  62. DECLSPEC void linked_list_iterator_set_key(linked_list_iterator_t it, void *new_key);
  63. /*!
  64. * @brief Sets the next iterator pointer.
  65. * Complexity O(1)
  66. *
  67. * @param Iterator
  68. * @param New next pointer
  69. */
  70. DECLSPEC void linked_list_iterator_set_next(linked_list_iterator_t it,
  71. linked_list_iterator_t new_next);
  72. /*!
  73. * @brief Joins three iterators : left -> middle -> right; the
  74. * function do: left->next = middle; middle->next = right; each
  75. * instruction is executed only if the left statement iterator
  76. * is not NULL.
  77. * Complexity O(1)
  78. *
  79. * @param Left iterator
  80. * @param Middle iterator
  81. * @param Right iterator
  82. */
  83. DECLSPEC void linked_list_iterator_join(linked_list_iterator_t left,
  84. linked_list_iterator_t middle, linked_list_iterator_t right);
  85. /*!
  86. * @brief Splits the link from three iterators:
  87. * left -> middle -> right => left, middle, right.
  88. * @see linked_list_iterator_join for addional informations
  89. * about those iterators.
  90. * Complexity O(1)
  91. *
  92. * @param Left iterator
  93. * @param Middle iterator
  94. * @param Right iterator
  95. */
  96. DECLSPEC void linked_list_iterator_split(linked_list_iterator_t left,
  97. linked_list_iterator_t middle, linked_list_iterator_t right);
  98. /*!
  99. * @brief Returns an iterator with default key and prev, next iterators.
  100. * Complexity O(1)
  101. *
  102. * @param Key
  103. * @param Previous iterator
  104. * @param Next iterator
  105. */
  106. DECLSPEC doubly_linked_list_iterator_t doubly_linked_list_iterator_new(void *key,
  107. doubly_linked_list_iterator_t default_prev,
  108. doubly_linked_list_iterator_t default_next);
  109. /*!
  110. * @brief Frees the memory occuppied by iterator.
  111. * Complexity O(1)
  112. *
  113. * @param Iterator
  114. */
  115. DECLSPEC void doubly_linked_list_iterator_delete(doubly_linked_list_iterator_t it);
  116. /*!
  117. * @brief Returns the key from iterator.
  118. * Complexity O(1)
  119. *
  120. * @param Iterator
  121. */
  122. DECLSPEC void *doubly_linked_list_iterator_get_key(doubly_linked_list_iterator_t it);
  123. /*!
  124. * @brief Returns the previous iterator pointer.
  125. * Complexity O(1)
  126. *
  127. * @param Iterator
  128. */
  129. DECLSPEC doubly_linked_list_iterator_t doubly_linked_list_iterator_get_prev(
  130. doubly_linked_list_iterator_t it);
  131. /*!
  132. * @brief Returns the next iterator pointer.
  133. * Complexity O(1)
  134. *
  135. * @param Iterator
  136. */
  137. DECLSPEC doubly_linked_list_iterator_t doubly_linked_list_iterator_get_next(
  138. doubly_linked_list_iterator_t it);
  139. /*!
  140. * @brief Sets the key from iterator.
  141. * Complexity O(1)
  142. *
  143. * @param Iterator
  144. * @param Key
  145. */
  146. DECLSPEC void doubly_linked_list_iterator_set_key(doubly_linked_list_iterator_t it,
  147. void *key);
  148. /*!
  149. * @brief Sets the previous iterator pointer.
  150. * Complexity O(1)
  151. *
  152. * @param Iterator
  153. * @param Previous iterator
  154. */
  155. DECLSPEC void doubly_linked_list_iterator_set_prev(doubly_linked_list_iterator_t it,
  156. doubly_linked_list_iterator_t prev);
  157. /*!
  158. * @brief Sets the next iterator pointer.
  159. * Complexity O(1)
  160. *
  161. * @param Iterator
  162. * @param Next iterator
  163. */
  164. DECLSPEC void doubly_linked_list_iterator_set_next(doubly_linked_list_iterator_t it,
  165. doubly_linked_list_iterator_t next);
  166. /*!
  167. * @brief Joins three iterators:
  168. * left, middle, right => left <-> middle <-> right;
  169. * each iterator can be NULL.
  170. * Complexity O(1)
  171. *
  172. * @param Left iterator
  173. * @param Middle iterator
  174. * @param Right iterator
  175. */
  176. DECLSPEC void doubly_linked_list_iterator_join(doubly_linked_list_iterator_t left,
  177. doubly_linked_list_iterator_t middle,
  178. doubly_linked_list_iterator_t right);
  179. /*!
  180. * @brief Splits three iterator:
  181. * left <-> middle <-> right => left, middle, right;
  182. * each iterator can be NULL.
  183. * Complexity O(1)
  184. *
  185. * @param Left iterator
  186. * @param Middle iterator
  187. * @param Right iterator
  188. */
  189. DECLSPEC void doubly_linked_list_iterator_spit(doubly_linked_list_iterator_t left,
  190. doubly_linked_list_iterator_t middle,
  191. doubly_linked_list_iterator_t right);
  192. #endif /* ITERATOR_H_ */