SheafSystem  0.0.0.0
std_unordered_set.h
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 #ifndef STD_UNORDERED_SET_H
19 #define STD_UNORDERED_SET_H
20 
21 #define HAVE_UNORDERED_SET 1
22 
23 #ifdef HAVE_UNORDERED_SET
24 
25 // Using unordered_set
26 
27 #include <unordered_set>
28 
29 #ifndef SHEAF_BEGIN_UNORDERED_NAMESPACE
30 namespace unordered = std;
31 #define SHEAF_BEGIN_UNORDERED_NAMESPACE namespace std {
32 #define SHEAF_END_UNORDERED_NAMESPACE }
33 #endif
34 
35 #else
36 
37 // Using tr1/unordered_set
38 
39 #include <tr1/unordered_set>
40 
41 #ifndef SHEAF_BEGIN_UNORDERED_NAMESPACE
42 namespace unordered = std::tr1;
43 #define SHEAF_BEGIN_UNORDERED_NAMESPACE namespace std { namespace tr1 {
44 #define SHEAF_END_UNORDERED_NAMESPACE }}
45 #endif
46 
47 #endif // HAVE_UNORDERED_SET
48 
49 
50 
52 
53 // If hash_cstr has not been defined by std_unordered_map,
54 // define it.
55 
56 #ifndef HAVE_HASH_CSTR
57 #define HAVE_HASH_CSTR 1
58 
59 #ifndef STD_CSTRING_H
60 #include "std_cstring.h"
61 #endif
62 
63 SHEAF_BEGIN_UNORDERED_NAMESPACE
64 
65  struct key_test
66  {
67  public:
68  bool operator()(const char* s1, const char* s2) const
69  {
70  return strcmp(s1, s2) == 0;
71  }
72  };
73 
74  struct hash_cstr
75  {
76  size_t operator()(const char* __s) const
77  {
78  unsigned long __h = 0;
79  for ( ; *__s; ++__s)
80  __h = 5*__h + *__s;
81  return size_t(__h);
82  }
83  };
84 
85 SHEAF_END_UNORDERED_NAMESPACE
86 
87 #endif // HAVE_HASH_CSTR
88 
89 #endif // STD_UNORDERED_SET_H
STL namespace.