Subversion Repositories PlanixRsrch.SVN

Rev

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

Rev Author Line No. Line
467 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
 
30
 
31
 
32
 
33
void *
34
mavliter_seek(struct mavliter *i ,const void *search, int mode)
35
{
36
 
37
	i->stack_ptr = 0;
38
	i->cur = i->root;
39
	while(i->cur){
40
		int rc;
41
 
42
		rc = i->cmp(search,mavlnode_dataptr(i->cur));
43
 
44
		if (rc==0){
45
			i->stack[i->stack_ptr++] = i->cur->s[1];
470 7u83 46
			return mavlnode_dataptr(i->cur);
467 7u83 47
		}
48
 
49
		if (rc<0){
50
			if (i->cur->s[0]){
51
 
52
				/* push s[1] branch */
53
				i->stack[i->stack_ptr++] = i->cur->s[1];
54
 
55
				/* push node */
56
				i->stack[i->stack_ptr++] = i->cur;
57
 
58
				i->cur = i->cur->s[0];
59
			}	
470 7u83 60
			else {
471 7u83 61
				i->stack[i->stack_ptr++] = i->cur->s[1];
470 7u83 62
				return mavlnode_dataptr(i->cur);
63
			}
467 7u83 64
		}
65
		else {
470 7u83 66
			if (i->cur->s[1]){
67
				i->cur=i->cur->s[1];
68
			}
69
			else {
70
				mavliter_next(i);
71
				return mavlnode_dataptr(i->cur);
72
			}
467 7u83 73
		}
74
	}
75
	return NULL;
76
}
77