Commit 8fa2ee05 by Ben Clayton

Vulkan/Debug: Support Locations as hashmap keys

Implement `operator<()`, `std::hash<>` Bug: b/145351270 Change-Id: I9ebcfccd3a1da36dc9286f6ed6d50c73c8c3bac3 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/48698 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent ac160bd3
...@@ -30,6 +30,7 @@ struct Location ...@@ -30,6 +30,7 @@ struct Location
inline bool operator==(const Location &o) const; inline bool operator==(const Location &o) const;
inline bool operator!=(const Location &o) const; inline bool operator!=(const Location &o) const;
inline bool operator<(const Location &o) const;
std::shared_ptr<File> file; std::shared_ptr<File> file;
int line = 0; // 1 based. 0 represents no line. int line = 0; // 1 based. 0 represents no line.
...@@ -52,7 +53,37 @@ bool Location::operator!=(const Location &o) const ...@@ -52,7 +53,37 @@ bool Location::operator!=(const Location &o) const
return !(*this == o); return !(*this == o);
} }
bool Location::operator<(const Location &o) const
{
if(file.get() < o.file.get()) { return true; }
if(file.get() > o.file.get()) { return false; }
if(line < o.line) { return true; }
if(line > o.line) { return false; }
if(column < o.column) { return true; }
if(column > o.column) { return false; }
return true;
}
} // namespace dbg } // namespace dbg
} // namespace vk } // namespace vk
#endif // VK_DEBUG_LOCATION_HPP_ namespace std {
\ No newline at end of file
template<>
struct hash<vk::dbg::Location>
{
size_t operator()(const vk::dbg::Location &l) const
{
auto h = std::hash<vk::dbg::File *>()(l.file.get());
h = h * 31 + l.line;
h = h * 31 + l.column;
return h;
}
};
} // namespace std
#endif // VK_DEBUG_LOCATION_HPP_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment