merged volatile memory barriers
[cacao.git] / src / toolbox / hashtable.hpp
1 /* src/toolbox/hashtable.hpp - hashtable classes
2
3    Copyright (C) 2009
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5    Copyright (C) 2009 Theobroma Systems Ltd.
6
7    This file is part of CACAO.
8
9    This program is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License as
11    published by the Free Software Foundation; either version 2, or (at
12    your option) any later version.
13
14    This program is distributed in the hope that it will be useful, but
15    WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22    02110-1301, USA.
23
24 */
25
26
27 #ifndef _HASHTABLE_HPP
28 #define _HASHTABLE_HPP
29
30 #include "config.h"
31
32 #if __cplusplus
33
34 // XXX This is a TR1 header and not (yet) part of the C++ standard, so we
35 // should not use it. The solution is to implement the below stuff
36 // ourselves. This will be done, sometimes, soon, I hope ...
37 #include <tr1/unordered_map>
38
39
40 /**
41  * Default hashing function for hashtable implementation.
42  */
43 template<class T> class Hasher {
44         // XXX Implement me!
45 };
46
47
48 /**
49  * Hashtable implementation.
50  */
51 template<class Key, class T,
52                 class Hash = Hasher<Key>,
53                 class Pred = std::equal_to<Key> >
54 class Hashtable :
55                 protected std::tr1::unordered_map<Key,T,Hash,Pred> {
56 public:
57         // Constructor.
58         Hashtable(size_t n) : std::tr1::unordered_map<Key,T,Hash,Pred>(n) {}
59
60         // Make iterator of TR1 unordered map visible.
61         using std::tr1::unordered_map<Key,T,Hash,Pred>::iterator;
62
63         // Make functions of TR1 unordered map visible.
64         using std::tr1::unordered_map<Key,T,Hash,Pred>::end;
65         using std::tr1::unordered_map<Key,T,Hash,Pred>::find;
66         using std::tr1::unordered_map<Key,T,Hash,Pred>::insert;
67 };
68
69
70 // Required by LockableHashtable.
71 #include "threads/mutex.hpp"
72
73
74 /**
75  * Hashtable implementation with a Mutex.
76  */
77 template<class Key, class T,
78                 class Hash = Hasher<Key>,
79                 class Pred = std::equal_to<Key> >
80 class LockableHashtable :
81                 public Hashtable<Key,T,Hash,Pred>,
82                 public Mutex {
83 public:
84         // Constructor.
85         LockableHashtable(size_t n) : Hashtable<Key,T,Hash,Pred>(n) {}
86 };
87
88 #endif
89
90 #endif /* _HASHTABLE_HPP */
91
92
93 /*
94  * These are local overrides for various environment variables in Emacs.
95  * Please do not remove this and leave it at the end of the file, where
96  * Emacs will automagically detect them.
97  * ---------------------------------------------------------------------
98  * Local variables:
99  * mode: c++
100  * indent-tabs-mode: t
101  * c-basic-offset: 4
102  * tab-width: 4
103  * End:
104  * vim:noexpandtab:sw=4:ts=4:
105  */