From bbb6a3fe8d787d4426060dfa29560ed8edf13a81 Mon Sep 17 00:00:00 2001 From: Matthew Poremba Date: Tue, 28 Apr 2020 16:12:23 -0700 Subject: [PATCH] mem-ruby: Allow MachineID to be unordered key 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 Reviewed-by: Bobby R. Bruce Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/mem/ruby/common/MachineID.hh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mem/ruby/common/MachineID.hh b/src/mem/ruby/common/MachineID.hh index 64082d79c..3ef7b8876 100644 --- a/src/mem/ruby/common/MachineID.hh +++ b/src/mem/ruby/common/MachineID.hh @@ -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 { + 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); -- 2.30.2