Skip to content

Commit 77f28d6

Browse files
Abseil Teamrongjiecomputer
authored andcommitted
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 abseil#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 abseil#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
1 parent 0f9e683 commit 77f28d6

21 files changed

+274
-51
lines changed

absl/base/internal/sysinfo.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ static int GetNumCPUs() {
7272
#if defined(_WIN32)
7373

7474
static double GetNominalCPUFrequency() {
75-
// UWP apps don't have access to the registry and currently don't provide an
76-
// API informing about CPU nominal frequency.
7775
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
7876
!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
77+
// UWP apps don't have access to the registry and currently don't provide an
78+
// API informing about CPU nominal frequency.
7979
return 1.0;
8080
#else
8181
#pragma comment(lib, "advapi32.lib") // For Reg* functions.
@@ -97,7 +97,7 @@ static double GetNominalCPUFrequency() {
9797
}
9898
}
9999
return 1.0;
100-
#endif // WINAPI_PARTITION_APP && !WINAPI_PARTITION_DESKTOP
100+
#endif // WINAPI_PARTITION_APP && !WINAPI_PARTITION_DESKTOP
101101
}
102102

103103
#elif defined(CTL_HW) && defined(HW_CPU_FREQ)

absl/container/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ cc_library(
390390
"//absl/base:config",
391391
"//absl/hash",
392392
"//absl/strings",
393+
"//absl/strings:cord",
393394
],
394395
)
395396

