GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-36359e2344
btree/find.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <
grass/btree.h
>
3
4
int
btree_find
(
const
BTREE
*B,
const
void
*key,
void
**data)
5
{
6
int
q;
7
int
dir;
8
9
if
(B->
N
<= 0)
10
return
0;
11
12
q = 1;
13
while
(q > 0) {
14
dir = (*B->
cmp
)(B->
node
[q].
key
, key);
15
if
(dir == 0) {
16
*data = B->
node
[q].
data
;
17
return
1;
18
}
19
if
(dir > 0)
20
q = B->
node
[q].
left
;
/* go left */
21
else
22
q = B->
node
[q].
right
;
/* go right */
23
}
24
25
return
0;
26
}
btree_find
int btree_find(const BTREE *B, const void *key, void **data)
Definition:
btree/find.c:4
btree.h
BTREE_NODE::left
int left
Definition:
btree.h:7
BTREE_NODE::right
int right
Definition:
btree.h:8
BTREE_NODE::key
void * key
Definition:
btree.h:5
BTREE_NODE::data
void * data
Definition:
btree.h:6
BTREE
Definition:
btree.h:11
BTREE::N
int N
Definition:
btree.h:14
BTREE::cmp
int(* cmp)(const void *, const void *)
Definition:
btree.h:17
BTREE::node
BTREE_NODE * node
Definition:
btree.h:12
lib
btree
find.c
Generated on Thu Nov 21 2024 07:03:26 for GRASS GIS 8 Programmer's Manual by
1.9.1