From: Matthew Poremba Date: Tue, 28 Apr 2020 23:12:23 +0000 (-0700) Subject: mem-ruby: Allow MachineID to be unordered key X-Git-Tag: v20.1.0.0~606 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bbb6a3fe8d787d4426060dfa29560ed8edf13a81;p=gem5.git 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 --- 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);