Mercurial > hg > svcore
comparison base/EventSeries.cpp @ 1654:26aa42fd60e9 single-point
Add overspill to events-within search
author | Chris Cannam |
---|---|
date | Wed, 20 Mar 2019 11:12:54 +0000 |
parents | eaad70939848 |
children | 69ab62d378bf |
comparison
equal
deleted
inserted
replaced
1653:eaad70939848 | 1654:26aa42fd60e9 |
---|---|
271 return span; | 271 return span; |
272 } | 272 } |
273 | 273 |
274 EventVector | 274 EventVector |
275 EventSeries::getEventsWithin(sv_frame_t frame, | 275 EventSeries::getEventsWithin(sv_frame_t frame, |
276 sv_frame_t duration) const | 276 sv_frame_t duration, |
277 int overspill) const | |
277 { | 278 { |
278 EventVector span; | 279 EventVector span; |
279 | 280 |
280 const sv_frame_t start = frame; | 281 const sv_frame_t start = frame; |
281 const sv_frame_t end = frame + duration; | 282 const sv_frame_t end = frame + duration; |
282 | 283 |
283 // because we don't need to "look back" at events that started | 284 // because we don't need to "look back" at events that end within |
284 // earlier than the start of the given range, we can do this | 285 // but started without, we can do this entirely from m_events. |
285 // entirely from m_events | 286 // The core operation is very simple, it's just overspill that |
286 | 287 // complicates it. |
287 auto pitr = lower_bound(m_events.begin(), m_events.end(), | 288 |
288 Event(start)); | 289 Events::const_iterator reference = |
290 lower_bound(m_events.begin(), m_events.end(), Event(start)); | |
291 | |
292 Events::const_iterator first = reference; | |
293 for (int i = 0; i < overspill; ++i) { | |
294 if (first == m_events.begin()) break; | |
295 --first; | |
296 } | |
297 for (int i = 0; i < overspill; ++i) { | |
298 if (first == reference) break; | |
299 span.push_back(*first); | |
300 ++first; | |
301 } | |
302 | |
303 Events::const_iterator pitr = reference; | |
304 Events::const_iterator last = reference; | |
305 | |
289 while (pitr != m_events.end() && pitr->getFrame() < end) { | 306 while (pitr != m_events.end() && pitr->getFrame() < end) { |
290 if (!pitr->hasDuration()) { | 307 if (!pitr->hasDuration() || |
308 (pitr->getFrame() + pitr->getDuration() <= end)) { | |
291 span.push_back(*pitr); | 309 span.push_back(*pitr); |
292 } else if (pitr->getFrame() + pitr->getDuration() <= end) { | 310 last = pitr; |
293 span.push_back(*pitr); | 311 ++last; |
294 } | 312 } |
295 ++pitr; | 313 ++pitr; |
296 } | 314 } |
297 | 315 |
316 for (int i = 0; i < overspill; ++i) { | |
317 if (last == m_events.end()) break; | |
318 span.push_back(*last); | |
319 ++last; | |
320 } | |
321 | |
298 return span; | 322 return span; |
299 } | 323 } |
300 | 324 |
301 EventVector | 325 EventVector |
302 EventSeries::getEventsStartingWithin(sv_frame_t frame, | 326 EventSeries::getEventsStartingWithin(sv_frame_t frame, |