diff 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
line wrap: on
line diff
--- a/base/Event.h	Mon Mar 11 11:25:17 2019 +0000
+++ b/base/Event.h	Mon Mar 11 13:44:35 2019 +0000
@@ -279,6 +279,27 @@
         if (m_haveReferenceFrame) h ^= qHash(m_referenceFrame);
         return h;
     }
+
+    static sv_id_t getId(const Event &ev) {
+        sv_id_t id;
+        if (!m_ids.contains(ev)) {
+            id = m_nextId;
+            ++m_nextId;
+            m_ids[ev] = id;
+            m_rids[id] = ev;
+            return id;
+        } else {
+            return m_ids.value(ev);
+        }
+    }
+
+    static Event getEventForId(sv_id_t id) {
+        if (!m_rids.contains(id)) {
+            throw std::runtime_error("unknown event id");
+        } else {
+            return m_rids.value(id);
+        }
+    }
     
 private:
     // The order of fields here is chosen to minimise overall size of struct.
@@ -293,6 +314,10 @@
     sv_frame_t m_duration;
     sv_frame_t m_referenceFrame;
     QString m_label;
+
+    static sv_id_t m_nextId;
+    static QHash<Event, sv_id_t> m_ids;
+    static QHash<sv_id_t, Event> m_rids;
 };
 
 inline uint qHash(const Event &e, uint seed = 0) {