You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by he...@apache.org on 2017/08/15 17:59:40 UTC

[5/7] incubator-impala git commit: IMPALA-5116: Remove deprecated hash_* types in gutil

IMPALA-5116: Remove deprecated hash_* types in gutil

The following class templates are substituted from C++11 standard.
__gnu_cxx::hash_map => std::unordered_map
__gnu_cxx::hash_set => std::unordered_set
__gnu_cxx::hash     => std::hash

Change-Id: I06af30fd15acd43a60e3c30af54056c96520b6e9
Reviewed-on: http://gerrit.cloudera.org:8080/7414
Reviewed-by: Jim Apple <jb...@apache.org>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/aaec43b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/aaec43b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/aaec43b9

Branch: refs/heads/master
Commit: aaec43b9a1dc1b1a2fb97ae257147c4f6d78f27a
Parents: 16ce201
Author: Jinchul <ji...@gmail.com>
Authored: Thu Jul 13 23:21:46 2017 +0900
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Tue Aug 15 16:20:57 2017 +0000

----------------------------------------------------------------------
 be/src/gutil/hash/hash.cc         |  13 ----
 be/src/gutil/hash/hash.h          | 133 +--------------------------------
 be/src/gutil/strings/join.h       |   6 --
 be/src/gutil/strings/serialize.cc |  17 ++---
 be/src/gutil/strings/serialize.h  |  17 ++---
 be/src/gutil/strings/split.cc     |  16 ++--
 be/src/gutil/strings/split.h      |  20 +++--
 7 files changed, 37 insertions(+), 185 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/aaec43b9/be/src/gutil/hash/hash.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/hash.cc b/be/src/gutil/hash/hash.cc
index beceab3..5a1988b 100644
--- a/be/src/gutil/hash/hash.cc
+++ b/be/src/gutil/hash/hash.cc
@@ -182,16 +182,3 @@ uint64 FingerprintInterleavedImplementation(const char *s, uint32 len) {
   mix(d, e, f);
   return CombineFingerprintHalves(c, f);
 }
-
-// Extern template definitions.
-
-#if defined(__GNUC__)
-#include <ext/hash_set>
-namespace __gnu_cxx {
-
-template class hash_set<std::string>;
-template class hash_map<std::string, std::string>;
-
-}  // namespace __gnu_cxx
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/aaec43b9/be/src/gutil/hash/hash.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/hash.h b/be/src/gutil/hash/hash.h
index f6a8b0a..ce17d43 100644
--- a/be/src/gutil/hash/hash.h
+++ b/be/src/gutil/hash/hash.h
@@ -77,12 +77,6 @@
 #include <stdint.h>     // for uintptr_t
 #include <string.h>
 #include <algorithm>
-#include <ext/hash_map>
-using __gnu_cxx::hash;
-using __gnu_cxx::hash_map;     // hacky way to make sure we import standard hash<> fns
-#include <ext/hash_set>
-using __gnu_cxx::hash;
-using __gnu_cxx::hash_set;
 #include <string>
 #include <utility>
 
@@ -98,32 +92,6 @@ using __gnu_cxx::hash_set;
 #include "gutil/hash/legacy_hash.h"
 #include "gutil/hash/string_hash.h"
 
-#include <ext/hash_set>
-namespace __gnu_cxx {
-
-
-// STLport and MSVC 10.0 above already define these.
-#if !defined(_STLP_LONG_LONG) && !(defined(_MSC_VER) && _MSC_VER >= 1600)
-
-#if defined(_MSC_VER)
-// MSVC's stl implementation with _MSC_VER less than 1600 doesn't have
-// this hash struct. STLport already defines this.
-template <typename T>
-struct hash {
-  size_t operator()(const T& t) const;
-};
-#endif  // defined(_MSC_VER)
-
-#endif  // !defined(_STLP_LONG_LONG) && !(defined(_MSC_VER) && _MSC_VER >= 1600)
-
-template<> struct hash<bool> {
-  size_t operator()(bool x) const { return static_cast<size_t>(x); }
-};
-
-
-}  // namespace __gnu_cxx
-
-
 
 // ----------------------------------------------------------------------
 // Fingerprint()
@@ -214,9 +182,7 @@ inline uint64 FingerprintCat(uint64 fp1, uint64 fp2) {
   return Hash64NumWithSeed(fp1, fp2);
 }
 
