ulist.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (C) 2011 STRATO AG
  3. * written by Arne Jansen <sensille@gmx.net>
  4. * Distributed under the GNU GPL license version 2.
  5. *
  6. */
  7. #ifndef __ULIST__
  8. #define __ULIST__
  9. #include <linux/list.h>
  10. #include <linux/rbtree.h>
  11. /*
  12. * ulist is a generic data structure to hold a collection of unique u64
  13. * values. The only operations it supports is adding to the list and
  14. * enumerating it.
  15. * It is possible to store an auxiliary value along with the key.
  16. *
  17. */
  18. struct ulist_iterator {
  19. #ifdef CONFIG_BTRFS_DEBUG
  20. int i;
  21. #endif
  22. struct list_head *cur_list; /* hint to start search */
  23. };
  24. /*
  25. * element of the list
  26. */
  27. struct ulist_node {
  28. u64 val; /* value to store */
  29. u64 aux; /* auxiliary value saved along with the val */
  30. #ifdef CONFIG_BTRFS_DEBUG
  31. int seqnum; /* sequence number this node is added */
  32. #endif
  33. struct list_head list; /* used to link node */
  34. struct rb_node rb_node; /* used to speed up search */
  35. };
  36. struct ulist {
  37. /*
  38. * number of elements stored in list
  39. */
  40. unsigned long nnodes;
  41. struct list_head nodes;
  42. struct rb_root root;
  43. };
  44. void ulist_init(struct ulist *ulist);
  45. void ulist_reinit(struct ulist *ulist);
  46. struct ulist *ulist_alloc(gfp_t gfp_mask);
  47. void ulist_free(struct ulist *ulist);
  48. int ulist_add(struct ulist *ulist, u64 val, u64 aux, gfp_t gfp_mask);
  49. int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux,
  50. u64 *old_aux, gfp_t gfp_mask);
  51. struct ulist_node *ulist_next(struct ulist *ulist,
  52. struct ulist_iterator *uiter);
  53. #define ULIST_ITER_INIT(uiter) ((uiter)->cur_list = NULL)
  54. #endif