You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5 KiB

10 years ago
  1. /* -*- coding: utf-8 -*-
  2. * ----------------------------------------------------------------------
  3. * Copyright © 2011-2014, RedJack, LLC.
  4. * All rights reserved.
  5. *
  6. * Please see the COPYING file in this distribution for license details.
  7. * ----------------------------------------------------------------------
  8. */
  9. #include "libcork/core/api.h"
  10. #include "libcork/core/types.h"
  11. #include "libcork/ds/dllist.h"
  12. /* Include a linkable (but deprecated) version of this to maintain ABI
  13. * compatibility. */
  14. #undef cork_dllist_init
  15. CORK_API void
  16. cork_dllist_init(struct cork_dllist *list)
  17. {
  18. list->head.next = &list->head;
  19. list->head.prev = &list->head;
  20. }
  21. void
  22. cork_dllist_map(struct cork_dllist *list,
  23. cork_dllist_map_func func, void *user_data)
  24. {
  25. struct cork_dllist_item *curr;
  26. struct cork_dllist_item *next;
  27. cork_dllist_foreach_void(list, curr, next) {
  28. func(curr, user_data);
  29. }
  30. }
  31. int
  32. cork_dllist_visit(struct cork_dllist *list, void *ud,
  33. cork_dllist_visit_f *visit)
  34. {
  35. struct cork_dllist_item *curr;
  36. struct cork_dllist_item *next;
  37. cork_dllist_foreach_void(list, curr, next) {
  38. int rc = visit(ud, curr);
  39. if (rc != 0) {
  40. return rc;
  41. }
  42. }
  43. return 0;
  44. }
  45. size_t
  46. cork_dllist_size(const struct cork_dllist *list)
  47. {
  48. size_t size = 0;
  49. struct cork_dllist_item *curr;
  50. struct cork_dllist_item *next;
  51. cork_dllist_foreach_void(list, curr, next) {
  52. size++;
  53. }
  54. return size;
  55. }