Fixed some typos.
[libfirm] / ir / ir / irnodehashmap.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @author    Matthias Braun
23  * @date      30.03.2007
24  * @brief     A nodemap. This should be preferred over a simple pset, because
25  *            it guarantees deterministic behavior when iterating of the
26  *            hashmap
27  */
28 #include "config.h"
29
30 #include "irnodehashmap.h"
31 #include "irnode_t.h"
32 #include "hashptr.h"
33
34 static ir_nodehashmap_entry_t null_nodehashmap_entry = { NULL, NULL };
35
36 #define DO_REHASH
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)
52
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,
58                                                ir_node *node);
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,
62                                              const ir_node *node);
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
68
69 #include "hashset.c.inl"
70
71 void ir_nodehashmap_init(ir_nodehashmap_t *nodehashmap)
72 {
73         ir_nodehashmap_init_size(nodehashmap, 16);
74 }
75
76 void *(ir_nodehashmap_get)(const ir_nodehashmap_t *self, const ir_node *node)
77 {
78         ir_nodehashmap_entry_t *entry = ir_nodehashmap_find_(self, node);
79         return entry->data;
80 }
81
82 void ir_nodehashmap_insert(ir_nodehashmap_t *self, ir_node *node, void *data)
83 {
84         ir_nodehashmap_entry_t *entry = ir_nodehashmap_insert_(self, node);
85         entry->data                   = data;
86 }