Mercurial > hg > svcore
comparison base/EventSeries.h @ 1626:895186c43fce single-point
Experiment with storing vectors of event ids in seam map for compactness
author | Chris Cannam |
---|---|
date | Mon, 11 Mar 2019 13:44:35 +0000 |
parents | 7dbb2a7b592e |
children | 1c21ddac220e |
comparison
equal
deleted
inserted
replaced
1625:7dbb2a7b592e | 1626:895186c43fce |
---|---|
57 void add(const Event &p) { | 57 void add(const Event &p) { |
58 | 58 |
59 ++m_events[p]; | 59 ++m_events[p]; |
60 ++m_count; | 60 ++m_count; |
61 | 61 |
62 sv_id_t id = Event::getId(p); | |
63 | |
62 if (p.hasDuration()) { | 64 if (p.hasDuration()) { |
63 | 65 |
64 const sv_frame_t frame = p.getFrame(); | 66 const sv_frame_t frame = p.getFrame(); |
65 const sv_frame_t endFrame = p.getFrame() + p.getDuration(); | 67 const sv_frame_t endFrame = p.getFrame() + p.getDuration(); |
66 | 68 |
76 SVCERR << "ERROR: EventSeries::add: " | 78 SVCERR << "ERROR: EventSeries::add: " |
77 << "reached end of seam map" | 79 << "reached end of seam map" |
78 << endl; | 80 << endl; |
79 break; | 81 break; |
80 } | 82 } |
81 i->second.insert(p); | 83 /* bool found = false; |
84 for (auto eid: i->second) { | |
85 if (eid == id) { | |
86 found = true; | |
87 break; | |
88 } | |
89 } | |
90 if (!found) {*/ | |
91 i->second.push_back(id); | |
92 // } | |
82 } | 93 } |
83 } | 94 } |
84 | 95 |
85 #ifdef DEBUG_EVENT_SERIES | 96 #ifdef DEBUG_EVENT_SERIES |
86 std::cerr << "after add:" << std::endl; | 97 std::cerr << "after add:" << std::endl; |
105 m_events.erase(pitr); | 116 m_events.erase(pitr); |
106 } | 117 } |
107 --m_count; | 118 --m_count; |
108 } | 119 } |
109 | 120 |
121 sv_id_t id = Event::getId(p); | |
122 | |
110 if (p.hasDuration() && isUnique) { | 123 if (p.hasDuration() && isUnique) { |
111 | 124 |
112 const sv_frame_t frame = p.getFrame(); | 125 const sv_frame_t frame = p.getFrame(); |
113 const sv_frame_t endFrame = p.getFrame() + p.getDuration(); | 126 const sv_frame_t endFrame = p.getFrame() + p.getDuration(); |
114 | 127 |
129 if (i == m_seams.end()) { | 142 if (i == m_seams.end()) { |
130 // This can happen only if we have a negative | 143 // This can happen only if we have a negative |
131 // duration, which Event forbids | 144 // duration, which Event forbids |
132 throw std::logic_error("unexpectedly reached end of map"); | 145 throw std::logic_error("unexpectedly reached end of map"); |
133 } | 146 } |
134 | 147 for (size_t j = 0; j < i->second.size(); ) { |
135 i->second.erase(p); | 148 if (i->second[j] == id) { |
149 i->second.erase(i->second.begin() + j); | |
150 } else { | |
151 ++j; | |
152 } | |
153 } | |
136 } | 154 } |
137 | 155 |
138 // Tidy up by removing any entries that are now identical | 156 // Tidy up by removing any entries that are now identical |
139 // to their predecessors | 157 // to their predecessors |
140 | 158 |
159 //!!! won't work as vector is not consistently ordered | |
160 | |
141 std::vector<sv_frame_t> redundant; | 161 std::vector<sv_frame_t> redundant; |
142 | 162 |
143 auto pitr = m_seams.end(); | 163 auto pitr = m_seams.end(); |
144 if (i0 != m_seams.begin()) { | 164 if (i0 != m_seams.begin()) { |
145 pitr = i0; | 165 pitr = i0; |
230 if (sitr != m_seams.begin()) { | 250 if (sitr != m_seams.begin()) { |
231 --sitr; | 251 --sitr; |
232 } | 252 } |
233 } | 253 } |
234 while (sitr != m_seams.end() && sitr->first < end) { | 254 while (sitr != m_seams.end() && sitr->first < end) { |
235 for (const auto &p: sitr->second) { | 255 for (const auto &id: sitr->second) { |
236 found.insert(p); | 256 found.insert(Event::getEventForId(id)); |
237 } | 257 } |
238 ++sitr; | 258 ++sitr; |
239 } | 259 } |
240 for (const auto &p: found) { | 260 for (const auto &p: found) { |
241 int n = m_events.at(p); | 261 int n = m_events.at(p); |
272 ++pitr; | 292 ++pitr; |
273 } | 293 } |
274 | 294 |
275 // now any non-zero-duration ones from the seam map | 295 // now any non-zero-duration ones from the seam map |
276 | 296 |
297 std::set<Event> found; | |
277 auto sitr = m_seams.lower_bound(frame); | 298 auto sitr = m_seams.lower_bound(frame); |
278 if (sitr == m_seams.end() || sitr->first > frame) { | 299 if (sitr == m_seams.end() || sitr->first > frame) { |
279 if (sitr != m_seams.begin()) { | 300 if (sitr != m_seams.begin()) { |
280 --sitr; | 301 --sitr; |
281 } | 302 } |
282 } | 303 } |
283 if (sitr != m_seams.end() && sitr->first <= frame) { | 304 if (sitr != m_seams.end() && sitr->first <= frame) { |
284 for (const auto &p: sitr->second) { | 305 for (const auto &id: sitr->second) { |
285 int n = m_events.at(p); | 306 found.insert(Event::getEventForId(id)); |
286 if (n < 1) { | 307 } |
287 throw std::logic_error("event is in seams but not events"); | 308 ++sitr; |
288 } | 309 } |
289 for (int i = 0; i < n; ++i) { | 310 for (const auto &p: found) { |
290 cover.push_back(p); | 311 int n = m_events.at(p); |
291 } | 312 if (n < 1) { |
313 throw std::logic_error("event is in seams but not events"); | |
314 } | |
315 for (int i = 0; i < n; ++i) { | |
316 cover.push_back(p); | |
292 } | 317 } |
293 } | 318 } |
294 | 319 |
295 return cover; | 320 return cover; |
296 } | 321 } |
329 * onward and disappearing again at its end frame. | 354 * onward and disappearing again at its end frame. |
330 * | 355 * |
331 * Only events with duration appear in this map; point events | 356 * Only events with duration appear in this map; point events |
332 * appear only in m_events. | 357 * appear only in m_events. |
333 */ | 358 */ |
334 typedef std::map<sv_frame_t, std::set<Event>> FrameEventMap; | 359 typedef std::map<sv_frame_t, std::vector<sv_id_t>> FrameEventMap; |
335 FrameEventMap m_seams; | 360 FrameEventMap m_seams; |
336 | 361 |
337 /** Create a seam at the given frame, copying from the prior seam | 362 /** Create a seam at the given frame, copying from the prior seam |
338 * if there is one. If a seam already exists at the given frame, | 363 * if there is one. If a seam already exists at the given frame, |
339 * leave it untouched. | 364 * leave it untouched. |