Subversion Repositories PlanixRsrch.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
466 7u83 1
#include "mavl.h"
2
 
3
 
4
 
5
struct mavlnode * mavlnode_get_ext(struct mavl *t ,const void *search, int mode)
6
{
7
 
8
	struct mavlnode *n,/**lastl,*/*last;
9
	last = NULL; /*lastl=NULL;*/
10
	n = t->root;
11
	while(n){
12
		int rc;
13
 
14
		rc = t->cmp(search,mavlnode_dataptr(n));
15
 
16
		/*printf("Compare: %s %s = %d\n",c1->key,c2->key, rc);*/
17
 
18
		if (rc==0){
19
			return n;
20
 
21
		}
22
 
23
		if (rc<0){
24
			if (mode == MAVL_FIND_FIRST)
25
				last = n;
26
			if (n->s[0]==NULL){
27
				if (last == NULL)
28
					return NULL;
29
				return last;
30
 
31
			}
32
			n=n->s[0];
33
		}
34
		else{
35
			if (mode == MAVL_FIND_LAST)
36
				last=n;
37
 
38
			if(n->s[1]==NULL){
39
				if (last == NULL)
40
					return NULL;
41
				return last;
42
 
43
			}
44
			n=n->s[1];
45
		}
46
	}
47
	return NULL;
48
}
49