2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @author Matthias Braun
24 * @brief A nodemap. This should be preferred over a simple pset, because
25 * it guarantees deterministic behavior when iterating of the
30 #include "irnodehashmap.h"
34 static ir_nodehashmap_entry_t null_nodehashmap_entry = { NULL, NULL };
37 #define HashSet ir_nodehashmap_t
38 #define HashSetIterator ir_nodehashmap_iterator_t
39 #define ValueType ir_nodehashmap_entry_t
40 #define NullValue null_nodehashmap_entry
41 #define KeyType ir_node*
42 #define ConstKeyType const ir_node*
43 #define GetKey(value) (value).node
44 #define InitData(self,value,key) (value).node = (key)
45 #define Hash(self,key) ((unsigned)((key)->node_nr))
46 #define KeysEqual(self,key1,key2) (key1) == (key2)
47 #define SetRangeEmpty(ptr,size) memset(ptr, 0, (size) * sizeof((ptr)[0]))
48 #define EntrySetEmpty(value) (value).node = NULL
49 #define EntrySetDeleted(value) (value).node = (ir_node*) -1
50 #define EntryIsEmpty(value) ((value).node == NULL)
51 #define EntryIsDeleted(value) ((value).node == (ir_node*)-1)
53 void ir_nodehashmap_init_(ir_nodehashmap_t *self);
54 #define hashset_init ir_nodehashmap_init_
55 #define hashset_init_size ir_nodehashmap_init_size
56 #define hashset_destroy ir_nodehashmap_destroy
57 ir_nodehashmap_entry_t *ir_nodehashmap_insert_(ir_nodehashmap_t *self,
59 #define hashset_insert ir_nodehashmap_insert_
60 #define hashset_remove ir_nodehashmap_remove
61 ir_nodehashmap_entry_t *ir_nodehashmap_find_(const ir_nodehashmap_t *self,
63 #define hashset_find ir_nodehashmap_find_
64 #define hashset_size ir_nodehashmap_size
65 #define hashset_iterator_init ir_nodehashmap_iterator_init
66 #define hashset_iterator_next ir_nodehashmap_iterator_next
67 #define hashset_remove_iterator ir_nodehashmap_remove_iterator
69 #include "hashset.c.inl"
71 void ir_nodehashmap_init(ir_nodehashmap_t *nodehashmap)
73 ir_nodehashmap_init_size(nodehashmap, 16);
76 void *(ir_nodehashmap_get)(const ir_nodehashmap_t *self, const ir_node *node)
78 ir_nodehashmap_entry_t *entry = ir_nodehashmap_find_(self, node);
82 void ir_nodehashmap_insert(ir_nodehashmap_t *self, ir_node *node, void *data)
84 ir_nodehashmap_entry_t *entry = ir_nodehashmap_insert_(self, node);