added qhash functions for timerange and rational

So these keys can be used in QHash containers, they need functions for how to
create those hashes.
This commit is contained in:
itsmattkc
2019-11-15 13:55:05 +09:00
parent 336b3a8e05
commit 16f80386e8
4 changed files with 17 additions and 9 deletions
+5
View File
@@ -421,3 +421,8 @@ QDebug operator<<(QDebug debug, const rational &r)
debug.nospace() << r.numerator() << "/" << r.denominator();
return debug.space();
}
uint qHash(const rational &r, uint seed)
{
return qHash(r.toDouble(), seed);
}
+2
View File
@@ -126,4 +126,6 @@ QDebug operator<<(QDebug debug, const rational& r);
Q_DECLARE_METATYPE(rational)
uint qHash(const rational& r, uint seed);
#endif // RATIONAL_H
+7 -7
View File
@@ -41,14 +41,9 @@ void TimeRange::set_range(const rational &in, const rational &out)
normalize();
}
bool TimeRange::operator<(const TimeRange &r) const
bool TimeRange::operator==(const TimeRange &r) const
{
return (in() + out()) < (r.in() + r.out());
}
bool TimeRange::operator>(const TimeRange &r) const
{
return (in() + out()) > (r.in() + r.out());
return in() == r.in() && out() == r.out();
}
void TimeRange::normalize()
@@ -63,3 +58,8 @@ void TimeRange::normalize()
// Calculate length
length_ = out_ - in_;
}
uint qHash(const TimeRange &r, uint seed)
{
return qHash(r.in(), seed) ^ qHash(r.out(), seed);
}
+3 -2
View File
@@ -16,8 +16,7 @@ public:
void set_out(const rational& out);
void set_range(const rational& in, const rational& out);
bool operator<(const TimeRange &r) const;
bool operator>(const TimeRange &r) const;
bool operator==(const TimeRange& r) const;
private:
void normalize();
@@ -27,4 +26,6 @@ private:
rational length_;
};
uint qHash(const TimeRange& r, uint seed);
#endif // TIMERANGE_H