GRASS Programmer's Manual
6.4.3(2013)-r
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
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
}
lib
btree
try.c
Generated on Thu Sep 26 2013 09:48:07 for GRASS Programmer's Manual by
1.8.4