list.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef _lub_list_h
  2. #define _lub_list_h
  3. #include <stddef.h>
  4. /****************************************************************
  5. * TYPE DEFINITIONS
  6. **************************************************************** */
  7. typedef struct lub_list_node_s lub_list_node_t;
  8. /**
  9. * This type defines a callback function which will compare two nodes
  10. * with each other
  11. *
  12. * \param clientnode the client node to compare
  13. * \param clientkey the key to compare with a node
  14. *
  15. * \return
  16. * <0 if clientnode < clientkey;
  17. * 0 if clientnode == clientkey;
  18. * >0 if clientnode > clientkey
  19. */
  20. typedef int lub_list_compare_fn(const void *first, const void *second);
  21. /**
  22. * This type represents a list instance
  23. */
  24. typedef struct lub_list_s lub_list_t;
  25. /**
  26. * This is used to perform iterations of a list
  27. */
  28. typedef struct lub_list_node_s lub_list_iterator_t;
  29. /****************************************************************
  30. * LIST OPERATIONS
  31. **************************************************************** */
  32. /**
  33. * This operation initialises an instance of a list.
  34. */
  35. extern lub_list_t *lub_list_new(lub_list_compare_fn compareFn);
  36. /**
  37. * This operation is called to initialise a "clientnode" ready for
  38. * insertion into a tree. This is only required once after the memory
  39. * for a node has been allocated.
  40. *
  41. * \pre none
  42. *
  43. * \post The node is ready to be inserted into a tree.
  44. */
  45. extern lub_list_node_t *lub_list_node_new(void *data);
  46. /*****************************************
  47. * NODE MANIPULATION OPERATIONS
  48. ***************************************** */
  49. /**
  50. * This operation adds a client node to the specified tree.
  51. *
  52. * \pre The tree must be initialised
  53. * \pre The clientnode must be initialised
  54. *
  55. * \return
  56. * 0 if the "clientnode" is added correctly to the tree.
  57. * If another "clientnode" already exists in the tree with the same key, then
  58. * -1 is returned, and the tree remains unchanged.
  59. *
  60. * \post If the bintree "node" is already part of a tree, then an
  61. * assert will fire.
  62. */
  63. void lub_list_free(lub_list_t *list);
  64. void lub_list_node_free(lub_list_node_t *node);
  65. inline lub_list_node_t *lub_list__get_head(lub_list_t *list);
  66. inline lub_list_node_t *lub_list__get_tail(lub_list_t *list);
  67. lub_list_node_t *lub_list_node__get_prev(lub_list_node_t *node);
  68. lub_list_node_t *lub_list_node__get_next(lub_list_node_t *node);
  69. void *lub_list_node__get_data(lub_list_node_t *node);
  70. lub_list_node_t *lub_list_iterator_init(lub_list_t *list);
  71. lub_list_node_t *lub_list_iterator_next(lub_list_node_t *node);
  72. lub_list_node_t *lub_list_iterator_prev(lub_list_node_t *node);
  73. lub_list_node_t *lub_list_add(lub_list_t *list, void *data);
  74. void lub_list_del(lub_list_t *list, lub_list_node_t *node);
  75. #endif /* _lub_list_h */