1
#ifndef _INCLUDED_HASHCLASSES_H_
2
#define _INCLUDED_HASHCLASSES_H_
8
Note that with the Gnu g++ compiler 3.2 (and beyond?) the ext/ header
9
uses the __gnu_cxx namespace for symbols defined in these header files.
11
When using compilers before version 3.2, do:
13
before including this file to circumvent problems that may occur
14
because of these namespace conventions which were not yet used in versions
19
#ifdef __GXX_EXPERIMENTAL_CXX0X__
20
#include <unordered_map>
21
#define hash_map unordered_map
23
#define __hash_map_ns std
25
#include <ext/hash_map>
26
#define __hash_ns __gnu_cxx
27
#define __hash_map_ns __gnu_cxx
30
//#include <backward/hash_map>
34
This file is copyright (c) GPL, 2001-2004
35
==========================================
36
august 2004: redundant include guards removed
38
october 2002: provisions for using the hashclasses with the g++ 3.2
39
compiler were incorporated.
41
april 2002: namespace FBB introduced
42
abbreviated class templates defined,
43
see the END of this comment section for examples of how
44
to use these abbreviations.
46
jan 2002: redundant include guards added,
47
required header files adapted,
48
for_each() rather than transform() used
50
With hash_maps using char const * for the keys:
53
* Use `HashCharPtr' as 3rd template argument for case-sensitive keys
54
* Use `HashCaseCharPtr' as 3rd template argument for case-insensitive
57
* Use `EqualCharPtr' as 4th template argument for case-sensitive keys
58
* Use `EqualCaseCharPtr' as 4th template argument for case-insensitive
62
With hash_maps using std::string for the keys:
65
* Use `HashString' as 3rd template argument for case-sensitive keys
66
* Use `HashCaseString' as 3rd template argument for case-insensitive keys
68
* OMIT the 4th template argument for case-sensitive keys
69
* Use `EqualCaseString' as 4th template argument for case-insensitive
73
Examples, using int as the value type. Any other type can be used instead
76
// key is char const *, case sensitive
77
__gnu_cxx::hash_map<char const *, int, FBB::HashCharPtr,
81
// key is char const *, case insensitive
82
__gnu_cxx::hash_map<char const *, int, FBB::HashCaseCharPtr,
83
FBB::EqualCaseCharPtr >
86
// key is std::string, case sensitive
87
__gnu_cxx::hash_map<std::string, int, FBB::HashString>
90
// key is std::string, case insensitive
91
__gnu_cxx::hash_map<std::string, int, FBB::HashCaseString,
95
Instead of the above full typedeclarations, the following shortcuts should
98
FBB::CharPtrHash<int> // key is char const *, case sensitive
101
FBB::CharCasePtrHash<int> // key is char const *, case insensitive
104
FBB::StringHash<int> // key is std::string, case sensitive
107
FBB::StringCaseHash<int> // key is std::string, case insensitive
110
With these template types iterators and other map-members are also
113
--------------------------------------------------------------------------
114
extern FBB::StringHash<int> dh;
116
for (FBB::StringHash<int>::iterator it = dh.begin(); it != dh.end(); it++)
117
_debugLevel4(it->first << " - " << it->second);
118
--------------------------------------------------------------------------
120
Feb. 2001 - April 2002
121
Frank B. Brokken (f.b.brokken@rug.nl)
124
/// The Frank B. Brokken namespace
131
size_t operator()(char const *str) const
133
return __hash_ns::hash<char const *>()(str);
140
bool operator()(char const *x, char const *y) const
142
return !strcmp(x, y);
146
class HashCaseCharPtr
149
size_t operator()(char const *str) const
152
for_each(s.begin(), s.end(), *this);
153
return __hash_ns::hash<char const *>()(s.c_str());
155
void operator()(char &c) const
161
class EqualCaseCharPtr
164
bool operator()(char const *x, char const *y) const
166
return !strcasecmp(x, y);
173
size_t operator()(std::string const &str) const
175
return __hash_ns::hash<char const *>()(str.c_str());
179
class HashCaseString: public HashCaseCharPtr
182
size_t operator()(std::string const &str) const
184
return HashCaseCharPtr::operator()(str.c_str());
188
class EqualCaseString
191
bool operator()(std::string const &s1, std::string const &s2) const
193
return !strcasecmp(s1.c_str(), s2.c_str());
198
template<typename Value>
199
class CharPtrHash: public
200
__hash_ns::hash_map<char const *, Value, HashCharPtr, EqualCharPtr >
205
template <typename InputIterator>
206
CharPtrHash(InputIterator first, InputIterator beyond)
208
__hash_ns::hash_map<char const *, Value, HashCharPtr,
209
EqualCharPtr>(first, beyond)
213
template<typename Value>
214
class CharCasePtrHash: public
215
__hash_ns::hash_map<char const *, Value, HashCaseCharPtr,
221
template <typename InputIterator>
222
CharCasePtrHash(InputIterator first, InputIterator beyond)
224
__hash_ns::hash_map<char const *, Value,
225
HashCaseCharPtr, EqualCaseCharPtr>
230
template<typename Value>
231
class StringHash: public __hash_ns::hash_map<std::string, Value,
237
template <typename InputIterator>
238
StringHash(InputIterator first, InputIterator beyond)
240
__hash_ns::hash_map<std::string, Value, HashString>
246
template<typename Value>
247
class StringCaseHash: public
248
__hash_ns::hash_map<std::string, Value, HashCaseString,
254
template <typename InputIterator>
255
StringCaseHash(InputIterator first, InputIterator beyond)
257
__hash_ns::hash_map<std::string,
258
Value, HashCaseString,
259
EqualCaseString>(first, beyond)
263
/* template<typename Key, typename Value>
265
__hash_ns::hash_map<Key, Value,
266
__hash_ns::hash<Key>(),