~ubuntu-branches/ubuntu/lucid/igraph/lucid

« back to all changes in this revision

Viewing changes to examples/simple/igraph_hashtable.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Malaterre
  • Date: 2009-11-16 18:12:42 UTC
  • Revision ID: james.westby@ubuntu.com-20091116181242-mzv9p5fz9uj57xd1
Tags: upstream-0.5.3
ImportĀ upstreamĀ versionĀ 0.5.3

Show diffs side-by-side

added added

removed removed

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