comparison base/Event.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 676e32fa403e
children 1c21ddac220e
comparison
equal deleted inserted replaced
1625:7dbb2a7b592e 1626:895186c43fce
277 h ^= qHash(m_frame); 277 h ^= qHash(m_frame);
278 h ^= qHash(m_duration); 278 h ^= qHash(m_duration);
279 if (m_haveReferenceFrame) h ^= qHash(m_referenceFrame); 279 if (m_haveReferenceFrame) h ^= qHash(m_referenceFrame);
280 return h; 280 return h;
281 } 281 }
282
283 static sv_id_t getId(const Event &ev) {
284 sv_id_t id;
285 if (!m_ids.contains(ev)) {
286 id = m_nextId;
287 ++m_nextId;
288 m_ids[ev] = id;
289 m_rids[id] = ev;
290 return id;
291 } else {
292 return m_ids.value(ev);
293 }
294 }
295
296 static Event getEventForId(sv_id_t id) {
297 if (!m_rids.contains(id)) {
298 throw std::runtime_error("unknown event id");
299 } else {
300 return m_rids.value(id);
301 }
302 }
282 303
283 private: 304 private:
284 // The order of fields here is chosen to minimise overall size of struct. 305 // The order of fields here is chosen to minimise overall size of struct.
285 // We potentially store very many of these objects. 306 // We potentially store very many of these objects.
286 // If you change something, check what difference it makes to packing. 307 // If you change something, check what difference it makes to packing.
291 float m_level; 312 float m_level;
292 sv_frame_t m_frame; 313 sv_frame_t m_frame;
293 sv_frame_t m_duration; 314 sv_frame_t m_duration;
294 sv_frame_t m_referenceFrame; 315 sv_frame_t m_referenceFrame;
295 QString m_label; 316 QString m_label;
317
318 static sv_id_t m_nextId;
319 static QHash<Event, sv_id_t> m_ids;
320 static QHash<sv_id_t, Event> m_rids;
296 }; 321 };
297 322
298 inline uint qHash(const Event &e, uint seed = 0) { 323 inline uint qHash(const Event &e, uint seed = 0) {
299 return e.hash(seed); 324 return e.hash(seed);
300 } 325 }