Keyframe::Contains(): Use binary search instead of linear search

This commit is contained in:
Daniel Jour
2019-11-30 11:32:52 +01:00
parent a67fb9555c
commit 54e8e37d2d

View File

@@ -114,20 +114,9 @@ int64_t Keyframe::FindIndex(Point p) const {
// Determine if point already exists
bool Keyframe::Contains(Point p) const {
// loop through points, and find a matching coordinate
for (int64_t x = 0; x < Points.size(); x++) {
// Get each point
Point existing_point = Points[x];
// find a match
if (p.co.X == existing_point.co.X) {
// Remove the matching point, and break out of loop
return true;
}
}
// no matching point found
return false;
std::vector<Point>::const_iterator i =
std::lower_bound(begin(Points), end(Points), p.co.X, IsPointBeforeX);
return i != end(Points) && i->co.X == p.co.X;
}
// Get current point (or closest point) from the X coordinate (i.e. the frame number)