2 * Copyright (C) 2014 Facebook. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
19 #include "rbtree-utils.h"
21 int rb_insert(struct rb_root
*root
, struct rb_node
*node
,
22 rb_compare_nodes comp
)
24 struct rb_node
**p
= &root
->rb_node
;
25 struct rb_node
*parent
= NULL
;
31 ret
= comp(parent
, node
);
40 rb_link_node(node
, parent
, p
);
41 rb_insert_color(node
, root
);
45 struct rb_node
*rb_search(struct rb_root
*root
, void *key
, rb_compare_keys comp
,
46 struct rb_node
**next_ret
)
48 struct rb_node
*n
= root
->rb_node
;
49 struct rb_node
*parent
= NULL
;
67 if (parent
&& ret
> 0)
68 parent
= rb_next(parent
);
74 void rb_free_nodes(struct rb_root
*root
, rb_free_node free_node
)
78 while ((node
= rb_first(root
))) {