mem-ruby: Allow MachineID to be unordered key
authorMatthew Poremba <matthew.poremba@amd.com>
Tue, 28 Apr 2020 23:12:23 +0000 (16:12 -0700)
committerMatthew Poremba <matthew.poremba@amd.com>
Mon, 8 Jun 2020 16:39:21 +0000 (16:39 +0000)
Define an std::hash function so that MachineID may be used as a key
type for unordered STL containers.

Change-Id: Ibc3bc78149c69683207d8967542fa6e8d545f75c
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/29652
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/mem/ruby/common/MachineID.hh

index 64082d79c3d621c3cb3eacf49c6f18230926e477..3ef7b8876ed03e6b55750971054b32b6e37f552b 100644 (file)
@@ -67,6 +67,16 @@ operator!=(const MachineID & obj1, const MachineID & obj2)
     return (obj1.type != obj2.type || obj1.num != obj2.num);
 }
 
+namespace std {
+    template<>
+    struct hash<MachineID> {
+        inline size_t operator()(const MachineID& id) const {
+            size_t hval = MachineType_base_level(id.type) << 16 | id.num;
+            return hval;
+        }
+    };
+}
+
 // Output operator declaration
 std::ostream& operator<<(std::ostream& out, const MachineID& obj);