1
1
forked from 0ad/0ad

per discussion with Philip, remove STL_HASH_MAP etc. because they're ugly, rarely used and superseded by boost::unordered*

This was SVN commit r9111.
This commit is contained in:
janwas 2011-03-23 16:56:27 +00:00
parent 588bfa11bf
commit 1f7e8d7194
12 changed files with 26 additions and 255 deletions

View File

@ -37,7 +37,7 @@
# include <boost/unordered_map.hpp>
# define MAP boost::unordered_map
#else
# define MAP STL_HASH_MAP
# define MAP stdext::hash_map
#endif
/*

View File

@ -470,64 +470,6 @@ struct Any_stack : public Any_deque
};
//
// nonstandard containers (will probably be part of C++0x)
//
#if HAVE_STL_HASH
struct Any_hash_map: public ContainerBase<STL_HASH_MAP<int,int> >
{
#if STL_DINKUMWARE == 405
bool IsValid(size_t el_size) const
{
Any_list* list = (Any_list*)&_List;
if(!list->IsValid(el_size))
return false;
return true;
}
#endif
};
struct Any_hash_multimap : public Any_hash_map
{
};
struct Any_hash_set: public ContainerBase<STL_HASH_SET<int> >
{
#if STL_DINKUMWARE == 405
bool IsValid(size_t el_size) const
{
Any_list* list = (Any_list*)&_List;
if(!list->IsValid(el_size))
return false;
return true;
}
#endif
};
struct Any_hash_multiset : public Any_hash_set
{
};
#endif // HAVE_STL_HASH
#if HAVE_STL_SLIST
struct Any_slist: public Any_list
{
};
#endif // HAVE_STL_SLIST
//-----------------------------------------------------------------------------
// generic iterator - returns next element. dereferences and increments the

View File

@ -27,6 +27,8 @@
#include "precompiled.h"
#include "h_mgr.h"
#include <boost/unordered_map.hpp>
#include <limits.h> // CHAR_BIT
#include <string.h>
#include <stdlib.h>
@ -345,10 +347,10 @@ static LibError free_idx(ssize_t idx)
//
// note: there may be several RES_UNIQUE handles of the same type and key
// (e.g. sound files - several instances of a sound definition file).
// that wasn't forseen here, so we'll just refrain from adding to the index.
// that wasn't foreseen here, so we'll just refrain from adding to the index.
// that means they won't be found via h_find - no biggie.
typedef STL_HASH_MULTIMAP<uintptr_t, ssize_t> Key2Idx;
typedef boost::unordered_multimap<uintptr_t, ssize_t> Key2Idx;
typedef Key2Idx::iterator It;
static OverrunProtector<Key2Idx> key2idx_wrapper;

View File

@ -194,20 +194,6 @@ class TestWdbgSym : public CxxTest::TestSuite
m_int_int.insert(std::make_pair<int,int>(2, 2));
m_int_int.insert(std::make_pair<int,int>(3, 3));
STL_HASH_MAP<std::string, int> hm_string_int;
hm_string_int.insert(std::make_pair<std::string,int>("s5", 5));
hm_string_int.insert(std::make_pair<std::string,int>("s6", 6));
hm_string_int.insert(std::make_pair<std::string,int>("s7", 7));
STL_HASH_MAP<int, std::string> hm_int_string;
hm_int_string.insert(std::make_pair<int,std::string>(1, "s1"));
hm_int_string.insert(std::make_pair<int,std::string>(2, "s2"));
hm_int_string.insert(std::make_pair<int,std::string>(3, "s3"));
STL_HASH_MAP<int, int> hm_int_int;
hm_int_int.insert(std::make_pair<int,int>(1, 1));
hm_int_int.insert(std::make_pair<int,int>(2, 2));
hm_int_int.insert(std::make_pair<int,int>(3, 3));
std::set<uintptr_t> s_uintptr;
s_uintptr.insert(0x123); s_uintptr.insert(0x456);
@ -221,15 +207,6 @@ class TestWdbgSym : public CxxTest::TestSuite
std::vector<double> v_double_empty;
std::queue<double> q_double_empty;
std::stack<double> st_double_empty;
#if HAVE_STL_HASH
STL_HASH_MAP<double,double> hm_double_empty;
STL_HASH_MULTIMAP<double,std::wstring> hmm_double_empty;
STL_HASH_SET<double> hs_double_empty;
STL_HASH_MULTISET<double> hms_double_empty;
#endif
#if HAVE_STL_SLIST
STL_SLIST<double> sl_double_empty;
#endif
std::string str_empty;
std::wstring wstr_empty;
@ -245,15 +222,6 @@ class TestWdbgSym : public CxxTest::TestSuite
std::vector<double> v_double_uninit;
std::queue<double> q_double_uninit;
std::stack<double> st_double_uninit;
#if HAVE_STL_HASH
STL_HASH_MAP<double,double> hm_double_uninit;
STL_HASH_MULTIMAP<double,std::wstring> hmm_double_uninit;
STL_HASH_SET<double> hs_double_uninit;
STL_HASH_MULTISET<double> hms_double_uninit;
#endif
#if HAVE_STL_SLIST
STL_SLIST<double> sl_double_uninit;
#endif
std::string str_uninit;
std::wstring wstr_uninit;
}

View File

@ -72,128 +72,4 @@
# endif
#endif
// STL_HASH_MAP, STL_HASH_MULTIMAP, STL_HASH_SET
// these containers are useful but not part of C++98. most STL vendors
// provide them in some form; we hide their differences behind macros.
#if STL_GCC
// std::tr1::unordered_* is preferred, but that causes a linker error in
// old versions of GCC, so fall back to the (deprecated) non-standard
// ext in older than 4.2.0
#if GCC_VERSION >= 402
# include <tr1/unordered_map>
# include <tr1/unordered_set>
# define STL_HASH_MAP std::tr1::unordered_map
# define STL_HASH_MULTIMAP std::tr1::unordered_multimap
# define STL_HASH_SET std::tr1::unordered_set
# define STL_HASH_MULTISET std::tr1::unordered_multiset
# define STL_SLIST __gnu_cxx::slist
template<typename T>
size_t STL_HASH_VALUE(T v)
{
return std::tr1::hash<T>()(v);
}
#else // For older versions of GCC:
# include <ext/hash_map>
# include <ext/hash_set>
# define STL_HASH_MAP __gnu_cxx::hash_map
# define STL_HASH_MULTIMAP __gnu_cxx::hash_multimap
# define STL_HASH_SET __gnu_cxx::hash_set
# define STL_HASH_MULTISET __gnu_cxx::hash_multiset
# define STL_SLIST __gnu_cxx::slist
template<typename T>
size_t STL_HASH_VALUE(T v)
{
return __gnu_cxx::hash<T>()(v);
}
namespace __gnu_cxx
{
// Define some hash functions that GCC doesn't provide itself:
template<> struct hash<std::wstring>
{
size_t operator()(const std::wstring& s) const
{
const wchar_t* __s = s.c_str();
unsigned long __h = 0;
for ( ; *__s; ++__s)
__h = 5*__h + *__s;
return size_t(__h);
}
};
template<> struct hash<std::string>
{
size_t operator()(const std::string& __x) const
{
return __stl_hash_string(__x.c_str());
}
};
template<> struct hash<const void*>
{
// Nemesi hash function (see: http://mail-index.netbsd.org/tech-kern/2001/11/30/0001.html)
// treating the pointer as an array of bytes that is hashed.
size_t operator()(const void* __x) const
{
union {
const void* ptr;
unsigned char bytes[sizeof(void*)];
} val;
size_t h = 5381;
val.ptr = __x;
for(size_t i = 0; i < sizeof(val); ++i)
h = 257*h + val.bytes[i];
return 257*h;
}
};
}
#endif // GCC_VERSION
#elif STL_DINKUMWARE
# include <hash_map>
# include <hash_set>
// VC7 or above
# if MSC_VERSION >= 1300
# define STL_HASH_MAP stdext::hash_map
# define STL_HASH_MULTIMAP stdext::hash_multimap
# define STL_HASH_SET stdext::hash_set
# define STL_HASH_MULTISET stdext::hash_multiset
# define STL_HASH_VALUE stdext::hash_value
// VC6 and anything else (most likely name)
# else
# define STL_HASH_MAP std::hash_map
# define STL_HASH_MULTIMAP std::hash_multimap
# define STL_HASH_SET std::hash_set
# define STL_HASH_MULTISET std::hash_multiset
# define STL_HASH_VALUE std::hash_value
# endif // MSC_VERSION >= 1300
#endif
// nonstandard STL containers
#define HAVE_STL_SLIST 0
#if STL_DINKUMWARE
# define HAVE_STL_HASH 1
#else
# define HAVE_STL_HASH 0
#endif
#endif // #ifndef INCLUDED_STL

View File

@ -341,20 +341,9 @@ public:
const u8* Deserialize(const u8* buffer, const u8* bufferend);
};
// Hash function (for STL_HASH_MAP, etc)
class CStr_hash_compare
static inline size_t hash_value(const CStr& s)
{
public:
static const size_t bucket_size = 1;
static const size_t min_buckets = 16;
size_t operator() (const CStr& Key) const
{
return Key.GetHashCode();
}
bool operator() (const CStr& _Key1, const CStr& _Key2) const
{
return (_Key1 < _Key2);
}
};
return s.GetHashCode();
}
#endif

View File

@ -25,12 +25,10 @@
// When compiling CStr.cpp with PCH, the unidoubler stuff gets rather
// confusing because of all the nested inclusions, but this makes it work:
#undef CStr
#undef CStr_hash_compare
// First, set up the environment for the Unicode version
#define _UNICODE
#define CStr CStrW
#define CStr_hash_compare CStrW_hash_compare
#define tstring wstring
#define tchar wchar_t
#define _T(t) L ## t
@ -41,7 +39,6 @@
// Clean up all the macros
#undef _UNICODE
#undef CStr
#undef CStr_hash_compare
#undef tstring
#undef tchar
#undef _T
@ -49,7 +46,6 @@
// Now include the 8-bit version under the name CStr8
#define CStr CStr8
#define CStr_hash_compare CStr8_hash_compare
#define tstring string
#define tchar char
#define _T(t) t
@ -58,7 +54,6 @@
// Clean up the macros again, to minimise namespace pollution
#undef CStr
#undef CStr_hash_compare
#undef tstring
#undef tchar
#undef _T
@ -66,7 +61,6 @@
// To please the file that originally include CStr.h, make CStr an alias for CStr8:
#define CStr CStr8
#define CStr_hash_compare CStr8_hash_compare
#undef IN_UNIDOUBLER
#undef UNIDOUBLER_HEADER

View File

@ -23,6 +23,7 @@
#ifndef INCLUDED_SCRIPTABLEOBJECT
#define INCLUDED_SCRIPTABLEOBJECT
#include <boost/unordered_map.hpp>
#include "scripting/ScriptingHost.h"
#include "JSConversions.h"
@ -43,7 +44,7 @@ public:
class IJSObject
{
public:
typedef STL_HASH_MAP<CStrW, IJSProperty*, CStrW_hash_compare> PropertyTable;
typedef boost::unordered_map<CStrW, IJSProperty*> PropertyTable;
// Property getters and setters
typedef jsval (IJSObject::*GetFn)( JSContext* cx );

View File

@ -41,6 +41,8 @@
#ifndef INCLUDED_ENTITY
#define INCLUDED_ENTITY
#include <boost/unordered_map.hpp>
#include <deque>
#include "scripting/ScriptableComplex.h"
#include "ps/Vector2D.h"
@ -98,8 +100,8 @@ class CEntity : public CJSComplex<CEntity>, public IEventTarget
friend class CEntityManager;
friend class CUnit;
typedef STL_HASH_MAP<CStrW, CAura*, CStrW_hash_compare> AuraTable;
typedef STL_HASH_MAP<int, SEntityAction> ActionTable;
typedef boost::unordered_map<CStrW, CAura*> AuraTable;
typedef boost::unordered_map<int, SEntityAction> ActionTable;
typedef std::set<CAura*> AuraSet;
public:

View File

@ -16,6 +16,7 @@
*/
#include "precompiled.h"
#include <boost/unordered_set.hpp>
#include "Technology.h"
#include "TechnologyCollection.h"
#include "ps/CStr.h"
@ -31,7 +32,7 @@
#define LOG_CATEGORY L"Techs"
STL_HASH_SET<CStr, CStr_hash_compare> CTechnology::m_scriptsLoaded;
boost::unordered_set<CStr> CTechnology::m_scriptsLoaded;
CTechnology::CTechnology( const CStrW& name, CPlayer* player )
: m_Name(name), m_player(player)

