list.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. @file list.c
  3. @brief ENet linked list functions
  4. */
  5. #define ENET_BUILDING_LIB 1
  6. #include "enet/enet.h"
  7. /**
  8. @defgroup list ENet linked list utility functions
  9. @ingroup private
  10. @{
  11. */
  12. void
  13. enet_list_clear (ENetList * list)
  14. {
  15. list -> sentinel.next = & list -> sentinel;
  16. list -> sentinel.previous = & list -> sentinel;
  17. }
  18. ENetListIterator
  19. enet_list_insert (ENetListIterator position, void * data)
  20. {
  21. ENetListIterator result = (ENetListIterator) data;
  22. result -> previous = position -> previous;
  23. result -> next = position;
  24. result -> previous -> next = result;
  25. position -> previous = result;
  26. return result;
  27. }
  28. void *
  29. enet_list_remove (ENetListIterator position)
  30. {
  31. position -> previous -> next = position -> next;
  32. position -> next -> previous = position -> previous;
  33. return position;
  34. }
  35. ENetListIterator
  36. enet_list_move (ENetListIterator position, void * dataFirst, void * dataLast)
  37. {
  38. ENetListIterator first = (ENetListIterator) dataFirst,
  39. last = (ENetListIterator) dataLast;
  40. first -> previous -> next = last -> next;
  41. last -> next -> previous = first -> previous;
  42. first -> previous = position -> previous;
  43. last -> next = position;
  44. first -> previous -> next = first;
  45. position -> previous = last;
  46. return first;
  47. }
  48. size_t
  49. enet_list_size (ENetList * list)
  50. {
  51. size_t size = 0;
  52. ENetListIterator position;
  53. for (position = enet_list_begin (list);
  54. position != enet_list_end (list);
  55. position = enet_list_next (position))
  56. ++ size;
  57. return size;
  58. }
  59. /** @} */