zend_llist.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andi Gutmans <andi@php.net> |
  16. | Zeev Suraski <zeev@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #ifndef ZEND_LLIST_H
  20. #define ZEND_LLIST_H
  21. typedef struct _zend_llist_element {
  22. struct _zend_llist_element *next;
  23. struct _zend_llist_element *prev;
  24. char data[1]; /* Needs to always be last in the struct */
  25. } zend_llist_element;
  26. typedef void (*llist_dtor_func_t)(void *);
  27. typedef int (*llist_compare_func_t)(const zend_llist_element **, const zend_llist_element **);
  28. typedef void (*llist_apply_with_args_func_t)(void *data, int num_args, va_list args);
  29. typedef void (*llist_apply_with_arg_func_t)(void *data, void *arg);
  30. typedef void (*llist_apply_func_t)(void *);
  31. typedef struct _zend_llist {
  32. zend_llist_element *head;
  33. zend_llist_element *tail;
  34. size_t count;
  35. size_t size;
  36. llist_dtor_func_t dtor;
  37. unsigned char persistent;
  38. zend_llist_element *traverse_ptr;
  39. } zend_llist;
  40. typedef zend_llist_element* zend_llist_position;
  41. BEGIN_EXTERN_C()
  42. ZEND_API void zend_llist_init(zend_llist *l, size_t size, llist_dtor_func_t dtor, unsigned char persistent);
  43. ZEND_API void zend_llist_add_element(zend_llist *l, void *element);
  44. ZEND_API void zend_llist_prepend_element(zend_llist *l, void *element);
  45. ZEND_API void zend_llist_del_element(zend_llist *l, void *element, int (*compare)(void *element1, void *element2));
  46. ZEND_API void zend_llist_destroy(zend_llist *l);
  47. ZEND_API void zend_llist_clean(zend_llist *l);
  48. ZEND_API void zend_llist_remove_tail(zend_llist *l);
  49. ZEND_API void zend_llist_copy(zend_llist *dst, zend_llist *src);
  50. ZEND_API void zend_llist_apply(zend_llist *l, llist_apply_func_t func);
  51. ZEND_API void zend_llist_apply_with_del(zend_llist *l, int (*func)(void *data));
  52. ZEND_API void zend_llist_apply_with_argument(zend_llist *l, llist_apply_with_arg_func_t func, void *arg);
  53. ZEND_API void zend_llist_apply_with_arguments(zend_llist *l, llist_apply_with_args_func_t func, int num_args, ...);
  54. ZEND_API size_t zend_llist_count(zend_llist *l);
  55. ZEND_API void zend_llist_sort(zend_llist *l, llist_compare_func_t comp_func);
  56. /* traversal */
  57. ZEND_API void *zend_llist_get_first_ex(zend_llist *l, zend_llist_position *pos);
  58. ZEND_API void *zend_llist_get_last_ex(zend_llist *l, zend_llist_position *pos);
  59. ZEND_API void *zend_llist_get_next_ex(zend_llist *l, zend_llist_position *pos);
  60. ZEND_API void *zend_llist_get_prev_ex(zend_llist *l, zend_llist_position *pos);
  61. #define zend_llist_get_first(l) zend_llist_get_first_ex(l, NULL)
  62. #define zend_llist_get_last(l) zend_llist_get_last_ex(l, NULL)
  63. #define zend_llist_get_next(l) zend_llist_get_next_ex(l, NULL)
  64. #define zend_llist_get_prev(l) zend_llist_get_prev_ex(l, NULL)
  65. END_EXTERN_C()
  66. #endif /* ZEND_LLIST_H */
  67. /*
  68. * Local variables:
  69. * tab-width: 4
  70. * c-basic-offset: 4
  71. * indent-tabs-mode: t
  72. * End:
  73. * vim600: sw=4 ts=4 fdm=marker
  74. * vim<600: sw=4 ts=4
  75. */