GRASS GIS 8 Programmer's Manual
8.2.2dev(2023)-3d2c704037
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
10
if
(B->
N
<= 0)
11
return
0;
12
13
q = 1;
14
while
(q > 0) {
15
dir = (*B->
cmp
) (B->
node
[q].
key
, key);
16
if
(dir == 0) {
17
*data = B->
node
[q].
data
;
18
return
1;
19
}
20
if
(dir > 0)
21
q = B->
node
[q].
left
;
/* go left */
22
else
23
q = B->
node
[q].
right
;
/* go right */
24
}
25
26
return
0;
27
}
btree.h
BTREE::N
int N
Definition:
btree.h:16
BTREE_NODE::left
int left
Definition:
btree.h:8
btree_find
int btree_find(const BTREE *B, const void *key, void **data)
Definition:
btree/find.c:4
BTREE
Definition:
btree.h:12
BTREE_NODE::key
void * key
Definition:
btree.h:6
BTREE::cmp
int(* cmp)(const void *, const void *)
Definition:
btree.h:19
BTREE_NODE::data
void * data
Definition:
btree.h:7
BTREE::node
BTREE_NODE * node
Definition:
btree.h:14
BTREE_NODE::right
int right
Definition:
btree.h:9
lib
btree
find.c
Generated on Tue Feb 14 2023 05:55:59 for GRASS GIS 8 Programmer's Manual by
1.8.13