rblist.h 1.3 KB

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