File: igraph_hashtable.c

package info (click to toggle)
igraph 0.7.1-2.1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 19,252 kB
  • sloc: ansic: 188,056; sh: 26,731; cpp: 18,275; yacc: 1,164; makefile: 959; lex: 484; xml: 405
file content (131 lines) | stat: -rw-r--r-- 4,275 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* -*- mode: C -*-  */
/* 
   IGraph library.
   Copyright (C) 2006-2012  Gabor Csardi <csardi.gabor@gmail.com>
   334 Harvard st, Cambridge MA, 02139 USA
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA 
   02110-1301 USA

*/

#include <igraph.h>
#include <igraph_types_internal.h>

int main() {

  igraph_hashtable_t ht;
  char *str;
  const igraph_strvector_t *keys;
  long int i;

  /* init and destroy */
  igraph_hashtable_init(&ht);
  igraph_hashtable_destroy(&ht);

  /* init, add some elements and destroy */
  igraph_hashtable_init(&ht);
  igraph_hashtable_addset(&ht, "color", "green", "red");
  igraph_hashtable_addset(&ht, "size", "", "4");
  igraph_hashtable_addset(&ht, "color", "", "grey");
  igraph_hashtable_addset(&ht, "shape", "", "circle");
  igraph_hashtable_addset(&ht, "shape", "", "diamond");
  igraph_hashtable_destroy(&ht);

  /* reset */
  igraph_hashtable_init(&ht);
  igraph_hashtable_addset(&ht, "color", "green", "red");
  igraph_hashtable_addset(&ht, "size", "", "4");
  igraph_hashtable_addset(&ht, "color", "", "grey");
  igraph_hashtable_addset(&ht, "shape", "", "circle");
  igraph_hashtable_addset(&ht, "shape", "", "diamond");
  igraph_hashtable_reset(&ht);
  igraph_hashtable_addset(&ht, "color", "green", "red");
  igraph_hashtable_addset(&ht, "size", "", "4");
  igraph_hashtable_addset(&ht, "color", "", "grey");
  igraph_hashtable_addset(&ht, "shape", "", "circle");
  igraph_hashtable_addset(&ht, "shape", "", "diamond");
  igraph_hashtable_destroy(&ht);

  /* Check semantics */
  igraph_hashtable_init(&ht);
  igraph_hashtable_addset(&ht, "color", "green", "red");
  igraph_hashtable_addset(&ht, "size", "", "4");
  igraph_hashtable_addset(&ht, "color", "", "grey");
  igraph_hashtable_addset(&ht, "shape", "", "circle");
  igraph_hashtable_addset(&ht, "shape", "", "diamond");
  
  igraph_hashtable_get(&ht, "color", &str);
  printf("color: %s\n", str);
  igraph_hashtable_get(&ht, "size", &str);
  printf("size: %s\n", str);
  igraph_hashtable_get(&ht, "shape", &str);
  printf("shape: %s\n", str);
  
  igraph_hashtable_reset(&ht);

  igraph_hashtable_get(&ht, "color", &str);
  printf("color: %s\n", str);
  igraph_hashtable_get(&ht, "size", &str);
  printf("size: %s\n", str);
  igraph_hashtable_get(&ht, "shape", &str);
  printf("shape: %s\n", str);
  
  igraph_hashtable_getkeys(&ht, &keys);
  for (i=0; i<igraph_strvector_size(keys); i++) {
    igraph_strvector_get(keys, i, &str);
    printf("%s ", str);
  }
  printf("\n");
  
  igraph_hashtable_destroy(&ht);

  /* addset2 */
  igraph_hashtable_init(&ht);
  igraph_hashtable_addset2(&ht, "color", "green", "redddd", 3);
  igraph_hashtable_addset2(&ht, "size", "", "4111", 1);
  igraph_hashtable_addset2(&ht, "color", "", "greysdsdf", 4);
  igraph_hashtable_addset2(&ht, "shape", "", "circle", 6);
  igraph_hashtable_addset(&ht, "shape", "", "diamond");
  
  igraph_hashtable_get(&ht, "color", &str);
  printf("color: %s\n", str);
  igraph_hashtable_get(&ht, "size", &str);
  printf("size: %s\n", str);
  igraph_hashtable_get(&ht, "shape", &str);
  printf("shape: %s\n", str);
  
  igraph_hashtable_reset(&ht);

  igraph_hashtable_get(&ht, "color", &str);
  printf("color: %s\n", str);
  igraph_hashtable_get(&ht, "size", &str);
  printf("size: %s\n", str);
  igraph_hashtable_get(&ht, "shape", &str);
  printf("shape: %s\n", str);
  
  igraph_hashtable_getkeys(&ht, &keys);
  for (i=0; i<igraph_strvector_size(keys); i++) {
    igraph_strvector_get(keys, i, &str);
    printf("%s ", str);
  }
  printf("\n");
  
  igraph_hashtable_destroy(&ht);
  
  if (!IGRAPH_FINALLY_STACK_EMPTY) return 1;

  return 0;
}