GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-87d2d42d3b
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 }
int btree_find(const BTREE *B, const void *key, void **data)
Definition: btree/find.c:4
int left
Definition: btree.h:7
int right
Definition: btree.h:8
void * key
Definition: btree.h:5
void * data
Definition: btree.h:6
Definition: btree.h:11
int N
Definition: btree.h:14
int(* cmp)(const void *, const void *)
Definition: btree.h:17
BTREE_NODE * node
Definition: btree.h:12