Skip to content

Commit 623e821

Browse files
authored
Remove specialization of std::hash for Timestamp (#3797)
1 parent 7ac9dbc commit 623e821

File tree

4 files changed

+3
-37
lines changed

4 files changed

+3
-37
lines changed

Firestore/core/include/firebase/firestore/timestamp.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,4 @@ std::chrono::time_point<Clock, Duration> Timestamp::ToTimePoint() const {
236236

237237
} // namespace firebase
238238

239-
namespace std {
240-
/** Convenience-only specialization of `std::hash`. */
241-
template <>
242-
struct hash<firebase::Timestamp> {
243-
/**
244-
* Hashes the given `timestamp`.
245-
*
246-
* @note: specialization of `std::hash` is provided for convenience only. The
247-
* implementation is subject to change.
248-
*/
249-
size_t operator()(const firebase::Timestamp& timestamp) const;
250-
};
251-
} // namespace std
252-
253239
#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_TIMESTAMP_H_

Firestore/core/src/firebase/firestore/model/snapshot_version.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include <ostream>
2020

21+
#include "Firestore/core/src/firebase/firestore/util/hashing.h"
22+
2123
namespace firebase {
2224
namespace firestore {
2325
namespace model {
@@ -37,7 +39,7 @@ util::ComparisonResult SnapshotVersion::CompareTo(
3739
}
3840

3941
size_t SnapshotVersion::Hash() const {
40-
return std::hash<Timestamp>{}(timestamp_);
42+
return util::Hash(timestamp_.seconds(), timestamp_.nanoseconds());
4143
}
4244

4345
std::string SnapshotVersion::ToString() const {

Firestore/core/src/firebase/firestore/timestamp.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,3 @@ void Timestamp::ValidateBounds() const {
138138
}
139139

140140
} // namespace firebase
141-
142-
namespace std {
143-
size_t hash<firebase::Timestamp>::operator()(
144-
const firebase::Timestamp& timestamp) const {
145-
// Note: if sizeof(size_t) == 4, this discards high-order bits of seconds.
146-
return 37 * static_cast<size_t>(timestamp.seconds()) +
147-
static_cast<size_t>(timestamp.nanoseconds());
148-
}
149-
150-
} // namespace std

Firestore/core/test/firebase/firestore/timestamp_test.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,6 @@ TEST(Timestamp, Comparison) {
274274
EXPECT_NE(Timestamp(123, 123456789), Timestamp(123, 123456780));
275275
}
276276

277-
TEST(Timestamp, Hash) {
278-
const Timestamp foo1{123, 456000000};
279-
const Timestamp foo2 = foo1;
280-
const Timestamp foo3 =
281-
Timestamp::FromTimePoint(TimePoint{Sec(123) + Ms(456)});
282-
EXPECT_EQ(std::hash<Timestamp>()(foo1), std::hash<Timestamp>()(foo2));
283-
EXPECT_EQ(std::hash<Timestamp>()(foo2), std::hash<Timestamp>()(foo3));
284-
285-
const Timestamp bar{123, 456};
286-
EXPECT_NE(std::hash<Timestamp>()(foo1), std::hash<Timestamp>()(bar));
287-
}
288-
289277
TEST(Timestamp, InvalidArguments) {
290278
// Negative nanoseconds.
291279
ASSERT_ANY_THROW(Timestamp(0, -1));

0 commit comments

Comments
 (0)