-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstl.h
129 lines (106 loc) · 2.88 KB
/
stl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*---------------------------------------------------------------------------
* ADOM Sage - frontend for ADOM
*
* Copyright (c) 2002 Joshua Kelley; see LICENSE for details
*
* Header file for ADOM Sage containing STL-related stuff. STL stuff is
* somewhat involved, and STL details (such as use of hash_map) differ between
* g++ and MSVC, so they're stuffed into here.
*/
#include <vector>
#include <string>
#include <ext/hash_map>
#include <list>
#include <map>
#include <deque>
#include <cstring>
using namespace std;
using namespace __gnu_cxx;
/*---------------------------------------------------------------------------
* STL helpers - common
*/
struct ltstr
{
bool operator()(const char *s1, const char *s2) const
{
return strcmp(s1, s2) < 0;
}
};
/*---------------------------------------------------------------------------
* STL helpers - Linux g++
*/
#ifndef _WIN32
struct eqstr
{
bool operator()(const char *s1, const char *s2) const
{
return strcmp(s1, s2) == 0;
}
};
struct eqcasestr
{
bool operator()(const char *s1, const char *s2) const
{
return strcasecmp(s1, s2) == 0;
}
};
#define STRING_HASH(t) hash_map<const char *, t, hash<const char *>, eqstr>
#define STRING_CASE_HASH(t) hash_map<const char *, t, hash<const char*>, \
eqcasestr>
/*---------------------------------------------------------------------------
* STL helpers - Microsoft Visual C++
*/
#else
// Specialized hash_compares modified from Andre Bremer's, off of Google Groups
class string_hash_compare
{
public:
enum
{
bucket_size = 4,
min_buckets = 8
};
// hash algorithm taken from SGI's STL
size_t operator()(const char *_Keyval) const
{
const char *__s = _Keyval;
unsigned long __h = 0;
for ( ; *__s; ++__s)
{
__h = 5 * __h + *__s;
}
return size_t(__h);
}
bool operator()(const char *_Keyval1, const char *_Keyval2) const
{
return strcmp(_Keyval1, _Keyval2) < 0;
}
};
class string_case_hash_compare
{
public:
enum
{
bucket_size = 4,
min_buckets = 8
};
// hash algorithm taken from SGI's STL
size_t operator()(const char *_Keyval) const
{
const char *__s = _Keyval;
unsigned long __h = 0;
for ( ; *__s; ++__s)
{
__h = 5 * __h + *__s;
}
return size_t(__h);
}
bool operator()(const char *_Keyval1, const char *_Keyval2) const
{
return _stricmp(_Keyval1, _Keyval2) < 0;
}
};
#define STRING_HASH(t) hash_map<const char *, t, string_hash_compare>
#define STRING_CASE_HASH(t) hash_map<const char *, t, string_case_hash_compare>
using namespace std;
#endif