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 <igraph.h>
25 #include "core/hashtable.h"
26
27 #include "test_utilities.inc"
28
main()29 int main() {
30
31 igraph_hashtable_t ht;
32 char *str;
33 const igraph_strvector_t *keys;
34 long int i;
35
36 /* init and destroy */
37 igraph_hashtable_init(&ht);
38 igraph_hashtable_destroy(&ht);
39
40 /* init, add some elements and destroy */
41 igraph_hashtable_init(&ht);
42 igraph_hashtable_addset(&ht, "color", "green", "red");
43 igraph_hashtable_addset(&ht, "size", "", "4");
44 igraph_hashtable_addset(&ht, "color", "", "grey");
45 igraph_hashtable_addset(&ht, "shape", "", "circle");
46 igraph_hashtable_addset(&ht, "shape", "", "diamond");
47 igraph_hashtable_destroy(&ht);
48
49 /* reset */
50 igraph_hashtable_init(&ht);
51 igraph_hashtable_addset(&ht, "color", "green", "red");
52 igraph_hashtable_addset(&ht, "size", "", "4");
53 igraph_hashtable_addset(&ht, "color", "", "grey");
54 igraph_hashtable_addset(&ht, "shape", "", "circle");
55 igraph_hashtable_addset(&ht, "shape", "", "diamond");
56 igraph_hashtable_reset(&ht);
57 igraph_hashtable_addset(&ht, "color", "green", "red");
58 igraph_hashtable_addset(&ht, "size", "", "4");
59 igraph_hashtable_addset(&ht, "color", "", "grey");
60 igraph_hashtable_addset(&ht, "shape", "", "circle");
61 igraph_hashtable_addset(&ht, "shape", "", "diamond");
62 igraph_hashtable_destroy(&ht);
63
64 /* Check semantics */
65 igraph_hashtable_init(&ht);
66 igraph_hashtable_addset(&ht, "color", "green", "red");
67 igraph_hashtable_addset(&ht, "size", "", "4");
68 igraph_hashtable_addset(&ht, "color", "", "grey");
69 igraph_hashtable_addset(&ht, "shape", "", "circle");
70 igraph_hashtable_addset(&ht, "shape", "", "diamond");
71
72 igraph_hashtable_get(&ht, "color", &str);
73 printf("color: %s\n", str);
74 igraph_hashtable_get(&ht, "size", &str);
75 printf("size: %s\n", str);
76 igraph_hashtable_get(&ht, "shape", &str);
77 printf("shape: %s\n", str);
78
79 igraph_hashtable_reset(&ht);
80
81 igraph_hashtable_get(&ht, "color", &str);
82 printf("color: %s\n", str);
83 igraph_hashtable_get(&ht, "size", &str);
84 printf("size: %s\n", str);
85 igraph_hashtable_get(&ht, "shape", &str);
86 printf("shape: %s\n", str);
87
88 igraph_hashtable_getkeys(&ht, &keys);
89 for (i = 0; i < igraph_strvector_size(keys); i++) {
90 igraph_strvector_get(keys, i, &str);
91 printf("%s ", str);
92 }
93 printf("\n");
94
95 igraph_hashtable_destroy(&ht);
96
97 /* addset2 */
98 igraph_hashtable_init(&ht);
99 igraph_hashtable_addset2(&ht, "color", "green", "redddd", 3);
100 igraph_hashtable_addset2(&ht, "size", "", "4111", 1);
101 igraph_hashtable_addset2(&ht, "color", "", "greysdsdf", 4);
102 igraph_hashtable_addset2(&ht, "shape", "", "circle", 6);
103 igraph_hashtable_addset(&ht, "shape", "", "diamond");
104
105 igraph_hashtable_get(&ht, "color", &str);
106 printf("color: %s\n", str);
107 igraph_hashtable_get(&ht, "size", &str);
108 printf("size: %s\n", str);
109 igraph_hashtable_get(&ht, "shape", &str);
110 printf("shape: %s\n", str);
111
112 igraph_hashtable_reset(&ht);
113
114 igraph_hashtable_get(&ht, "color", &str);
115 printf("color: %s\n", str);
116 igraph_hashtable_get(&ht, "size", &str);
117 printf("size: %s\n", str);
118 igraph_hashtable_get(&ht, "shape", &str);
119 printf("shape: %s\n", str);
120
121 igraph_hashtable_getkeys(&ht, &keys);
122 for (i = 0; i < igraph_strvector_size(keys); i++) {
123 igraph_strvector_get(keys, i, &str);
124 printf("%s ", str);
125 }
126 printf("\n");
127
128 igraph_hashtable_destroy(&ht);
129
130 VERIFY_FINALLY_STACK();
131
132 return 0;
133 }
134