Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
intlist.h
Go to the documentation of this file.
1 #ifndef __PERF_INTLIST_H
2 #define __PERF_INTLIST_H
3 
4 #include <linux/rbtree.h>
5 #include <stdbool.h>
6 
7 #include "rblist.h"
8 
9 struct int_node {
10  struct rb_node rb_node;
11  int i;
12 };
13 
14 struct intlist {
15  struct rblist rblist;
16 };
17 
18 struct intlist *intlist__new(void);
19 void intlist__delete(struct intlist *ilist);
20 
21 void intlist__remove(struct intlist *ilist, struct int_node *in);
22 int intlist__add(struct intlist *ilist, int i);
23 
24 struct int_node *intlist__entry(const struct intlist *ilist, unsigned int idx);
25 struct int_node *intlist__find(struct intlist *ilist, int i);
26 
27 static inline bool intlist__has_entry(struct intlist *ilist, int i)
28 {
29  return intlist__find(ilist, i) != NULL;
30 }
31 
32 static inline bool intlist__empty(const struct intlist *ilist)
33 {
34  return rblist__empty(&ilist->rblist);
35 }
36 
37 static inline unsigned int intlist__nr_entries(const struct intlist *ilist)
38 {
39  return rblist__nr_entries(&ilist->rblist);
40 }
41 
42 /* For intlist iteration */
43 static inline struct int_node *intlist__first(struct intlist *ilist)
44 {
45  struct rb_node *rn = rb_first(&ilist->rblist.entries);
46  return rn ? rb_entry(rn, struct int_node, rb_node) : NULL;
47 }
48 static inline struct int_node *intlist__next(struct int_node *in)
49 {
50  struct rb_node *rn;
51  if (!in)
52  return NULL;
53  rn = rb_next(&in->rb_node);
54  return rn ? rb_entry(rn, struct int_node, rb_node) : NULL;
55 }
56 
62 #define intlist__for_each(pos, ilist) \
63  for (pos = intlist__first(ilist); pos; pos = intlist__next(pos))
64 
72 #define intlist__for_each_safe(pos, n, ilist) \
73  for (pos = intlist__first(ilist), n = intlist__next(pos); pos;\
74  pos = n, n = intlist__next(n))
75 #endif /* __PERF_INTLIST_H */