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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user