2 * Based on strlist.c by:
3 * (c) 2009 Arnaldo Carvalho de Melo <acme@redhat.com>
5 * Licensed under the GPLv2.
14 int rblist__add_node(struct rblist
*rblist
, const void *new_entry
)
16 struct rb_node
**p
= &rblist
->entries
.rb_node
;
17 struct rb_node
*parent
= NULL
, *new_node
;
24 rc
= rblist
->node_cmp(parent
, new_entry
);
33 new_node
= rblist
->node_new(rblist
, new_entry
);
37 rb_link_node(new_node
, parent
, p
);
38 rb_insert_color(new_node
, &rblist
->entries
);
44 void rblist__remove_node(struct rblist
*rblist
, struct rb_node
*rb_node
)
46 rb_erase(rb_node
, &rblist
->entries
);
48 rblist
->node_delete(rblist
, rb_node
);
51 struct rb_node
*rblist__find(struct rblist
*rblist
, const void *entry
)
53 struct rb_node
**p
= &rblist
->entries
.rb_node
;
54 struct rb_node
*parent
= NULL
;
61 rc
= rblist
->node_cmp(parent
, entry
);
73 void rblist__init(struct rblist
*rblist
)
76 rblist
->entries
= RB_ROOT
;
77 rblist
->nr_entries
= 0;
83 void rblist__delete(struct rblist
*rblist
)
86 struct rb_node
*pos
, *next
= rb_first(&rblist
->entries
);
91 rblist__remove_node(rblist
, pos
);
97 struct rb_node
*rblist__entry(const struct rblist
*rblist
, unsigned int idx
)
101 for (node
= rb_first(&rblist
->entries
); node
; node
= rb_next(node
)) {