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 }
int N
Definition: btree.h:16
int left
Definition: btree.h:8
int btree_find(const BTREE *B, const void *key, void **data)
Definition: btree/find.c:4
Definition: btree.h:12
void * key
Definition: btree.h:6
int(* cmp)(const void *, const void *)
Definition: btree.h:19
void * data
Definition: btree.h:7
BTREE_NODE * node
Definition: btree.h:14
int right
Definition: btree.h:9