-#include <ext/hash_set>
-namespace __gnu_cxx {
-
+namespace std {
 
 // This intended to be a "good" hash function.  It may change from time to time.
 template<> struct hash<uint128> {
@@ -235,97 +201,25 @@ template<> struct hash<uint128> {
       return c;
     }
   }
-  // Less than operator for MSVC use.
-  bool operator()(const uint128& a, const uint128& b) const {
-    return a < b;
-  }
-  static const size_t bucket_size = 4;  // These are required by MSVC
-  static const size_t min_buckets = 8;  // 4 and 8 are defaults.
-};
-
-// Avoid collision with definition in port_hash.h (via port.h).
-#ifndef HAVE_DEFINED_HASH_FOR_POINTERS
-#define HAVE_DEFINED_HASH_FOR_POINTERS
-// Hash pointers as if they were int's, but bring more entropy to
-// the lower bits.
-template<class T> struct hash<T*> {
-  size_t operator()(T *x) const {
-    size_t k = reinterpret_cast<size_t>(x);
-    return k + (k >> 6);
-  }
-};
-#endif  // HAVE_DEFINED_HASH_FOR_POINTERS
-
-#if defined(__GNUC__)
-// Use our nice hash function for strings
-template<class _CharT, class _Traits, class _Alloc>
-struct hash<std::basic_string<_CharT, _Traits, _Alloc> > {
-  size_t operator()(const std::basic_string<_CharT, _Traits, _Alloc>& k) const {
-    return HashTo32(k.data(), static_cast<uint32>(k.length()));
-  }
-};
-
-// they don't define a hash for const string at all
-template<> struct hash<const std::string> {
-  size_t operator()(const std::string& k) const {
-    return HashTo32(k.data(), static_cast<uint32>(k.length()));
-  }
-};
-#endif  // defined(__GNUC__)
-
-// MSVC's STL requires an ever-so slightly different decl
-#if defined(STL_MSVC)
-template<> struct hash<char const*> {
-  size_t operator()(char const* const k) const {
-    return HashTo32(k, strlen(k));
-  }
-  // Less than operator:
-  bool operator()(char const* const a, char const* const b) const {
-    return strcmp(a, b) < 0;
-  }
-  static const size_t bucket_size = 4;  // These are required by MSVC
-  static const size_t min_buckets = 8;  // 4 and 8 are defaults.
-};
-
-// MSVC 10.0 and above have already defined this.
-#if !defined(_MSC_VER) || _MSC_VER < 1600
-template<> struct hash<std::string> {
-  size_t operator()(const std::string& k) const {
-    return HashTo32(k.data(), k.length());
-  }
-  // Less than operator:
-  bool operator()(const std::string& a, const std::string& b) const {
-    return a < b;
-  }
-  static const size_t bucket_size = 4;  // These are required by MSVC
   static const size_t min_buckets = 8;  // 4 and 8 are defaults.
 };
-#endif  // !defined(_MSC_VER) || _MSC_VER < 1600
-
-#endif  // defined(STL_MSVC)
 
 // Hasher for STL pairs. Requires hashers for both members to be defined
 template<class First, class Second>
 struct hash<pair<First, Second> > {
   size_t operator()(const pair<First, Second>& p) const {
-    size_t h1 = hash<First>()(p.first);
-    size_t h2 = hash<Second>()(p.second);
+    size_t h1 = std::hash<First>()(p.first);
+    size_t h2 = std::hash<Second>()(p.second);
     // The decision below is at compile time
     return (sizeof(h1) <= sizeof(uint32)) ?
             Hash32NumWithSeed(h1, h2)
             : Hash64NumWithSeed(h1, h2);
   }
-  // Less than operator for MSVC.
-  bool operator()(const pair<First, Second>& a,
-                  const pair<First, Second>& b) const {
-    return a < b;
-  }
-  static const size_t bucket_size = 4;  // These are required by MSVC
   static const size_t min_buckets = 8;  // 4 and 8 are defaults.
 };
 
 
-}  // namespace __gnu_cxx
+}  // namespace std
 
 
 // If you want an excellent string hash function, and you don't mind if it
@@ -397,23 +291,4 @@ struct GoodFastHash<const std::basic_string<_CharT, _Traits, _Alloc> > {
   static const size_t min_buckets = 8;  // 4 and 8 are defaults.
 };
 
