Export of internal Abseil changes

--
2c5c118f0615ba90e48ee2f18eccc9f511740f6d by Samuel Benzaquen <sbenza@google.com>:

Rename internal macros to follow the convention in absl.

PiperOrigin-RevId: 299906738

--
92d84a707c7ebc4ec19bdd92d5765d1b6d218c1e by Derek Mauro <dmauro@google.com>:

Import GitHub #629: Skip the .exe suffix in the helpshort filter on Windows

PiperOrigin-RevId: 299892396

--
2a6910d4be6c67a8376628764121b528ff53504d by Abseil Team <absl-team@google.com>:

Use unsigned int128 intrinsic when available. It generates better branchless code.

PiperOrigin-RevId: 299848585

--
110c16cf0a739e1df5028fb6fbd03ef5dde1d278 by Derek Mauro <dmauro@google.com>:

Import GitHub #594: Avoid reading the registry for Windows UWP apps

PiperOrigin-RevId: 299821671

--
d8397d367e88163e5e8a47f379c716352dc91d03 by Greg Falcon <gfalcon@google.com>:

Add absl::Hash support for Cord.  The hash function is heterogeneous with other string types: a Cord and a string with the same byte sequence will hash to the same value.

SwissTable types know about Cord, and will allow heterogeneous lookup (e.g., you can pass a Cord to flat_hash_map<string, T>::find(), and vice versa.)

Add a missing dependency to the cmake Cord target.

PiperOrigin-RevId: 299443713
GitOrigin-RevId: 2c5c118f0615ba90e48ee2f18eccc9f511740f6d
Change-Id: I7b087c7984b0cb52c4b337d49266c467b98ebdf9
This commit is contained in:
Abseil Team 2020-03-09 12:34:31 -07:00 committed by Derek Mauro
parent 238b9a59c8
commit d936052d32
21 changed files with 274 additions and 51 deletions

View file

@ -42,6 +42,7 @@
#include "absl/hash/internal/spy_hash_state.h"
#include "absl/meta/type_traits.h"
#include "absl/numeric/int128.h"
#include "absl/strings/cord_test_helpers.h"
namespace {
@ -269,6 +270,22 @@ struct WrapInTuple {
}
};
absl::Cord FlatCord(absl::string_view sv) {
absl::Cord c(sv);
c.Flatten();
return c;
}
absl::Cord FragmentedCord(absl::string_view sv) {
if (sv.size() < 2) {
return absl::Cord(sv);
}
size_t halfway = sv.size() / 2;
std::vector<absl::string_view> parts = {sv.substr(0, halfway),
sv.substr(halfway)};
return absl::MakeFragmentedCord(parts);
}
TEST(HashValueTest, Strings) {
EXPECT_TRUE((is_hashable<std::string>::value));
@ -277,23 +294,27 @@ TEST(HashValueTest, Strings) {
const std::string large = std::string(2048, 'x'); // multiple of chunk size
const std::string huge = std::string(5000, 'a'); // not a multiple
EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(std::make_tuple(
std::string(), absl::string_view(),
std::string(""), absl::string_view(""),
std::string(small), absl::string_view(small),
std::string(dup), absl::string_view(dup),
std::string(large), absl::string_view(large),
std::string(huge), absl::string_view(huge))));
EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(std::make_tuple( //
std::string(), absl::string_view(), absl::Cord(), //
std::string(""), absl::string_view(""), absl::Cord(""), //
std::string(small), absl::string_view(small), absl::Cord(small), //
std::string(dup), absl::string_view(dup), absl::Cord(dup), //
std::string(large), absl::string_view(large), absl::Cord(large), //
std::string(huge), absl::string_view(huge), FlatCord(huge), //
FragmentedCord(huge))));
// Also check that nested types maintain the same hash.
const WrapInTuple t{};
EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(std::make_tuple(
t(std::string()), t(absl::string_view()),
t(std::string("")), t(absl::string_view("")),
t(std::string(small)), t(absl::string_view(small)),
t(std::string(dup)), t(absl::string_view(dup)),
t(std::string(large)), t(absl::string_view(large)),
t(std::string(huge)), t(absl::string_view(huge)))));
EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(std::make_tuple( //
t(std::string()), t(absl::string_view()), t(absl::Cord()), //
t(std::string("")), t(absl::string_view("")), t(absl::Cord("")), //
t(std::string(small)), t(absl::string_view(small)), //
t(absl::Cord(small)), //
t(std::string(dup)), t(absl::string_view(dup)), t(absl::Cord(dup)), //
t(std::string(large)), t(absl::string_view(large)), //
t(absl::Cord(large)), //
t(std::string(huge)), t(absl::string_view(huge)), //
t(FlatCord(huge)), t(FragmentedCord(huge)))));
// Make sure that hashing a `const char*` does not use its std::string-value.
EXPECT_NE(SpyHash(static_cast<const char*>("ABC")),