View File

@ -46,7 +46,7 @@ class CTechnology : public CJSComplex<CTechnology>
bool isPercent;
Modifier(): value(0), isPercent(false) {}
};
static STL_HASH_SET<CStr, CStr_hash_compare> m_scriptsLoaded;
static boost::unordered_set<CStr> m_scriptsLoaded;
public:
CTechnology(const CStrW& name, CPlayer* player);

View File

@ -35,20 +35,16 @@ protected:
virtual void setNew(ssize_t x, ssize_t y, const T& val) = 0;
private:
struct hashfunc {
enum {
bucket_size = 4,
min_buckets = 8
};
size_t operator()(const std::pair<ssize_t, ssize_t>& p) const {
return STL_HASH_VALUE(p.first << 16) + STL_HASH_VALUE(p.second);
}
bool operator()(const std::pair<ssize_t, ssize_t>& a, const std::pair<ssize_t, ssize_t>& b) const {
return (a < b);
}
};
std::size_t hash_value(const std::pair<ssize_t, ssize_t>& p)
{
std::size_t seed = 0;
boost::hash_combine(seed, p.first << 16);
boost::hash_combine(seed, p.second);
return seed;
}
// TODO: more efficient representation
typedef STL_HASH_MAP<std::pair<ssize_t, ssize_t>, std::pair<T, T>, hashfunc> Data; // map of <x,y> -> <old_val, new_val>
typedef boost::unordered_map<std::pair<ssize_t, ssize_t>, std::pair<T, T>> Data; // map of <x,y> -> <old_val, new_val>
Data m_Data;
};