PR156: Preparation
[cacao.git] / src / toolbox / hashtable.hpp
1 /* src/toolbox/hashtable.hpp - hashtable classes
2
3    Copyright (C) 2009, 2011
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 #include <tr1/unordered_map>
35
36
37 /**
38  * Default hashing function for hashtable implementation.
39  */
40 template<class T> class Hasher {
41         // XXX Implement me!
42 };
43
44
45 /**
46  * Hashtable implementation.
47  */
48 template<class Key, class T,
49                 class Hash = Hasher<Key>,
50                 class Pred = std::equal_to<Key> >
51 class Hashtable :
52                 protected std::tr1::unordered_map<Key,T,Hash,Pred> {
53 public:
54         // Constructor.
55         Hashtable(size_t n) : std::tr1::unordered_map<Key,T,Hash,Pred>(n) {}
56
57         // Make iterator of TR1 unordered map visible.
58         using std::tr1::unordered_map<Key,T,Hash,Pred>::iterator;
59
60         // Make functions of TR1 unordered map visible.
61         using std::tr1::unordered_map<Key,T,Hash,Pred>::end;
62         using std::tr1::unordered_map<Key,T,Hash,Pred>::find;
63         using std::tr1::unordered_map<Key,T,Hash,Pred>::insert;
64 };
65
66
67 // Required by LockableHashtable.
68 #include "threads/mutex.hpp"
69
70
71 /**
72  * Hashtable implementation with a Mutex.
73  */
74 template<class Key, class T,
75                 class Hash = Hasher<Key>,
76                 class Pred = std::equal_to<Key> >
77 class LockableHashtable :
78                 public Hashtable<Key,T,Hash,Pred>,
79                 public Mutex {
80 public:
81         // Constructor.
82         LockableHashtable(size_t n) : Hashtable<Key,T,Hash,Pred>(n) {}
83 };
84
85 #endif
86
87 #endif /* _HASHTABLE_HPP */
88
89
90 /*
91  * These are local overrides for various environment variables in Emacs.
92  * Please do not remove this and leave it at the end of the file, where
93  * Emacs will automagically detect them.
94  * ---------------------------------------------------------------------
95  * Local variables:
96  * mode: c++
97  * indent-tabs-mode: t
98  * c-basic-offset: 4
99  * tab-width: 4
100  * End:
101  * vim:noexpandtab:sw=4:ts=4:
102  */