rblist.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PERF_RBLIST_H
  3. #define __PERF_RBLIST_H
  4. #include <linux/rbtree.h>
  5. #include <stdbool.h>
  6. /*
  7. * create node structs of the form:
  8. * struct my_node {
  9. * struct rb_node rb_node;
  10. * ... my data ...
  11. * };
  12. *
  13. * create list structs of the form:
  14. * struct mylist {
  15. * struct rblist rblist;
  16. * ... my data ...
  17. * };
  18. */
  19. struct rblist {
  20. struct rb_root_cached entries;
  21. unsigned int nr_entries;
  22. int (*node_cmp)(struct rb_node *rbn, const void *entry);
  23. struct rb_node *(*node_new)(struct rblist *rlist, const void *new_entry);
  24. void (*node_delete)(struct rblist *rblist, struct rb_node *rb_node);
  25. };
  26. void rblist__init(struct rblist *rblist);
  27. void rblist__exit(struct rblist *rblist);
  28. void rblist__delete(struct rblist *rblist);
  29. int rblist__add_node(struct rblist *rblist, const void *new_entry);
  30. void rblist__remove_node(struct rblist *rblist, struct rb_node *rb_node);
  31. struct rb_node *rblist__find(struct rblist *rblist, const void *entry);
  32. struct rb_node *rblist__findnew(struct rblist *rblist, const void *entry);
  33. struct rb_node *rblist__entry(const struct rblist *rblist, unsigned int idx);
  34. static inline bool rblist__empty(const struct rblist *rblist)
  35. {
  36. return rblist->nr_entries == 0;
  37. }
  38. static inline unsigned int rblist__nr_entries(const struct rblist *rblist)
  39. {
  40. return rblist->nr_entries;
  41. }
  42. #endif /* __PERF_RBLIST_H */