1 /* -*- mode: C -*-  */
2 /*
3    IGraph library.
4    Copyright (C) 2006-2012  Gabor Csardi <csardi.gabor@gmail.com>
5    334 Harvard st, Cambridge MA, 02139 USA
6 
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA
20    02110-1301 USA
21 
22 */
23 
24 #include <stdio.h>
25 #include <igraph.h>
26 
27 #include "core/trie.h"
28 
29 #include "test_utilities.inc"
30 
main()31 int main() {
32 
33     igraph_trie_t trie;
34     long int id;
35     int i;
36     char *str;
37 
38     /* init */
39     igraph_trie_init(&trie, 0);
40 
41     /* add and get values */
42     igraph_trie_get(&trie, "hello", &id);
43     printf("hello: %li\n", id);
44     igraph_trie_get(&trie, "hepp", &id);
45     printf("hepp:  %li\n", id);
46     igraph_trie_get(&trie, "alma", &id);
47     printf("alma:  %li\n", id);
48     igraph_trie_get(&trie, "also", &id);
49     printf("also:  %li\n", id);
50 
51     igraph_trie_get(&trie, "hello", &id);
52     printf("hello: %li\n", id);
53     igraph_trie_get(&trie, "hepp", &id);
54     printf("hepp:  %li\n", id);
55     igraph_trie_get(&trie, "alma", &id);
56     printf("alma:  %li\n", id);
57     igraph_trie_get(&trie, "also", &id);
58     printf("also:  %li\n", id);
59 
60     igraph_trie_get(&trie, "a", &id);
61     printf("a:     %li\n", id);
62     igraph_trie_get(&trie, "axon", &id);
63     printf("axon:  %li\n", id);
64 
65     igraph_trie_get(&trie, "hello", &id);
66     printf("hello: %li\n", id);
67     igraph_trie_get(&trie, "hepp", &id);
68     printf("hepp:  %li\n", id);
69     igraph_trie_get(&trie, "alma", &id);
70     printf("alma:  %li\n", id);
71     igraph_trie_get(&trie, "also", &id);
72     printf("also:  %li\n", id);
73 
74     /* check for existence */
75     igraph_trie_check(&trie, "head", &id);
76     printf("head:  %li\n", id);
77     igraph_trie_check(&trie, "alma", &id);
78     printf("alma:  %li\n", id);
79 
80     /* destroy */
81     igraph_trie_destroy(&trie);
82 
83     /* the same with index */
84     igraph_trie_init(&trie, 1);
85 
86     igraph_trie_get(&trie, "hello", &id);
87     printf("hello: %li\n", id);
88     igraph_trie_get(&trie, "hepp", &id);
89     printf("hepp:  %li\n", id);
90     igraph_trie_get(&trie, "alma", &id);
91     printf("alma:  %li\n", id);
92     igraph_trie_get(&trie, "also", &id);
93     printf("also:  %li\n", id);
94 
95     igraph_trie_get(&trie, "hello", &id);
96     printf("hello: %li\n", id);
97     igraph_trie_get(&trie, "hepp", &id);
98     printf("hepp:  %li\n", id);
99     igraph_trie_get(&trie, "alma", &id);
100     printf("alma:  %li\n", id);
101     igraph_trie_get(&trie, "also", &id);
102     printf("also:  %li\n", id);
103 
104     igraph_trie_get(&trie, "a", &id);
105     printf("a:     %li\n", id);
106     igraph_trie_get(&trie, "axon", &id);
107     printf("axon:  %li\n", id);
108 
109     igraph_trie_get(&trie, "hello", &id);
110     printf("hello: %li\n", id);
111     igraph_trie_get(&trie, "hepp", &id);
112     printf("hepp:  %li\n", id);
113     igraph_trie_get(&trie, "alma", &id);
114     printf("alma:  %li\n", id);
115     igraph_trie_get(&trie, "also", &id);
116     printf("also:  %li\n", id);
117 
118     /* check for existence */
119     igraph_trie_check(&trie, "head", &id);
120     printf("head:  %li\n", id);
121     igraph_trie_check(&trie, "alma", &id);
122     printf("alma:  %li\n", id);
123 
124     for (i = 0; i < igraph_trie_size(&trie); i++) {
125         igraph_trie_idx(&trie, i, &str);
126         printf("%d: %s\n", i, str);
127     }
128     igraph_trie_destroy(&trie);
129 
130     VERIFY_FINALLY_STACK();
131 
132     return 0;
133 }
134