Skip to content

Commit 54e8e37

Browse files
committed
Keyframe::Contains(): Use binary search instead of linear search
1 parent a67fb95 commit 54e8e37

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/KeyFrame.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,9 @@ int64_t Keyframe::FindIndex(Point p) const {
114114

115115
// Determine if point already exists
116116
bool Keyframe::Contains(Point p) const {
117-
// loop through points, and find a matching coordinate
118-
for (int64_t x = 0; x < Points.size(); x++) {
119-
// Get each point
120-
Point existing_point = Points[x];
121-
122-
// find a match
123-
if (p.co.X == existing_point.co.X) {
124-
// Remove the matching point, and break out of loop
125-
return true;
126-
}
127-
}
128-
129-
// no matching point found
130-
return false;
117+
std::vector<Point>::const_iterator i =
118+
std::lower_bound(begin(Points), end(Points), p.co.X, IsPointBeforeX);
119+
return i != end(Points) && i->co.X == p.co.X;
131120
}
132121

133122
// Get current point (or closest point) from the X coordinate (i.e. the frame number)

0 commit comments

Comments
 (0)