xref: /linux/tools/perf/util/strlist.h (revision 3e3405906dab00afecd5a16871850a088eba4626)
18b40f521SJohn Kacur #ifndef __PERF_STRLIST_H
28b40f521SJohn Kacur #define __PERF_STRLIST_H
325903407SArnaldo Carvalho de Melo 
443cbcd8aSArnaldo Carvalho de Melo #include <linux/rbtree.h>
525903407SArnaldo Carvalho de Melo #include <stdbool.h>
625903407SArnaldo Carvalho de Melo 
725903407SArnaldo Carvalho de Melo struct str_node {
825903407SArnaldo Carvalho de Melo 	struct rb_node rb_node;
925903407SArnaldo Carvalho de Melo 	const char     *s;
1025903407SArnaldo Carvalho de Melo };
1125903407SArnaldo Carvalho de Melo 
1225903407SArnaldo Carvalho de Melo struct strlist {
1325903407SArnaldo Carvalho de Melo 	struct rb_root entries;
1427d0fd41SArnaldo Carvalho de Melo 	unsigned int   nr_entries;
1525903407SArnaldo Carvalho de Melo 	bool	       dupstr;
1625903407SArnaldo Carvalho de Melo };
1725903407SArnaldo Carvalho de Melo 
1825903407SArnaldo Carvalho de Melo struct strlist *strlist__new(bool dupstr, const char *slist);
1925903407SArnaldo Carvalho de Melo void strlist__delete(struct strlist *self);
2025903407SArnaldo Carvalho de Melo 
2125903407SArnaldo Carvalho de Melo void strlist__remove(struct strlist *self, struct str_node *sn);
2225903407SArnaldo Carvalho de Melo int strlist__load(struct strlist *self, const char *filename);
2325903407SArnaldo Carvalho de Melo int strlist__add(struct strlist *self, const char *str);
2425903407SArnaldo Carvalho de Melo 
2527d0fd41SArnaldo Carvalho de Melo struct str_node *strlist__entry(const struct strlist *self, unsigned int idx);
26*3e340590SMasami Hiramatsu struct str_node *strlist__find(struct strlist *self, const char *entry);
27*3e340590SMasami Hiramatsu 
28*3e340590SMasami Hiramatsu static inline bool strlist__has_entry(struct strlist *self, const char *entry)
29*3e340590SMasami Hiramatsu {
30*3e340590SMasami Hiramatsu 	return strlist__find(self, entry) != NULL;
31*3e340590SMasami Hiramatsu }
3225903407SArnaldo Carvalho de Melo 
3325903407SArnaldo Carvalho de Melo static inline bool strlist__empty(const struct strlist *self)
3425903407SArnaldo Carvalho de Melo {
3527d0fd41SArnaldo Carvalho de Melo 	return self->nr_entries == 0;
3627d0fd41SArnaldo Carvalho de Melo }
3727d0fd41SArnaldo Carvalho de Melo 
3827d0fd41SArnaldo Carvalho de Melo static inline unsigned int strlist__nr_entries(const struct strlist *self)
3927d0fd41SArnaldo Carvalho de Melo {
4027d0fd41SArnaldo Carvalho de Melo 	return self->nr_entries;
4125903407SArnaldo Carvalho de Melo }
4225903407SArnaldo Carvalho de Melo 
4325903407SArnaldo Carvalho de Melo int strlist__parse_list(struct strlist *self, const char *s);
448b40f521SJohn Kacur #endif /* __PERF_STRLIST_H */
45