GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
btree/try.c
Go to the documentation of this file.
1 
2 /****************************************************************************
3  *
4  * MODULE: btree
5  * AUTHOR(S): CERL (present in ver 4.x)
6  * Radim Blazek <radim.blazek gmail.com>
7  * Glynn Clements <glynn gclements.plus.com>
8  * PURPOSE: balanced tree - possibly duplicating libavl functionality; see
9  * http://grass.itc.it/pipermail/grass-dev/2007-April/030396.html
10  * COPYRIGHT: (C) 2002-2007 by the GRASS Development Team
11  *
12  * This program is free software under the GNU General Public
13  * License (>=v2). Read the file COPYING that comes with GRASS
14  * for details.
15  *
16  *****************************************************************************/
17 #include <stdio.h>
18 #include <string.h>
19 #include <grass/btree.h>
20 
21 static int cmp(const void *a, const void *b)
22 {
23  return strcmp(a, b);
24 }
25 
26 int main(void)
27 {
28  char key[100], data[100];
29  void *k, *d;
30  BTREE B;
31 
32  btree_create(&B, strcmp, 10);
33  while (1) {
34  fprintf(stdout, "enter key (or RETURN if done): ");
35  if (!gets(key))
36  exit(0);
37  if (*key == 0)
38  break;
39  fprintf(stdout, " ");
40  if (btree_find(&B, key, &d))
41  fprintf(stdout, "%s = %s\n", key, d);
42  else
43  fprintf(stdout, "%s - not found\n", key);
44  fprintf(stdout, " ");
45  fprintf(stdout, "enter new value (or RETURN if none): ");
46  if (!gets(data))
47  exit(0);
48  if (*data)
49  btree_update(&B, key, strlen(key) + 1, data, strlen(data) + 1);
50  }
51 
52  fprintf(stdout, "final tree\n");
53  btree_rewind(&B);
54  while (btree_next(&B, &k, &d))
55  fprintf(stdout, "%s:%s\n", (const char *)k, (const char *)d);
56 
57  return 0;
58 }
float b
Definition: named_colr.c:8
int btree_update(BTREE *B, const void *key, int keylen, const void *data, int datalen)
Definition: btree/update.c:8
int btree_rewind(BTREE *B)
Definition: btree/rewind.c:3
int btree_find(const BTREE *B, const void *key, void **data)
Definition: btree/find.c:4
tuple data
int btree_next(BTREE *B, void **key, void **data)
Definition: btree/next.c:3
int main(int argc, char *argv[])
Definition: gem/main.c:302
int btree_create(BTREE *B, int(*cmp)(const void *, const void *), int incr)
Definition: create.c:5