ipc/chromium/src/base/hash_tables.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/hash_tables.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +//
     1.8 +
     1.9 +//
    1.10 +// Deal with the differences between Microsoft and GNU implemenations
    1.11 +// of hash_map. Allows all platforms to use |base::hash_map| and
    1.12 +// |base::hash_set|.
    1.13 +//  eg:
    1.14 +//   base::hash_map<int> my_map;
    1.15 +//   base::hash_set<int> my_set;
    1.16 +//
    1.17 +
    1.18 +#ifndef BASE_HASH_TABLES_H_
    1.19 +#define BASE_HASH_TABLES_H_
    1.20 +
    1.21 +#include "build/build_config.h"
    1.22 +
    1.23 +#include "base/string16.h"
    1.24 +
    1.25 +#if defined(COMPILER_MSVC) || (defined(ANDROID) && defined(_STLP_STD_NAME))
    1.26 +#include <hash_map>
    1.27 +#include <hash_set>
    1.28 +namespace base {
    1.29 +#ifdef ANDROID
    1.30 +using _STLP_STD_NAME::hash_map;
    1.31 +using _STLP_STD_NAME::hash_set;
    1.32 +#else
    1.33 +using stdext::hash_map;
    1.34 +using stdext::hash_set;
    1.35 +#endif
    1.36 +}
    1.37 +#elif defined(COMPILER_GCC)
    1.38 +// This is a hack to disable the gcc 4.4 warning about hash_map and hash_set
    1.39 +// being deprecated.  We can get rid of this when we upgrade to VS2008 and we
    1.40 +// can use <tr1/unordered_map> and <tr1/unordered_set>.
    1.41 +#ifdef __DEPRECATED
    1.42 +#define CHROME_OLD__DEPRECATED __DEPRECATED
    1.43 +#undef __DEPRECATED
    1.44 +#endif
    1.45 +
    1.46 +#include <ext/hash_map>
    1.47 +#include <ext/hash_set>
    1.48 +#include <string>
    1.49 +
    1.50 +#ifdef CHROME_OLD__DEPRECATED
    1.51 +#define __DEPRECATED CHROME_OLD__DEPRECATED
    1.52 +#undef CHROME_OLD__DEPRECATED
    1.53 +#endif
    1.54 +
    1.55 +namespace base {
    1.56 +using __gnu_cxx::hash_map;
    1.57 +using __gnu_cxx::hash_set;
    1.58 +}  // namespace base
    1.59 +
    1.60 +namespace __gnu_cxx {
    1.61 +
    1.62 +// The GNU C++ library provides identiy hash functions for many integral types,
    1.63 +// but not for |long long|.  This hash function will truncate if |size_t| is
    1.64 +// narrower than |long long|.  This is probably good enough for what we will
    1.65 +// use it for.
    1.66 +
    1.67 +#define DEFINE_TRIVIAL_HASH(integral_type) \
    1.68 +    template<> \
    1.69 +    struct hash<integral_type> { \
    1.70 +      std::size_t operator()(integral_type value) const { \
    1.71 +        return static_cast<std::size_t>(value); \
    1.72 +      } \
    1.73 +    }
    1.74 +
    1.75 +DEFINE_TRIVIAL_HASH(long long);
    1.76 +DEFINE_TRIVIAL_HASH(unsigned long long);
    1.77 +
    1.78 +#undef DEFINE_TRIVIAL_HASH
    1.79 +
    1.80 +// Implement string hash functions so that strings of various flavors can
    1.81 +// be used as keys in STL maps and sets.  The hash algorithm comes from the
    1.82 +// GNU C++ library, in <tr1/functional>.  It is duplicated here because GCC
    1.83 +// versions prior to 4.3.2 are unable to compile <tr1/functional> when RTTI
    1.84 +// is disabled, as it is in our build.
    1.85 +
    1.86 +#define DEFINE_STRING_HASH(string_type) \
    1.87 +    template<> \
    1.88 +    struct hash<string_type> { \
    1.89 +      std::size_t operator()(const string_type& s) const { \
    1.90 +        std::size_t result = 0; \
    1.91 +        for (string_type::const_iterator i = s.begin(); i != s.end(); ++i) \
    1.92 +          result = (result * 131) + *i; \
    1.93 +        return result; \
    1.94 +      } \
    1.95 +    }
    1.96 +
    1.97 +DEFINE_STRING_HASH(std::string);
    1.98 +DEFINE_STRING_HASH(std::wstring);
    1.99 +
   1.100 +#if defined(WCHAR_T_IS_UTF32)
   1.101 +// If string16 and std::wstring are not the same type, provide a
   1.102 +// specialization for string16.
   1.103 +DEFINE_STRING_HASH(string16);
   1.104 +#endif  // WCHAR_T_IS_UTF32
   1.105 +
   1.106 +#undef DEFINE_STRING_HASH
   1.107 +
   1.108 +}  // namespace __gnu_cxx
   1.109 +
   1.110 +#endif  // COMPILER
   1.111 +
   1.112 +#endif  // BASE_HASH_TABLES_H_

mercurial