GRASS Programmer's Manual  6.4.2(2012)
btree/find.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <grass/btree.h>
00003 
00004 int btree_find(const BTREE * B, const void *key, void **data)
00005 {
00006     int q;
00007     int dir;
00008 
00009 
00010     if (B->N <= 0)
00011         return 0;
00012 
00013     q = 1;
00014     while (q > 0) {
00015         dir = (*B->cmp) (B->node[q].key, key);
00016         if (dir == 0) {
00017             *data = B->node[q].data;
00018             return 1;
00019         }
00020         if (dir > 0)
00021             q = B->node[q].left;        /* go left */
00022         else
00023             q = B->node[q].right;       /* go right */
00024     }
00025 
00026     return 0;
00027 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines