list.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * This list header defines a simple
  3. * thread-safe object-oriented single
  4. * linked list data structure with
  5. * merge sort and duplicates removal
  6. * functionality.
  7. * Copyright (C) 1989-2089 Sergey Sergeevich Tsybanov
  8. *
  9. * This list program is free software:
  10. * you can redistribute it and/or
  11. * modify it under the terms of the
  12. * GNU Affero General Public License
  13. * as published by the Free Software
  14. * Foundation, either version 3 of
  15. * the License, or (at your option)
  16. * any later version.
  17. *
  18. * This list program is distributed in
  19. * the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without
  21. * even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A
  23. * PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License
  25. * for more details.
  26. *
  27. * You should have received a copy of
  28. * the GNU Affero General Public License
  29. * along with this list program. If not,
  30. * see <https://www.gnu.org/licenses/>.
  31. */
  32. #ifndef LIST_H
  33. #include <limits.h>
  34. #include <pthread.h>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #define LIST_H
  38. struct link;
  39. struct list;
  40. /*
  41. * The function assign_list assigns a
  42. * struct list to another struct list.
  43. * The function takes two struct list
  44. * pointers to constant addresses of
  45. * struct list pointers as arguments.
  46. * The function returns a pointer
  47. * to a struct list.
  48. */
  49. struct list* assign_list( struct list **const assignTo,
  50. struct list **const assignIt);
  51. /*
  52. * The function copy_list creates a
  53. * copy of a struct list.
  54. * The function takes a struct list
  55. * pointer to a constant address of
  56. * a struct list pointer as an
  57. * argument. The function returns
  58. * a pointer to a struct list.
  59. */
  60. struct list* copy_list( struct list **const copyIt);
  61. /*
  62. * The function create_list allocates
  63. * memory and initializes a struct
  64. * list. The function takes no
  65. * arguments. The function returns
  66. * a pointer to a struct list.
  67. */
  68. struct list* create_list( void);
  69. /*
  70. * The function destroy_list deallocates
  71. * a struct list. The function takes a
  72. * struct list pointer to a constant
  73. * address of a struct list pointer as
  74. * an argument. The function returns the
  75. * character '\x00' on failure.
  76. * The function returns the
  77. * character '\x01' on success.
  78. */
  79. char destroy_list( struct list **const destroyIt);
  80. /*
  81. * The function get_length_list returns
  82. * the length of the struct list. The
  83. * function takes a struct list pointer
  84. * to a constant address of a struct
  85. * list pointer as an argument.
  86. * The function returns a long negative
  87. * one on failure. The function returns
  88. * a long length value on success.
  89. */
  90. long get_length_list( struct list **const this);
  91. /*
  92. * The function insert_link_list inserts
  93. * a struct link into a struct list.
  94. * The function takes a struct list
  95. * pointer to a constant address of a
  96. * struct list pointer, a constant long
  97. * value and a constant long index as
  98. * arguments. The function returns the
  99. * character '\x00' on failure.
  100. * The function returns the
  101. * character '\x01' on success.
  102. */
  103. char insert_link_list( struct list **const this,
  104. const long insertIt, const long index);
  105. /*
  106. * The function print_list outputs
  107. * a struct list to the standard
  108. * output. The function takes a
  109. * struct list pointer to a
  110. * constant address of a struct
  111. * list pointer. The function
  112. * returns the character '\x00'
  113. * on failure. The function
  114. * returns the character '\x01'
  115. * on success.
  116. */
  117. char print_list( struct list **const this);
  118. /*
  119. * The function remove_duplicates_list removes
  120. * duplicate values from a sorted struct list.
  121. * The function takes a struct list pointer to
  122. * a constant address of a struct list pointer.
  123. * The function returns the character '\x00'
  124. * on failure. The function returns the
  125. * character '\x01' on success.
  126. */
  127. char remove_duplicates_list( struct list **const this);
  128. /*
  129. * The function remove_link_list removes
  130. * a struct link from a struct list.
  131. * The function takes a struct list
  132. * pointer to a constant address of a
  133. * struct list pointer, a constant long
  134. * value and a constant long index as
  135. * arguments. The function returns the
  136. * character '\x00' on failure.
  137. * The function returns the
  138. * character '\x01' on success.
  139. */
  140. char remove_link_list( struct list **const this,
  141. const long deleteIt, const long index);
  142. /*
  143. * The function sort_list sorts
  144. * a struct list with iterative
  145. * merge sort. The function
  146. * takes a struct list pointer
  147. * to a constant address of a
  148. * struct list pointer as an
  149. * argument. The function
  150. * returns the character '\x00'
  151. * on failure. The function
  152. * returns the character '\x01'
  153. * on success.
  154. */
  155. char sort_list( struct list **const sortIt);
  156. #endif