-// Extern template declarations.
-//
-// gcc only for now.  msvc and others: this technique is likely to work with
-// your compiler too.  changelists welcome.
-//
-// This technique is limited to template specializations whose hash key
-// functions are declared in this file.
-
-#if defined(__GNUC__)
-#include <ext/hash_set>
-namespace __gnu_cxx {
-
-extern template class hash_set<std::string>;
-extern template class hash_map<std::string, std::string>;
-
-}  // namespace __gnu_cxx
-
-#endif  // defined(__GNUC__)
-
 #endif  // UTIL_HASH_HASH_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/aaec43b9/be/src/gutil/strings/join.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/join.h b/be/src/gutil/strings/join.h
index bd34c39..152629d 100644
--- a/be/src/gutil/strings/join.h
+++ b/be/src/gutil/strings/join.h
@@ -9,12 +9,6 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <ext/hash_map>
-using __gnu_cxx::hash;
-using __gnu_cxx::hash_map;  // Not used in this file.
-#include <ext/hash_set>
-using __gnu_cxx::hash;
-using __gnu_cxx::hash_set;  // Not used in this file.
 #include <iterator>
 using std::back_insert_iterator;
 using std::iterator_traits;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/aaec43b9/be/src/gutil/strings/serialize.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/serialize.cc b/be/src/gutil/strings/serialize.cc
index a4e27c3..7088244 100644
--- a/be/src/gutil/strings/serialize.cc
+++ b/be/src/gutil/strings/serialize.cc
@@ -4,9 +4,6 @@
 
 #include <stddef.h>
 #include <stdlib.h>
-#include <ext/hash_map>
-using __gnu_cxx::hash;
-using __gnu_cxx::hash_map;
 #include <string>
 using std::string;
 #include <utility>
@@ -14,6 +11,8 @@ using std::make_pair;
 using std::pair;
 #include <vector>
 using std::vector;
+#include <unordered_map>
+using std::unordered_map;
 
 #include "gutil/casts.h"
 #include "gutil/integral_types.h"