@@ -402,7 +403,10 @@ cc_test(
402403
deps = [
403404
":hash_function_defaults",
404405
"//absl/hash",
406+
"//absl/random",
405407
"//absl/strings",
408+
"//absl/strings:cord",
409+
"//absl/strings:cord_test_helpers",
406410
"@com_google_googletest//:gtest_main",
407411
],
408412
)
@@ -828,6 +832,7 @@ cc_library(
828832
"//absl/memory",
829833
"//absl/meta:type_traits",
830834
"//absl/strings",
835+
"//absl/strings:cord",
831836
"//absl/types:compare",
832837
"//absl/utility",
833838
],
@@ -844,6 +849,7 @@ cc_library(
844849
":btree",
845850
":flat_hash_set",
846851
"//absl/strings",
852+
"//absl/strings:cord",
847853
"//absl/time",
848854
],
849855
)
@@ -895,6 +901,7 @@ cc_binary(
895901
"//absl/flags:flag",
896902
"//absl/hash",
897903
"//absl/memory",
904+
"//absl/strings:cord",
898905
"//absl/strings:str_format",
899906
"//absl/time",
900907
"@com_github_google_benchmark//:benchmark_main",

absl/container/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ absl_cc_library(
4040
absl::compare
4141
absl::compressed_tuple
4242
absl::container_memory
43+
absl::cord
4344
absl::core_headers
4445
absl::layout
4546
absl::memory
@@ -60,6 +61,7 @@ absl_cc_library(
6061
${ABSL_DEFAULT_LINKOPTS}
6162
DEPS
6263
absl::btree
64+
absl::cord
6365
absl::flat_hash_set
6466
absl::strings
6567
absl::time
@@ -443,6 +445,7 @@ absl_cc_library(
443445
${ABSL_DEFAULT_COPTS}
444446
DEPS
445447
absl::config
448+
absl::cord
446449
absl::hash
447450
absl::strings
448451
PUBLIC
@@ -456,8 +459,11 @@ absl_cc_test(
456459
COPTS
457460
${ABSL_TEST_COPTS}
458461
DEPS
462+
absl::cord
463+
absl::cord_test_helpers
459464
absl::hash_function_defaults
460465
absl::hash
466+
absl::random_random
461467
absl::strings
462468
gmock_main
463469
)

absl/container/btree_benchmark.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "absl/flags/flag.h"
3737
#include "absl/hash/hash.h"
3838
#include "absl/memory/memory.h"
39+
#include "absl/strings/cord.h"
3940
#include "absl/strings/str_format.h"
4041
#include "absl/time/time.h"
4142
#include "benchmark/benchmark.h"
@@ -438,6 +439,7 @@ using StdString = std::string;
438439
STL_ORDERED_TYPES(int32_t);
439440
STL_ORDERED_TYPES(int64_t);
440441
STL_ORDERED_TYPES(StdString);
442+
STL_ORDERED_TYPES(Cord);
441443
STL_ORDERED_TYPES(Time);
442444

443445
#define STL_UNORDERED_TYPES(value) \
@@ -458,6 +460,8 @@ STL_ORDERED_TYPES(Time);
458460
using stl_unordered_multimap_##value = \
459461
std::unordered_multimap<value, intptr_t, hash>
460462

463+
STL_UNORDERED_TYPES_CUSTOM_HASH(Cord, absl::Hash<absl::Cord>);
464+
461465
STL_UNORDERED_TYPES(int32_t);
462466
STL_UNORDERED_TYPES(int64_t);
463467
STL_UNORDERED_TYPES(StdString);
@@ -478,6 +482,7 @@ STL_UNORDERED_TYPES_CUSTOM_HASH(Time, absl::Hash<absl::Time>);
478482
BTREE_TYPES(int32_t);
479483
BTREE_TYPES(int64_t);
480484
BTREE_TYPES(StdString);
485+
BTREE_TYPES(Cord);
481486
BTREE_TYPES(Time);
482487

483488
#define MY_BENCHMARK4(type, func) \
@@ -526,6 +531,7 @@ BTREE_TYPES(Time);
526531
MY_BENCHMARK(int32_t);
527532
MY_BENCHMARK(int64_t);
528533
MY_BENCHMARK(StdString);
534+
MY_BENCHMARK(Cord);
529535
MY_BENCHMARK(Time);
530536

531537
// Define a type whose size and cost of moving are independently customizable.

absl/container/btree_test.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,10 +812,12 @@ void MapTest() {
812812
TEST(Btree, set_int32) { SetTest<int32_t>(); }
813813
TEST(Btree, set_int64) { SetTest<int64_t>(); }
814814
TEST(Btree, set_string) { SetTest<std::string>(); }
815+
TEST(Btree, set_cord) { SetTest<absl::Cord>(); }
815816
TEST(Btree, set_pair) { SetTest<std::pair<int, int>>(); }
816817
TEST(Btree, map_int32) { MapTest<int32_t>(); }
817818
TEST(Btree, map_int64) { MapTest<int64_t>(); }
818819
TEST(Btree, map_string) { MapTest<std::string>(); }
820+
TEST(Btree, map_cord) { MapTest<absl::Cord>(); }
819821
TEST(Btree, map_pair) { MapTest<std::pair<int, int>>(); }
820822

821823
template <typename K, int N = 256>
@@ -847,10 +849,12 @@ void MultiMapTest() {
847849
TEST(Btree, multiset_int32) { MultiSetTest<int32_t>(); }
848850
TEST(Btree, multiset_int64) { MultiSetTest<int64_t>(); }
849851
TEST(Btree, multiset_string) { MultiSetTest<std::string>(); }
852+
TEST(Btree, multiset_cord) { MultiSetTest<absl::Cord>(); }
850853
TEST(Btree, multiset_pair) { MultiSetTest<std::pair<int, int>>(); }
851854
TEST(Btree, multimap_int32) { MultiMapTest<int32_t>(); }
852855
TEST(Btree, multimap_int64) { MultiMapTest<int64_t>(); }
853856
TEST(Btree, multimap_string) { MultiMapTest<std::string>(); }
857+
TEST(Btree, multimap_cord) { MultiMapTest<absl::Cord>(); }
854858
TEST(Btree, multimap_pair) { MultiMapTest<std::pair<int, int>>(); }
855859

856860
struct CompareIntToString {
@@ -1268,6 +1272,8 @@ TEST(Btree, KeyCompareToAdapter) {
12681272
AssertKeyCompareToAdapted<std::less<absl::string_view>, absl::string_view>();
12691273
AssertKeyCompareToAdapted<std::greater<absl::string_view>,
12701274
absl::string_view>();
1275+
AssertKeyCompareToAdapted<std::less<absl::Cord>, absl::Cord>();
1276+
AssertKeyCompareToAdapted<std::greater<absl::Cord>, absl::Cord>();
12711277
AssertKeyCompareToNotAdapted<std::less<int>, int>();
12721278
AssertKeyCompareToNotAdapted<std::greater<int>, int>();
12731279
}

absl/container/btree_test.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "absl/container/btree_map.h"
2626
#include "absl/container/btree_set.h"
2727
#include "absl/container/flat_hash_set.h"
28+
#include "absl/strings/cord.h"
2829
#include "absl/time/time.h"
2930

3031
namespace absl {
@@ -100,6 +101,16 @@ struct Generator<std::string> {
100101
}
101102
};
102103

104+
template <>
105+
struct Generator<Cord> {
106+
int maxval;
107+
explicit Generator(int m) : maxval(m) {}
108+
Cord operator()(int i) const {
109+
char buf[16];
110+
return Cord(GenerateDigits(buf, i, maxval));
111+
}
112+
};
113+
103114
template <typename T, typename U>
104115
struct Generator<std::pair<T, U> > {
105116
Generator<typename remove_pair_const<T>::type> tgen;

absl/container/internal/btree.h

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "absl/container/internal/layout.h"
6666
#include "absl/memory/memory.h"
6767
#include "absl/meta/type_traits.h"
68+
#include "absl/strings/cord.h"
6869
#include "absl/strings/string_view.h"
6970
#include "absl/types/compare.h"
7071
#include "absl/utility/utility.h"
@@ -93,6 +94,19 @@ struct StringBtreeDefaultLess {
9394
absl::string_view rhs) const {
9495
return compare_internal::compare_result_as_ordering(lhs.compare(rhs));
9596
}
97+
StringBtreeDefaultLess(std::less<absl::Cord>) {} // NOLINT
98+
absl::weak_ordering operator()(const absl::Cord &lhs,
99+
const absl::Cord &rhs) const {
100+
return compare_internal::compare_result_as_ordering(lhs.Compare(rhs));
101+
}
102+
absl::weak_ordering operator()(const absl::Cord &lhs,
103+
absl::string_view rhs) const {
104+
return compare_internal::compare_result_as_ordering(lhs.Compare(rhs));
105+
}
106+
absl::weak_ordering operator()(absl::string_view lhs,
107+
const absl::Cord &rhs) const {
108+
return compare_internal::compare_result_as_ordering(-rhs.Compare(lhs));
109+
}
96110
};
97111

98112
struct StringBtreeDefaultGreater {
@@ -107,13 +121,27 @@ struct StringBtreeDefaultGreater {
107121
absl::string_view rhs) const {
108122
return compare_internal::compare_result_as_ordering(rhs.compare(lhs));
109123
}
124+
StringBtreeDefaultGreater(std::greater<absl::Cord>) {} // NOLINT
125+
absl::weak_ordering operator()(const absl::Cord &lhs,
126+
const absl::Cord &rhs) const {
127+
return compare_internal::compare_result_as_ordering(rhs.Compare(lhs));
128+
}
129+
absl::weak_ordering operator()(const absl::Cord &lhs,
130+
absl::string_view rhs) const {
131+
return compare_internal::compare_result_as_ordering(-lhs.Compare(rhs));
132+
}
133+
absl::weak_ordering operator()(absl::string_view lhs,
134+
const absl::Cord &rhs) const {
135+
return compare_internal::compare_result_as_ordering(rhs.Compare(lhs));
136+
}
110137
};
111138

112139
// A helper class to convert a boolean comparison into a three-way "compare-to"
113140
// comparison that returns a negative value to indicate less-than, zero to
114141
// indicate equality and a positive value to indicate greater-than. This helper
115142
// class is specialized for less<std::string>, greater<std::string>,
116-
// less<string_view>, and greater<string_view>.
143+
// less<string_view>, greater<string_view>, less<absl::Cord>, and
144+
// greater<absl::Cord>.
117145
//
118146
// key_compare_to_adapter is provided so that btree users
119147
// automatically get the more efficient compare-to code when using common
@@ -145,6 +173,16 @@ struct key_compare_to_adapter<std::greater<absl::string_view>> {
145173
using type = StringBtreeDefaultGreater;
146174
};
147175

176+
template <>
177+
struct key_compare_to_adapter<std::less<absl::Cord>> {
178+
using type = StringBtreeDefaultLess;
179+
};
180+
181+
template <>
182+
struct key_compare_to_adapter<std::greater<absl::Cord>> {
183+
using type = StringBtreeDefaultGreater;
184+
};
185+
148186
template <typename Key, typename Compare, typename Alloc, int TargetNodeSize,
149187
bool Multi, typename SlotPolicy>
150188
struct common_params {

absl/container/internal/hash_function_defaults.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
#include "absl/base/config.h"
5555
#include "absl/hash/hash.h"
56+
#include "absl/strings/cord.h"
5657
#include "absl/strings/string_view.h"
5758

5859
namespace absl {
@@ -72,6 +73,9 @@ struct StringHash {
7273
size_t operator()(absl::string_view v) const {
7374
return absl::Hash<absl::string_view>{}(v);
7475
}
76+
size_t operator()(const absl::Cord& v) const {
77+
return absl::Hash<absl::Cord>{}(v);
78+
}
7579
};
7680

7781
// Supports heterogeneous lookup for string-like elements.
@@ -82,13 +86,24 @@ struct StringHashEq {
8286
bool operator()(absl::string_view lhs, absl::string_view rhs) const {
8387
return lhs == rhs;
8488
}
89+
bool operator()(const absl::Cord& lhs, const absl::Cord& rhs) const {
90+
return lhs == rhs;
91+
}
92+
bool operator()(const absl::Cord& lhs, absl::string_view rhs) const {
93+
return lhs == rhs;
94+
}
95+
bool operator()(absl::string_view lhs, const absl::Cord& rhs) const {
96+
return lhs == rhs;
97+
}
8598
};
8699
};
87100

88101
template <>
89102
struct HashEq<std::string> : StringHashEq {};
90103
template <>
91104
struct HashEq<absl::string_view> : StringHashEq {};
105+
template <>
106+
struct HashEq<absl::Cord> : StringHashEq {};
92107

93108
// Supports heterogeneous lookup for pointers and smart pointers.
94109
template <class T>

0 commit comments

Comments
 (0)