CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
OdHashSet.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24#ifndef _ODA_HASH_SET_H_
25#define _ODA_HASH_SET_H_
26
27/* hash_set isn't included into STL standart initially, so implementations is
28 available under different namespaces and could have implementation
29 differences. */
30
31/* Mostly STL implementations contain hash_set which uses separate hasher and predicate
32 template arguments. In this implementations predicate defined as std::equal_to.
33 Now this type of hash sets included in C++11 standart as unordered_set.
34 This implementation contained by all compilers, which uses SGI STL, but
35 Visual Studio contains it only since 2015 (previous versions contain Dinkumware hash_set
36 implementation, which invokes std::less predicate, so we can't emulate unordered_set
37 through this container. */
38// #ifdef UNORDEREDSET_SUPPORTED
39// Syntax: OdUnorderedSet<KeyType, HashFunction, EqualityPredicate, Allocator>
40
41#if defined(__GNUC__)
42// GCC
43#define _GLIBCXX_PERMIT_BACKWARD_HASH
44#include <ext/hash_set>
45#define UNORDEREDSET_SUPPORTED
46// This is for GCC-3.1+, GCC 3.0.x puts hash_set in the std namespace.
47// Older compilers such as GCC before version 3.0 do not keep
48// extensions in the `ext' directory, and ignore the `std' namespace.
49#define OdUnorderedSet __gnu_cxx::hash_set
50#define OdUnorderedSet_DefaultHasher __gnu_cxx::hash
51#elif defined(__sun)
52// sparc on Sun Studio compiler, solaris
53// SUNpro uses Cstd by default which is haven't hash_set. But SUNpro ships with -library=stlport4
54// which is could be enabled by compiler and linker options.
55// LIBSTLPORT = -library=no%Cstd -L../../lib -lstlport_sunpro64
56// First of all include <utility> to detect which STL is actually configured to use:
57#include <utility>
58// Enable hash_set only if stlport is used:
59#ifdef _STLPORT_VERSION
60#include <hash_set>
61#define UNORDEREDSET_SUPPORTED
62#define OdUnorderedSet std::hash_set
63#define OdUnorderedSet_DefaultHasher std::hash
64#endif // _STLPORT_VERSION
65#elif defined(_MSC_VER) || defined(__BORLANDC__)
66// MSVC, BB (Dinkumware)
67#if (_MSC_VER >= 1600)
68#include <unordered_set>
69#define UNORDEREDSET_SUPPORTED
70#define OdUnorderedSet std::unordered_set
71#define OdUnorderedSet_DefaultHasher std::hash
72#else
73#include <hash_set>
74#define HASHSET_SUPPORTED
75#define OdUnorderedSet stdext::hash_set
76namespace std
77{
78 template <class DataType> struct hash
79 {
80 size_t operator()(const DataType& x) const { return static_cast<size_t>(x); }
81 };
82}
83#define OdUnorderedSet_DefaultHasher std::hash
84#endif
85#elif defined(sgi)
86// SGI (StlPort)
87#include <hash_set>
88#define UNORDEREDSET_SUPPORTED
89#define OdUnorderedSet std::hash_set
90#define OdUnorderedSet_DefaultHasher std::hash
91#elif defined(__hpux)
92// HPUX
93// HP aCC doesn't include an SGI-like hash_set. For this platform (or
94// any others using Rogue Wave Software's Tools.h++ library), we wrap
95// around them in std::
96#include <rw/stdex/hashset.h>
97#if 1 // to wrap in std if necessary
98//#ifndef RW_ALLOCATOR_PLAIN
99namespace std {
100 template <class DataType> struct hash {
101 size_t operator()(const DataType& x) const { return static_cast<size_t>(x); }
102 };
103 template < class KeyVal,
104 class _HashFcn = hash<KeyVal>,
105 class Pred = equal_to<KeyVal>,
106 class Alloc = allocator<KeyVal> >
107 class hash_set : public rw_hashset < KeyVal, _HashFcn, Pred, Alloc > {};
108}
109#define UNORDEREDSET_SUPPORTED
110#define OdUnorderedSet std::hash_set
111#define OdUnorderedSet_DefaultHasher std::hash
112//#endif
113#else // clear way without wrapping
114#define UNORDEREDSET_SUPPORTED
115#define OdUnorderedSet rw_hashset
116#define OdUnorderedSet_DefaultHasher rw_hash
117#endif
118#else
119// List of known platforms which isn't support hash_set:
120// MSVC6 and earlier
121// solaris w/o stlport
122#error Unknown platform... check hash_set support
123#endif
124
125/* Dinkumware hash_set implementation require following specification of hasher and predicate:
126 struct Hasher {
127 enum { bucket_size = 4, min_buckets = 8 };
128 size_t operator()(const Key &key) const {
129 return hash(key);
130 }
131 bool operator()(const Key &ls, const Key &rs) const {
132 return ls < rs;
133 }
134 };
135 It is combines hash function and predicate. We can use this specification as client for
136 OdUnorderedSet implementation too using two comparisons through less predicate:
137 equal_to == !(l < r) && !(r < l). Of course this solution can cause perfomance loss
138 if keys comparison isn't simple, but at least it will work onto all platforms. */
139// #ifdef HASHSET_SUPPORTED
140// Syntax: OdHashSetLs<KeyType, HashWithLessPredicate, Allocator>
141
142#ifdef UNORDEREDSET_SUPPORTED
143#define HASHSET_SUPPORTED
144template <class Key> struct od_std_hash_set_def_func : public OdUnorderedSet_DefaultHasher<Key>, public std::less<Key> {};
145template <class Key, class _HashFcn>
146struct od_std_hash_set_generalized_equal_to : protected _HashFcn
147{ bool operator()(const Key& leftArg, const Key& rightArg) const {
148 return !_HashFcn::operator()(leftArg, rightArg) && !_HashFcn::operator()(rightArg, leftArg); } };
152template <class Key, class _HashFcn = od_std_hash_set_def_func<Key>, class Alloc = std::allocator<Key> >
153class OdHashSetLs : public OdUnorderedSet<Key, _HashFcn, od_std_hash_set_generalized_equal_to<Key, _HashFcn>, Alloc> {};
154#elif defined(_MSC_VER) || defined(__BORLANDC__)
155// MSVC (this container available only since vc7), BB
156#if (_MSC_VER >= 1300) || defined(__BORLANDC__)
157#include <hash_set>
158#define HASHSET_SUPPORTED
159#define OdHashSetLs stdext::hash_set
160#define OdHashSet_DefaultHasher stdext::hash_compare
161#endif
162#endif
163
164/* Typically default implementation of predicate is enough for our needs.
165 OdHashSet template doesn't require specification of predicate and uses default
166 which is depends from hash_set implementation. */
167// #ifdef HASHSET_SUPPORTED
168// Syntax: OdHashSet<KeyType, HashFunction, Allocator>
169#ifdef UNORDEREDSET_SUPPORTED
173template <class Key, class HashFcn = OdUnorderedSet_DefaultHasher<Key>, class Alloc = std::allocator<Key> >
174class OdHashSet : public OdUnorderedSet<Key, HashFcn, std::equal_to<Key>, Alloc> {};
175#elif defined(HASHSET_SUPPORTED)
176template <class Key, class HashFcn>
177struct od_std_hash_set_add_less_predicate : public HashFcn, public std::less<Key> {
178 size_t operator()(const Key &key) const { return HashFcn::operator()(key); }
179 bool operator()(const Key &ls, const Key &rs) const { return std::less<Key>::operator()(ls, rs); } };
183template <class Key, class HashFcn = OdHashSet_DefaultHasher<Key>, class Alloc = std::allocator<Key> >
184class OdHashSet : public OdHashSetLs<Key, od_std_hash_set_add_less_predicate<Key, HashFcn>, Alloc> {};
185#endif
186
187template <class T> struct OdHashSet_PtrHasher : OdUnorderedSet_DefaultHasher<OdIntPtr> {
188 enum { bucket_size = 4, min_buckets = 8 };
189 size_t operator()(const T* key) const { return OdUnorderedSet_DefaultHasher<OdIntPtr>::operator()((OdIntPtr)key); }
190};
191
192#endif //_ODA_HASH_SET_H_
ptrdiff_t OdIntPtr
GLfloat x
Definition: gles2_ext.h:314
size_t operator()(const T *key) const
Definition: OdHashSet.h:189