diff options
author | Abseil Team <absl-team@google.com> | 2020-10-14 10:45:02 -0700 |
---|---|---|
committer | Derek Mauro <dmauro@google.com> | 2020-10-14 14:52:17 -0400 |
commit | 60d00a5822bb98f18e40b294554f91ca14fb793a (patch) | |
tree | f9b37ed0aa0c79d5e0fb9b5df97bf7303b6951b0 /absl/container | |
parent | f3f785ab59478dd0312bf1b5df65d380650bf0dc (diff) |
Export of internal Abseil changes
--
4ee535c37f92cd45b8c9aa009e5c833265b3a0bb by Samuel Benzaquen <sbenza@google.com>:
Test and fix `insert(hint, node)`
PiperOrigin-RevId: 337122891
--
7b760ced555756fecbad702fedb697424dd65167 by Abseil Team <absl-team@google.com>:
Changed the minimum version of iOS and OSX for Abseil Podspec.
PiperOrigin-RevId: 336926756
GitOrigin-RevId: 4ee535c37f92cd45b8c9aa009e5c833265b3a0bb
Change-Id: I94e70f3342570c83b9965ca458a3f02eaa3efc0d
Diffstat (limited to 'absl/container')
-rw-r--r-- | absl/container/internal/raw_hash_set.h | 4 | ||||
-rw-r--r-- | absl/container/internal/raw_hash_set_test.cc | 20 |
2 files changed, 23 insertions, 1 deletions
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index ec13a2f7..67364b75 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h @@ -1065,7 +1065,9 @@ class raw_hash_set { } iterator insert(const_iterator, node_type&& node) { - return insert(std::move(node)).first; + auto res = insert(std::move(node)); + node = std::move(res.node); + return res.position; } // This overload kicks in if we can deduce the key from args. This enables us diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 6210eb64..33d2773d 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -1711,6 +1711,26 @@ TEST(Nodes, ExtractInsert) { EXPECT_FALSE(node); } +TEST(Nodes, HintInsert) { + IntTable t = {1, 2, 3}; + auto node = t.extract(1); + EXPECT_THAT(t, UnorderedElementsAre(2, 3)); + auto it = t.insert(t.begin(), std::move(node)); + EXPECT_THAT(t, UnorderedElementsAre(1, 2, 3)); + EXPECT_EQ(*it, 1); + EXPECT_FALSE(node); + + node = t.extract(2); + EXPECT_THAT(t, UnorderedElementsAre(1, 3)); + // reinsert 2 to make the next insert fail. + t.insert(2); + EXPECT_THAT(t, UnorderedElementsAre(1, 2, 3)); + it = t.insert(t.begin(), std::move(node)); + EXPECT_EQ(*it, 2); + // The node was not emptied by the insert call. + EXPECT_TRUE(node); +} + IntTable MakeSimpleTable(size_t size) { IntTable t; while (t.size() < size) t.insert(t.size()); |