Write qHash functions for QDate, QTime and QDateTime.
These functions didn't exist - this patch implements them. Task-number: QTBUG-23079 Change-Id: I9eb6e238531d5cda878f5f2cdd27bab30aa60669 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
623bfe2093
commit
282d81e4e5
@ -4067,6 +4067,43 @@ QDebug operator<<(QDebug dbg, const QDateTime &date)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*! \fn uint qHash(const QDateTime &key, uint seed = 0)
|
||||||
|
\relates QHash
|
||||||
|
\since 5.0
|
||||||
|
|
||||||
|
Returns the hash value for the \a key, using \a seed to seed the calculation.
|
||||||
|
*/
|
||||||
|
uint qHash(const QDateTime &key, uint seed)
|
||||||
|
{
|
||||||
|
// Use to toMSecsSinceEpoch instead of individual qHash functions for
|
||||||
|
// QDate/QTime/spec/offset because QDateTime::operator== converts both arguments
|
||||||
|
// to the same timezone. If we don't, qHash would return different hashes for
|
||||||
|
// two QDateTimes that are equivalent once converted to the same timezone.
|
||||||
|
return qHash(key.toMSecsSinceEpoch(), seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \fn uint qHash(const QDate &key, uint seed = 0)
|
||||||
|
\relates QHash
|
||||||
|
\since 5.0
|
||||||
|
|
||||||
|
Returns the hash value for the \a key, using \a seed to seed the calculation.
|
||||||
|
*/
|
||||||
|
uint qHash(const QDate &key, uint seed)
|
||||||
|
{
|
||||||
|
return qHash(key.toJulianDay(), seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \fn uint qHash(const QTime &key, uint seed = 0)
|
||||||
|
\relates QHash
|
||||||
|
\since 5.0
|
||||||
|
|
||||||
|
Returns the hash value for the \a key, using \a seed to seed the calculation.
|
||||||
|
*/
|
||||||
|
uint qHash(const QTime &key, uint seed)
|
||||||
|
{
|
||||||
|
return QTime(0, 0, 0, 0).msecsTo(key) ^ seed;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef QT_BOOTSTRAPPED
|
#ifndef QT_BOOTSTRAPPED
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -288,6 +288,10 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QTime &);
|
|||||||
Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &);
|
Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Q_CORE_EXPORT uint qHash(const QDateTime &key, uint seed = 0);
|
||||||
|
Q_CORE_EXPORT uint qHash(const QDate &key, uint seed = 0);
|
||||||
|
Q_CORE_EXPORT uint qHash(const QTime &key, uint seed = 0);
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
QT_END_HEADER
|
QT_END_HEADER
|
||||||
|
@ -712,6 +712,8 @@ void tst_QDate::operator_eq_eq()
|
|||||||
bool notEqual = d1 != d2;
|
bool notEqual = d1 != d2;
|
||||||
QCOMPARE(notEqual, !expectEqual);
|
QCOMPARE(notEqual, !expectEqual);
|
||||||
|
|
||||||
|
if (equal)
|
||||||
|
QVERIFY(qHash(d1) == qHash(d2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QDate::operator_lt()
|
void tst_QDate::operator_lt()
|
||||||
|
@ -1212,7 +1212,10 @@ void tst_QDateTime::operator_eqeq()
|
|||||||
bool notEqual = dt1 != dt2;
|
bool notEqual = dt1 != dt2;
|
||||||
QCOMPARE(notEqual, !expectEqual);
|
QCOMPARE(notEqual, !expectEqual);
|
||||||
|
|
||||||
if (checkEuro) {
|
if (equal)
|
||||||
|
QVERIFY(qHash(dt1) == qHash(dt2));
|
||||||
|
|
||||||
|
if (checkEuro && europeanTimeZone) {
|
||||||
QVERIFY(dt1.toUTC() == dt2);
|
QVERIFY(dt1.toUTC() == dt2);
|
||||||
QVERIFY(dt1 == dt2.toLocalTime());
|
QVERIFY(dt1 == dt2.toLocalTime());
|
||||||
}
|
}
|
||||||
|
@ -370,6 +370,8 @@ void tst_QTime::operator_eq_eq()
|
|||||||
bool notEqual = t1 != t2;
|
bool notEqual = t1 != t2;
|
||||||
QCOMPARE(notEqual, !expectEqual);
|
QCOMPARE(notEqual, !expectEqual);
|
||||||
|
|
||||||
|
if (equal)
|
||||||
|
QVERIFY(qHash(t1) == qHash(t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QTime::operator_lt()
|
void tst_QTime::operator_lt()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user