]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
report_manager: more use of unordered_map
authorJustin Viiret <justin.viiret@intel.com>
Mon, 24 Apr 2017 04:58:20 +0000 (14:58 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 30 May 2017 03:58:32 +0000 (13:58 +1000)
src/util/report.h
src/util/report_manager.cpp
src/util/report_manager.h

index 24ecca9d417751457c8769137882f0aff9441419..a8e233ffd801f871725ff55f49ab7ef1e1794b6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
 #ifndef UTIL_REPORT_H
 #define UTIL_REPORT_H
 
-#include "util/exhaust.h" // for INVALID_EKEY
-#include "order_check.h"
 #include "ue2common.h"
+#include "util/exhaust.h" // for INVALID_EKEY
+#include "util/hash.h"
+#include "util/order_check.h"
 
 #include <cassert>
 
@@ -195,6 +196,23 @@ bool operator<(const Report &a, const Report &b) {
     return false;
 }
 
+inline
+bool operator==(const Report &a, const Report &b) {
+    return a.type == b.type && a.quashSom == b.quashSom &&
+           a.minOffset == b.minOffset && a.maxOffset == b.maxOffset &&
+           a.minLength == b.minLength && a.ekey == b.ekey &&
+           a.offsetAdjust == b.offsetAdjust && a.onmatch == b.onmatch &&
+           a.revNfaIndex == b.revNfaIndex && a.somDistance == b.somDistance &&
+           a.topSquashDistance == b.topSquashDistance;
+}
+
+inline
+size_t hash_value(const Report &r) {
+    return hash_all(r.type, r.quashSom, r.minOffset, r.maxOffset, r.minLength,
+                    r.ekey, r.offsetAdjust, r.onmatch, r.revNfaIndex,
+                    r.somDistance, r.topSquashDistance);
+}
+
 static inline
 Report makeECallback(u32 report, s32 offsetAdjust, u32 ekey) {
     Report ir(EXTERNAL_CALLBACK, report);
index 6f6bd0e8af64a90aaa701f16bed55271dd9e1ef9..a846eb25e5396a0dcbcf093f4f89b91ee1f17b4f 100644 (file)
@@ -67,7 +67,7 @@ u32 ReportManager::getInternalId(const Report &ir) {
 
     u32 size = reportIds.size();
     reportIds.push_back(ir);
-    reportIdToInternalMap[ir] = size;
+    reportIdToInternalMap.emplace(ir, size);
     DEBUG_PRINTF("new report %u\n", size);
     return size;
 }
index 3fcad3303fdd850096f174a5a4a46b16b4c5f731..95e14a2c33ce725a343fb5c8495a3c8683128959 100644 (file)
@@ -130,14 +130,14 @@ private:
     std::vector<Report> reportIds;
 
     /** \brief Mapping from Report to ID (inverse of \ref reportIds
-     * vector).  */
-    std::map<Report, size_t> reportIdToInternalMap;
+     * vector). */
+    unordered_map<Report, size_t> reportIdToInternalMap;
 
     /** \brief Mapping from ReportID to dedupe key. */
-    std::map<ReportID, u32> reportIdToDedupeKey;
+    unordered_map<ReportID, u32> reportIdToDedupeKey;
 
     /** \brief Mapping from ReportID to Rose program offset in bytecode. */
-    std::map<ReportID, u32> reportIdToProgramOffset;
+    unordered_map<ReportID, u32> reportIdToProgramOffset;
 
     /** \brief Mapping from external match ids to information about that
      * id. */