1 /* src/toolbox/hashtable.hpp - hashtable classes
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 Copyright (C) 2009 Theobroma Systems Ltd.
7 This file is part of CACAO.
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.
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.
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
27 #ifndef _HASHTABLE_HPP
28 #define _HASHTABLE_HPP
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>
41 * Default hashing function for hashtable implementation.
43 template<class T> class Hasher {
49 * Hashtable implementation.
51 template<class Key, class T,
52 class Hash = Hasher<Key>,
53 class Pred = std::equal_to<Key> >
55 protected std::tr1::unordered_map<Key,T,Hash,Pred> {
58 Hashtable(size_t n) : std::tr1::unordered_map<Key,T,Hash,Pred>(n) {}
60 // Make iterator of TR1 unordered map visible.
61 using std::tr1::unordered_map<Key,T,Hash,Pred>::iterator;
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;
70 // Required by LockableHashtable.
71 #include "threads/mutex.hpp"
75 * Hashtable implementation with a Mutex.
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>,
85 LockableHashtable(size_t n) : Hashtable<Key,T,Hash,Pred>(n) {}
90 #endif /* _HASHTABLE_HPP */
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 * ---------------------------------------------------------------------
100 * indent-tabs-mode: t
104 * vim:noexpandtab:sw=4:ts=4: