]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - fs/btrfs/common/rbtree-utils.c
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 <linux/errno.h>
20 #include "rbtree-utils.h"
22 int rb_insert(struct rb_root
*root
, struct rb_node
*node
,
23 rb_compare_nodes comp
)
25 struct rb_node
**p
= &root
->rb_node
;
26 struct rb_node
*parent
= NULL
;
32 ret
= comp(parent
, node
);
41 rb_link_node(node
, parent
, p
);
42 rb_insert_color(node
, root
);
46 struct rb_node
*rb_search(struct rb_root
*root
, void *key
, rb_compare_keys comp
,
47 struct rb_node
**next_ret
)
49 struct rb_node
*n
= root
->rb_node
;
50 struct rb_node
*parent
= NULL
;
68 if (parent
&& ret
> 0)
69 parent
= rb_next(parent
);
75 void rb_free_nodes(struct rb_root
*root
, rb_free_node free_node
)
79 while ((node
= rb_first(root
))) {