@@ -221,7 +220,7 @@ int64 ReverseOrderedStringToInt64(const StringPiece& key) {
 //   and commas to separate entries.
 // --------------------------------------------------------------------------
 
-string DictionaryInt32Encode(const hash_map<string, int32>* dictionary) {
+string DictionaryInt32Encode(const unordered_map<string, int32>* dictionary) {
   vector<string> entries;
   for (const auto& entry : *dictionary) {
     entries.push_back(StringPrintf("%s:%d", entry.first.c_str(), entry.second));
@@ -232,7 +231,7 @@ string DictionaryInt32Encode(const hash_map<string, int32>* dictionary) {
   return result;
 }
 
-string DictionaryInt64Encode(const hash_map<string, int64>* dictionary) {
+string DictionaryInt64Encode(const unordered_map<string, int64>* dictionary) {
   vector<string> entries;
   for (const auto& entry : *dictionary) {
     entries.push_back(StringPrintf("%s:%" PRId64,
@@ -244,7 +243,7 @@ string DictionaryInt64Encode(const hash_map<string, int64>* dictionary) {
   return result;
 }
 
-string DictionaryDoubleEncode(const hash_map<string, double>* dictionary) {
+string DictionaryDoubleEncode(const unordered_map<string, double>* dictionary) {
   vector<string> entries;
   for (const auto& entry : *dictionary) {
     entries.push_back(StringPrintf("%s:%g", entry.first.c_str(), entry.second));
@@ -269,7 +268,7 @@ bool DictionaryParse(const string& encoded_str,
   return true;
 }
 
-bool DictionaryInt32Decode(hash_map<string, int32>* dictionary,
+bool DictionaryInt32Decode(unordered_map<string, int32>* dictionary,
                            const string& encoded_str) {
   vector<pair<string, string> > items;
   if (!DictionaryParse(encoded_str, &items))
@@ -288,7 +287,7 @@ bool DictionaryInt32Decode(hash_map<string, int32>* dictionary,
   return true;
 }
 
-bool DictionaryInt64Decode(hash_map<string, int64>* dictionary,
+bool DictionaryInt64Decode(unordered_map<string, int64>* dictionary,
                            const string& encoded_str) {
   vector<pair<string, string> > items;
   if (!DictionaryParse(encoded_str, &items))
@@ -308,7 +307,7 @@ bool DictionaryInt64Decode(hash_map<string, int64>* dictionary,
 }
 
 
-bool DictionaryDoubleDecode(hash_map<string, double>* dictionary,
+bool DictionaryDoubleDecode(unordered_map<string, double>* dictionary,
                             const string& encoded_str) {
   vector<pair<string, string> > items;
   if (!DictionaryParse(encoded_str, &items))

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/aaec43b9/be/src/gutil/strings/serialize.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/serialize.h b/be/src/gutil/strings/serialize.h
index d69382a..1aad2eb 100644
--- a/be/src/gutil/strings/serialize.h
+++ b/be/src/gutil/strings/serialize.h
@@ -8,9 +8,6 @@
 #define STRINGS_SERIALIZE_H_
 
 #include <string.h>
-#include <ext/hash_map>
-using __gnu_cxx::hash;
-using __gnu_cxx::hash_map;
 #include <string>
 using std::string;
 #include <utility>
@@ -18,6 +15,8 @@ using std::make_pair;
 using std::pair;
 #include <vector>
 using std::vector;
+#include <unordered_map>
+using std::unordered_map;
 
 #include <common/logging.h>
 
@@ -328,15 +327,15 @@ bool DictionaryParse(const string& encoded_str,
 //   Note: these routines are not meant for use with very large dictionaries.
 //   They are written for convenience and not efficiency.
 // --------------------------------------------------------------------------
-string DictionaryInt32Encode(const hash_map<string, int32>* dictionary);
-string DictionaryInt64Encode(const hash_map<string, int64>* dictionary);
-string DictionaryDoubleEncode(const hash_map<string, double>* dictionary);
+string DictionaryInt32Encode(const unordered_map<string, int32>* dictionary);
+string DictionaryInt64Encode(const unordered_map<string, int64>* dictionary);
+string DictionaryDoubleEncode(const unordered_map<string, double>* dictionary);
 
-bool DictionaryInt32Decode(hash_map<string, int32>* dictionary,
+bool DictionaryInt32Decode(unordered_map<string, int32>* dictionary,
                            const string& encoded_str);
-bool DictionaryInt64Decode(hash_map<string, int64>* dictionary,
+bool DictionaryInt64Decode(unordered_map<string, int64>* dictionary,
                            const string& encoded_str);
-bool DictionaryDoubleDecode(hash_map<string, double>* dictionary,
+bool DictionaryDoubleDecode(unordered_map<string, double>* dictionary,
                             const string& encoded_str);
 
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/aaec43b9/be/src/gutil/strings/split.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/split.cc b/be/src/gutil/strings/split.cc
index 34a9d99..e888856 100644
--- a/be/src/gutil/strings/split.cc
+++ b/be/src/gutil/strings/split.cc
@@ -118,7 +118,7 @@ namespace {
 // the following overloads:
 // - vector<string>           - for better performance
 // - map<string, string>      - to change append semantics
-// - hash_map<string, string> - to change append semantics
+// - unordered_map<string, string> - to change append semantics
 template <typename Container, typename Splitter>
 void AppendToImpl(Container* container, Splitter splitter) {
   Container c = splitter;  // Calls implicit conversion operator.
@@ -138,7 +138,7 @@ void AppendToImpl(vector<string>* container, Splitter splitter) {
   }
 }
 
-// Here we define two AppendToImpl() overloads for map<> and hash_map<>. Both of
+// Here we define two AppendToImpl() overloads for map<> and unordered_map<>. Both of
 // these overloads call through to this AppendToMap() function. This is needed
 // because inserting a duplicate key into a map does NOT overwrite the previous
 // value, which was not the behavior of the split1 Split*() functions. Consider
@@ -150,7 +150,7 @@ void AppendToImpl(vector<string>* container, Splitter splitter) {
 //   ASSERT_EQ(m["a"], "1");  // <-- "a" has value "1" not "2".
 //
 // Due to this behavior of map::insert, we can't rely on a normal std::inserter
-// for a maps. Instead, maps and hash_maps need to be special cased to implement
+// for a maps. Instead, maps and unordered_maps need to be special cased to implement
 // the desired append semantic of inserting an existing value overwrites the
 // previous value.
 //
@@ -172,7 +172,7 @@ void AppendToImpl(map<string, string>* map_container, Splitter splitter) {
 }
 
 template <typename Splitter>
-void AppendToImpl(hash_map<string, string>* map_container, Splitter splitter) {
+void AppendToImpl(unordered_map<string, string>* map_container, Splitter splitter) {
   AppendToMap(map_container, splitter);
 }
 
@@ -420,7 +420,7 @@ void SplitStringUsing(const string& full,
 }
 
 void SplitStringToHashsetUsing(const string& full, const char* delim,
-                               hash_set<string>* result) {
+                               unordered_set<string>* result) {
   AppendTo(result, strings::Split(full, AnyOf(delim), strings::SkipEmpty()));
 }
 
@@ -435,7 +435,7 @@ void SplitStringToMapUsing(const string& full, const char* delim,
 }
 
 void SplitStringToHashmapUsing(const string& full, const char* delim,
-                               hash_map<string, string>* result) {
+                               unordered_map<string, string>* result) {
   AppendTo(result, strings::Split(full, AnyOf(delim), strings::SkipEmpty()));
 }
 
@@ -588,8 +588,8 @@ void SplitStringWithEscapingToSet(const string &full,
 
 void SplitStringWithEscapingToHashset(const string &full,
                                       const strings::CharSet& delimiters,
-                                      hash_set<string> *result) {
-  std::insert_iterator< hash_set<string> > it(*result, result->end());
+                                      unordered_set<string> *result) {
+  std::insert_iterator< unordered_set<string> > it(*result, result->end());
   SplitStringWithEscapingToIterator(full, delimiters, false, &it);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/aaec43b9/be/src/gutil/strings/split.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/split.h b/be/src/gutil/strings/split.h
index e2f74a7..964e3fc 100644
--- a/be/src/gutil/strings/split.h
+++ b/be/src/gutil/strings/split.h
@@ -28,12 +28,6 @@ using std::min;
 using std::reverse;
 using std::sort;
 using std::swap;
-#include <ext/hash_map>
-using __gnu_cxx::hash;
-using __gnu_cxx::hash_map;
-#include <ext/hash_set>
-using __gnu_cxx::hash;
-using __gnu_cxx::hash_set;
 #include <iterator>
 using std::back_insert_iterator;
 using std::iterator_traits;
@@ -50,6 +44,10 @@ using std::make_pair;
 using std::pair;
 #include <vector>
 using std::vector;
+#include <unordered_map>
+using std::unordered_map;
+#include <unordered_set>
+using std::unordered_set;
 
 #include <common/logging.h>
 
@@ -131,8 +129,8 @@ namespace strings {
 // string, StringPiece, Cord, or any object that has a constructor (explicit or
 // not) that takes a single StringPiece argument. This pattern works for all
 // standard STL containers including vector, list, deque, set, multiset, map,
-// and multimap, non-standard containers including hash_set and hash_map, and
-// even std::pair which is not actually a container.
+// multimap, unordered_set and unordered_map, and even std::pair which is not
+// actually a container.
 //
 // Splitting to std::pair is an interesting case because it can hold only two
 // elements and is not a collection type. When splitting to an std::pair the
@@ -679,7 +677,7 @@ void SplitStringPieceToVector(const StringPiece& full,
 void SplitStringUsing(const string& full, const char* delimiters,
                       vector<string>* result);
 void SplitStringToHashsetUsing(const string& full, const char* delimiters,
-                               hash_set<string>* result);
+                               unordered_set<string>* result);
 void SplitStringToSetUsing(const string& full, const char* delimiters,
                            set<string>* result);
 // The even-positioned (0-based) components become the keys for the
@@ -690,7 +688,7 @@ void SplitStringToSetUsing(const string& full, const char* delimiters,
 void SplitStringToMapUsing(const string& full, const char* delim,
                            map<string, string>* result);
 void SplitStringToHashmapUsing(const string& full, const char* delim,
-                               hash_map<string, string>* result);
+                               unordered_map<string, string>* result);
 
 // ----------------------------------------------------------------------
 // SplitStringAllowEmpty()
@@ -744,7 +742,7 @@ void SplitStringWithEscapingToSet(const string& full,
                                   set<string>* result);
 void SplitStringWithEscapingToHashset(const string& full,
                                       const strings::CharSet& delimiters,
-                                      hash_set<string>* result);
+                                      unordered_set<string>* result);
 
 // ----------------------------------------------------------------------
 // SplitStringIntoNPiecesAllowEmpty()