Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 155713
b: refs/heads/master
c: 27d0fd4
h: refs/heads/master
i:
  155711: 8fbcd45
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo authored and Ingo Molnar committed Jul 11, 2009
1 parent f14e4c0 commit 2a1589d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 60c1baf1248e00d423604f018c8af1cf750ad885
refs/heads/master: 27d0fd410c3cee00ece2e55f4354a7a9ec1a6a6a
20 changes: 18 additions & 2 deletions trunk/tools/perf/util/strlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ int strlist__add(struct strlist *self, const char *new_entry)

rb_link_node(&sn->rb_node, parent, p);
rb_insert_color(&sn->rb_node, &self->entries);
++self->nr_entries;

return 0;
}
Expand Down Expand Up @@ -155,8 +156,9 @@ struct strlist *strlist__new(bool dupstr, const char *slist)
struct strlist *self = malloc(sizeof(*self));

if (self != NULL) {
self->entries = RB_ROOT;
self->dupstr = dupstr;
self->entries = RB_ROOT;
self->dupstr = dupstr;
self->nr_entries = 0;
if (slist && strlist__parse_list(self, slist) != 0)
goto out_error;
}
Expand All @@ -182,3 +184,17 @@ void strlist__delete(struct strlist *self)
free(self);
}
}

struct str_node *strlist__entry(const struct strlist *self, unsigned int idx)
{
struct rb_node *nd;

for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
struct str_node *pos = rb_entry(nd, struct str_node, rb_node);

if (!idx--)
return pos;
}

return NULL;
}
11 changes: 9 additions & 2 deletions trunk/tools/perf/util/strlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ struct str_node {

struct strlist {
struct rb_root entries;
bool dupstr;
unsigned int nr_entries;
bool dupstr;
};

struct strlist *strlist__new(bool dupstr, const char *slist);
Expand All @@ -21,11 +22,17 @@ void strlist__remove(struct strlist *self, struct str_node *sn);
int strlist__load(struct strlist *self, const char *filename);
int strlist__add(struct strlist *self, const char *str);

struct str_node *strlist__entry(const struct strlist *self, unsigned int idx);
bool strlist__has_entry(struct strlist *self, const char *entry);

static inline bool strlist__empty(const struct strlist *self)
{
return rb_first(&self->entries) == NULL;
return self->nr_entries == 0;
}

static inline unsigned int strlist__nr_entries(const struct strlist *self)
{
return self->nr_entries;
}

int strlist__parse_list(struct strlist *self, const char *s);
Expand Down

0 comments on commit 2a1589d

Please sign in to comment.