From 91b1b6cec4776d8c2e48b54e16d698abcea6bbfe Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Thu, 4 Mar 2010 22:54:38 +0100 Subject: Clean up the unordered containers fix. (bzr r9142) --- src/util/Makefile_insert | 4 +-- src/util/set-types.h | 55 ----------------------------- src/util/unordered-containers.h | 78 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 57 deletions(-) delete mode 100644 src/util/set-types.h create mode 100644 src/util/unordered-containers.h (limited to 'src/util') diff --git a/src/util/Makefile_insert b/src/util/Makefile_insert index 3d3c88940..1908aea19 100644 --- a/src/util/Makefile_insert +++ b/src/util/Makefile_insert @@ -16,12 +16,12 @@ ink_common_sources += \ util/map-list.h \ util/mathfns.h \ util/reverse-list.h \ - util/set-types.h \ util/share.h \ util/share.cpp \ util/tuple.h \ util/units.cpp \ - util/units.h + util/units.h \ + util/unordered-containers.h # ###################### # ### CxxTest stuff #### diff --git a/src/util/set-types.h b/src/util/set-types.h deleted file mode 100644 index f6752fb64..000000000 --- a/src/util/set-types.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef SEEN_SET_TYPES_H -#define SEEN_SET_TYPES_H - - -/** @file - * Simple wrapper to disambiguate hash/unordered lists & sets. - */ -/* Authors: - * Jon A. Cruz - * - * Copyright (C) 2010 Authors - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#if defined(HAVE_TR1_UNORDERED_SET) - -# include -# include -# define optim_set std::tr1::unordered_set -# define optim_map std::tr1::unordered_map - -// TODO test on platform with this detected: -//#elif defined(HAVE_UNORDERED_SET) -// -//# include -//# include -//#define optim_set std::unordered_set -//#define optim_map std::unordered_map - -#elif defined(HAVE_EXT_HASH_SET) - -# include -# include -# define optim_set __gnu_cxx::hash_set -# define optim_map __gnu_cxx::hash_map -# define USE_GNU_HASHES 1 - -#endif - - -#endif // SEEN_SET_TYPES_H -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/util/unordered-containers.h b/src/util/unordered-containers.h new file mode 100644 index 000000000..aaf771959 --- /dev/null +++ b/src/util/unordered-containers.h @@ -0,0 +1,78 @@ +/** @file + * @brief Compatibility wrapper for unordered containers. + */ +/* Authors: + * Jon A. Cruz + * Krzysztof KosiƄski + * + * Copyright (C) 2010 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_INK_UTIL_UNORDERED_CONTAINERS_H +#define SEEN_INK_UTIL_UNORDERED_CONTAINERS_H + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#if defined(HAVE_TR1_UNORDERED_SET) + +# include +# include +# define INK_UNORDERED_SET std::tr1::unordered_set +# define INK_UNORDERED_MAP std::tr1::unordered_map +# define INK_HASH std::tr1::hash + +#elif defined(HAVE_BOOST_UNORDERED_SET) +# include +# include +# define INK_UNORDERED_SET boost::unordered_set +# define INK_UNORDERED_MAP boost::unordered_map +# define INK_HASH boost::hash + +#elif defined(HAVE_EXT_HASH_SET) + +# include +# include +# include +# define INK_UNORDERED_SET __gnu_cxx::hash_set +# define INK_UNORDERED_MAP __gnu_cxx::hash_map +# define INK_HASH __gnu_cxx::hash + +namespace __gnu_cxx { +// hash function for pointers +// TR1 and Boost have this defined by default, __gnu_cxx doesn't +template +struct hash : public std::unary_function { + std::size_t operator()(T *p) const { + // Taken from Boost + std::size_t x = static_cast(reinterpret_cast(p)); + return x + (x >> 3); + } +}; +} // namespace __gnu_cxx +#endif + +#else +/// Name (with namespace) of the unordered set template. +#define INK_UNORDERED_SET +/// Name (with namespace) of the unordered map template. +#define INK_UNORDERED_MAP +/// Name (with namespace) of the hash template. +#define INK_HASH + +#endif + +#endif // SEEN_SET_TYPES_H +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : -- cgit v1.2.3