CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
OdHashMap.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_MAP_H_
25#define _ODA_HASH_MAP_H_
26
27/* hash_map 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_map which uses separate hasher and predicate
32 template arguments. In this implementations predicate defined as std::equal_to.
33 Now this type of hash maps included in C++11 standart as unordered_map.
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_map
36 implementation, which invokes std::less predicate, so we can't emulate unordered_map
37 through this container. */
38// #ifdef UNORDEREDMAP_SUPPORTED
39// Syntax: OdUnorderedMap<KeyType, ValueType, HashFunction, EqualityPredicate, Allocator>
40
41#if defined(__GNUC__)
42// GCC
43#define _GLIBCXX_PERMIT_BACKWARD_HASH
44#include <ext/hash_map>
45#define UNORDEREDMAP_SUPPORTED
46// This is for GCC-3.1+, GCC 3.0.x puts hash_map 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 OdUnorderedMap __gnu_cxx::hash_map
50#define OdUnorderedMap_DefaultHasher __gnu_cxx::hash
51//for x86
52#if OD_SIZEOF_LONG == 4
53namespace __gnu_cxx {
54 template<>
55 struct hash<OdUInt64>
56 {
57 size_t operator()(const OdUInt64& handle) const { return handle; }
58 };
59}
60#endif
61#elif defined(__sun)
62// sparc on Sun Studio compiler, solaris
63// SUNpro uses Cstd by default which is haven't hash_map. But SUNpro ships with -library=stlport4
64// which is could be enabled by compiler and linker options.
65// LIBSTLPORT = -library=no%Cstd -L../../lib -lstlport_sunpro64
66// First of all include <utility> to detect which STL is actually configured to use:
67#include <utility>
68// Enable hash_map only if stlport is used:
69#ifdef _STLPORT_VERSION
70#include <hash_map>
71#define UNORDEREDMAP_SUPPORTED
72#define OdUnorderedMap std::hash_map
73#define OdUnorderedMap_DefaultHasher std::hash
74#endif // _STLPORT_VERSION
75#elif defined(_MSC_VER) || defined(__BORLANDC__)
76// MSVC, BB (Dinkumware)
77#if (_MSC_VER >= 1900)
78#include <unordered_map>
79#define UNORDEREDMAP_SUPPORTED
80#define OdUnorderedMap std::unordered_map
81#define OdUnorderedMap_DefaultHasher std::hash
82#endif
83#elif defined(sgi)
84// SGI (StlPort)
85#include <hash_map>
86#define UNORDEREDMAP_SUPPORTED
87#define OdUnorderedMap std::hash_map
88#define OdUnorderedMap_DefaultHasher std::hash
89#elif defined(__hpux)
90// HPUX
91// HP aCC doesn't include an SGI-like hash_map. For this platform (or
92// any others using Rogue Wave Software's Tools.h++ library), we wrap
93// around them in std::
94#include <rw/stdex/hashmap.h>
95#if 1 // to wrap in std if necessary
96//#ifndef RW_ALLOCATOR_PLAIN
97namespace std {
98 template <class DataType> struct hash {
99 size_t operator()(const DataType& x) const { return static_cast<size_t>(x); }
100 };
101 template < class KeyVal,
102 class Value,
103 class _HashFcn = hash<KeyVal>,
104 class Pred = equal_to<KeyVal>,
105 class Alloc = allocator <pair <const KeyVal, Value> > >
106 class hash_map : public rw_hashmap < KeyVal, Value, _HashFcn, Pred, Alloc > { };
107}
108#define UNORDEREDMAP_SUPPORTED
109#define OdUnorderedMap std::hash_map
110#define OdUnorderedMap_DefaultHasher std::hash
111//#endif
112#else // clear way without wrapping
113#define UNORDEREDMAP_SUPPORTED
114#define OdUnorderedMap rw_hashmap
115#define OdUnorderedMap_DefaultHasher rw_hash
116#endif
117#else
118// List of known platforms which isn't support hash_map:
119// MSVC6 and earlier
120// solaris w/o stlport
121#error Unknown platform... check hash_map support
122#endif
123
124/* Dinkumware hash_map implementation require following specification of hasher and predicate:
125 struct Hasher {
126 enum { bucket_size = 4, min_buckets = 8 };
127 size_t operator()(const Key &key) const {
128 return hash(key);
129 }
130 bool operator()(const Key &ls, const Key &rs) const {
131 return ls < rs;
132 }
133 };
134 It is combines hash function and predicate. We can use this specification as client for
135 OdUnorderedMap implementation too using two comparisons through less predicate:
136 equal_to == !(l < r) && !(r < l). Of course this solution can cause perfomance loss
137 if keys comparison isn't simple, but at least it will work onto all platforms. */
138// #ifdef HASHMAP_SUPPORTED
139// Syntax: OdHashMapLs<KeyType, ValType, HashWithLessPredicate, Allocator>
140
141#ifdef UNORDEREDMAP_SUPPORTED
142#define HASHMAP_SUPPORTED
143template <class Key> struct od_std_hash_map_def_func : public OdUnorderedMap_DefaultHasher<Key>, public std::less<Key> {};
144template <class Key, class _HashFcn>
145struct od_std_hash_map_generalized_equal_to : protected _HashFcn
146{ bool operator()(const Key& leftArg, const Key& rightArg) const {
147 return !_HashFcn::operator()(leftArg, rightArg) && !_HashFcn::operator()(rightArg, leftArg); } };
152template <class Key, class Value, class _HashFcn = od_std_hash_map_def_func<Key>, class Alloc = std::allocator<std::pair<const Key, Value> > >
153class OdHashMapLs : public OdUnorderedMap<Key, Value, _HashFcn, od_std_hash_map_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_map>
158#define HASHMAP_SUPPORTED
159#define OdHashMapLs stdext::hash_map
160#define OdHashMap_DefaultHasher stdext::hash_compare
161#endif
162#endif
163
164/* Typically default implementation of predicate is enough for our needs.
165 OdHashMap template doesn't require specification of predicate and uses default
166 which is depends from hash_map implementation. */
167// #ifdef HASHMAP_SUPPORTED
168// Syntax: OdHashMap<KeyType, ValType, HashFunction, Allocator>
169#ifdef UNORDEREDMAP_SUPPORTED
173template <class Key, class Value, class HashFcn = OdUnorderedMap_DefaultHasher<Key>, class Alloc = std::allocator<std::pair<const Key, Value> > >
174class OdHashMap : public OdUnorderedMap<Key, Value, HashFcn, std::equal_to<Key>, Alloc> {};
175#elif defined(HASHMAP_SUPPORTED)
176template <class Key, class HashFcn>
177struct od_std_hash_map_add_less_predicate : public HashFcn, public std::less<Key> {
178 enum
179 { // parameters for hash table
180 bucket_size = 4, // 0 < bucket_size
181 min_buckets = 8
182 }; // min_buckets = 2 ^^ N, 0 < N
183 size_t operator()(const Key &key) const { return HashFcn::operator()(key); }
184 bool operator()(const Key &ls, const Key &rs) const { return std::less<Key>::operator()(ls, rs); } };
188template <class Key, class Value, class HashFcn = OdHashMap_DefaultHasher<Key>, class Alloc = std::allocator<std::pair<const Key, Value> > >
189class OdHashMap : public OdHashMapLs<Key, Value, od_std_hash_map_add_less_predicate<Key, HashFcn>, Alloc> {};
190#endif
191
192#endif //_ODA_HASH_MAP_H_
GLfloat x
Definition: gles2_ext.h:314