2 * Based on intlist.c by:
3 * (c) 2009 Arnaldo Carvalho de Melo <acme@redhat.com>
5 * Licensed under the GPLv2.
10 #include <linux/compiler.h>
14 static struct rb_node *intlist__node_new(struct rblist *rblist __used,
17 int i = (int)((long)entry);
18 struct rb_node *rc = NULL;
19 struct int_node *node = malloc(sizeof(*node));
29 static void int_node__delete(struct int_node *ilist)
34 static void intlist__node_delete(struct rblist *rblist __used,
35 struct rb_node *rb_node)
37 struct int_node *node = container_of(rb_node, struct int_node, rb_node);
39 int_node__delete(node);
42 static int intlist__node_cmp(struct rb_node *rb_node, const void *entry)
44 int i = (int)((long)entry);
45 struct int_node *node = container_of(rb_node, struct int_node, rb_node);
50 int intlist__add(struct intlist *ilist, int i)
52 return rblist__add_node(&ilist->rblist, (void *)((long)i));
55 void intlist__remove(struct intlist *ilist __used, struct int_node *node)
57 int_node__delete(node);
60 struct int_node *intlist__find(struct intlist *ilist, int i)
62 struct int_node *node = NULL;
63 struct rb_node *rb_node = rblist__find(&ilist->rblist, (void *)((long)i));
66 node = container_of(rb_node, struct int_node, rb_node);
71 struct intlist *intlist__new(void)
73 struct intlist *ilist = malloc(sizeof(*ilist));
76 rblist__init(&ilist->rblist);
77 ilist->rblist.node_cmp = intlist__node_cmp;
78 ilist->rblist.node_new = intlist__node_new;
79 ilist->rblist.node_delete = intlist__node_delete;
85 void intlist__delete(struct intlist *ilist)
88 rblist__delete(&ilist->rblist);
91 struct int_node *intlist__entry(const struct intlist *ilist, unsigned int idx)
93 struct int_node *node = NULL;
94 struct rb_node *rb_node;
96 rb_node = rblist__entry(&ilist->rblist, idx);
98 node = container_of(rb_node, struct int_node, rb_node);