PIPS
newgen_map.h
Go to the documentation of this file.
1 /*
2 
3  $Id: newgen_map.h 1357 2016-03-02 08:18:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of NewGen.
8 
9  NewGen is free software: you can redistribute it and/or modify it under the
10  terms of the GNU General Public License as published by the Free Software
11  Foundation, either version 3 of the License, or any later version.
12 
13  NewGen is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16  License for more details.
17 
18  You should have received a copy of the GNU General Public License along with
19  NewGen. If not, see <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifndef newgen_map_included
24 #define newgen_map_included
25 
26 /*
27  * These are the functions defined in the Newgen map library.
28  */
29 
30 #define HASH_GET(start,image,h,k) \
31  hash_map_get((const hash_table)(h), (const void *)(k))
32 #define HASH_BOUND_P(start, image, h, k) \
33  hash_map_defined_p((const hash_table)(h), (const void *)(k))
34 #define HASH_UPDATE(start,image,h,k,v) \
35  hash_map_update((h), (const void *)(k), (const void *)(v))
36 #define HASH_EXTEND(start,image,h,k,v) \
37  hash_map_put((h), (const void *)(k), (const void *)(v))
38 #define HASH_DELETE(start,image,h,k) \
39  hash_map_del((h), (const void *)(k))
40 
41 // rather use FOREACH version below?
42 #define FUNCTION_MAP(type, start, image, k, v, code, fun) \
43  { \
44  type NGMID(f) = (fun); \
45  hash_table NGMID(h) = (type##_hash_table(NGMID(f))); \
46  register void * NGMID(i) = NULL; \
47  gen_chunk * NGMID(k); \
48  gen_chunk * NGMID(v); \
49  while ((NGMID(i) = \
50  hash_table_scan(NGMID(h), NGMID(i), \
51  (void**) &NGMID(k), (void**) &NGMID(v)))) \
52  { \
53  type##_key_type k = (type##_key_type) (NGMID(k))->start ; \
54  type##_value_type v = (type##_value_type) (NGMID(v))->image; \
55  code ; \
56  } \
57  }
58 
59 // see also HASH_FOREACH
60 #define FUNCTION_FOREACH(type, key, val, k, v, fun) \
61  type NGMID(f) = fun; \
62  message_assert("check domain", \
63  NGMID(f) && type##_defined_p(NGMID(f)) && \
64  type##_domain_number(NGMID(f)) == type##_domain); \
65  hash_table NGMID(h) = type##_hash_table(NGMID(f)); \
66  type##_key_type k; \
67  type##_value_type v; \
68  gen_chunk * NGMID(k); \
69  gen_chunk * NGMID(v); \
70  for (register void * NGMID(i) = NULL; \
71  ((NGMID(i) = \
72  hash_table_scan(NGMID(h), NGMID(i), \
73  (void**) & NGMID(k), (void**) & NGMID(v))), \
74  k = (type##_key_type) (NGMID(i)? NGMID(k)->key: NULL), \
75  v = (type##_value_type) (NGMID(i)? NGMID(v)->val: NULL), \
76  NGMID(i));)
77 
78 #endif /* newgen_map_included */