Subversion Repositories PlanixRsrch.SVN

Rev

Rev 40 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 7u83 1
/*
2
 * Copyright 2019, The PLANIX Project
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions are
6
 * met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 * this list of conditions and the following disclaimer.
10
 *
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 * notice, this list of conditions and the following disclaimer in the
13
 * documentation and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
#include "mavl.h"
28
 
29
int mavl_foreach_lr(struct mavlnode *n, int (*callback)(void *,void *),void *cbpriv)
30
{
31
	if (!n)
32
		return 1;
40 7u83 33
	if (!mavl_foreach_lr(n->s[0],callback,cbpriv))
18 7u83 34
		return 0;
35
	if (!callback(cbpriv,mavlnode_dataptr(n)))
36
		return 0;
40 7u83 37
	return mavl_foreach_lr(n->s[1],callback,cbpriv);
18 7u83 38
 
39
}
40
 
41
int mavl_foreach_rl(struct mavlnode *n, int (*callback)(void *,void *),void *cbpriv)
42
{
43
	if (!n)
44
		return 1;
40 7u83 45
	if (!mavl_foreach_rl(n->s[1],callback,cbpriv))
18 7u83 46
		return 0;
47
	if (!callback(cbpriv,mavlnode_dataptr(n)))
48
		return 0;
40 7u83 49
	return mavl_foreach_rl(n->s[0],callback,cbpriv);
18 7u83 50
}
51
 
52
void mavl_foreach(struct mavl *t, int (*callback)(void *,void *),void * cbpriv,int dir)
53
{
54
	if (dir)
85 7u83 55
		(void)mavl_foreach_lr(t->root,callback,cbpriv);
18 7u83 56
	else
85 7u83 57
		(void)mavl_foreach_rl(t->root,callback,cbpriv);
18 7u83 58
}
59