Add qHash implementation for QPoint

[ChangeLog][QtCore][QPoint] Added qHash() implementation.

Change-Id: I65332e7aafab53af40a6e11457b9b457196d584c
Fixes: QTBUG-86457
Reviewed-by: Thorbjørn Lindeijer <bjorn@lindeijer.nl>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Mitch Curtis 2020-09-07 15:57:15 +02:00
parent 9815ebf24b
commit fb65b32d76
5 changed files with 18 additions and 18 deletions

View File

@ -53,19 +53,6 @@
#include "slippymap.h" #include "slippymap.h"
#include "qmath.h" #include "qmath.h"
#ifdef QT_NAMESPACE
QT_BEGIN_NAMESPACE
size_t qHash(const QT_NAMESPACE::QPoint& p)
#else
size_t qHash(const QPoint& p)
#endif
{
return p.x() * 17 ^ p.y();
}
#ifdef QT_NAMESPACE
QT_END_NAMESPACE
#endif
// tile size in pixels // tile size in pixels
const int tdim = 256; const int tdim = 256;

View File

@ -41,6 +41,7 @@
#include "qdatastream.h" #include "qdatastream.h"
#include <private/qdebug_p.h> #include <private/qdebug_p.h>
#include <QtCore/qhashfunctions.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -483,6 +484,19 @@ QDebug operator<<(QDebug dbg, const QPointF &p)
} }
#endif #endif
/*!
\fn size_t qHash(QPoint key, size_t seed = 0)
\relates QHash
\since 6.0
Returns the hash value for the \a key, using \a seed to seed the
calculation.
*/
size_t qHash(QPoint key, size_t seed) noexcept
{
return qHashMulti(seed, key.x(), key.y());
}
/*! /*!
\class QPointF \class QPointF
\inmodule QtCore \inmodule QtCore

View File

@ -214,6 +214,7 @@ constexpr inline const QPoint operator/(const QPoint &p, qreal c)
Q_CORE_EXPORT QDebug operator<<(QDebug, const QPoint &); Q_CORE_EXPORT QDebug operator<<(QDebug, const QPoint &);
#endif #endif
Q_CORE_EXPORT size_t qHash(QPoint key, size_t seed = 0) noexcept;

View File

@ -346,6 +346,9 @@ void tst_QPoint::operator_eq()
QCOMPARE(equal, expectEqual); QCOMPARE(equal, expectEqual);
bool notEqual = point1 != point2; bool notEqual = point1 != point2;
QCOMPARE(notEqual, !expectEqual); QCOMPARE(notEqual, !expectEqual);
if (equal)
QCOMPARE(qHash(point1), qHash(point2));
} }
#ifndef QT_NO_DATASTREAM #ifndef QT_NO_DATASTREAM

View File

@ -3256,11 +3256,6 @@ void tst_QPainter::imageScaling_task206785()
#define FOR_EACH_NEIGHBOR_8 for (int dx = -1; dx <= 1; ++dx) for (int dy = -1; dy <= 1; ++dy) if (dx != 0 || dy != 0) #define FOR_EACH_NEIGHBOR_8 for (int dx = -1; dx <= 1; ++dx) for (int dy = -1; dy <= 1; ++dy) if (dx != 0 || dy != 0)
#define FOR_EACH_NEIGHBOR_4 for (int dx = -1; dx <= 1; ++dx) for (int dy = -1; dy <= 1; ++dy) if ((dx == 0) != (dy == 0)) #define FOR_EACH_NEIGHBOR_4 for (int dx = -1; dx <= 1; ++dx) for (int dy = -1; dy <= 1; ++dy) if ((dx == 0) != (dy == 0))
size_t qHash(const QPoint &point)
{
return qHash(qMakePair(point.x(), point.y()));
}
bool verifyOutlineFillConsistency(const QImage &img, QRgb outside, QRgb inside, QRgb outline) bool verifyOutlineFillConsistency(const QImage &img, QRgb outside, QRgb inside, QRgb outline)
{ {
if (img.pixel(img.width() / 2, img.height() / 2) != inside) if (img.pixel(img.width() / 2, img.height() / 2) != inside)