[neurun] Specialize `std::hash` for Index class (#2585)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Wed, 5 Sep 2018 01:02:28 +0000 (10:02 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 5 Sep 2018 01:02:28 +0000 (10:02 +0900)
(partially) Specialize `std::hash` for `graph::Index` class.
This will enable having Index as the key in "std::unordered_.."
containers.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/graph/Index.h

index ac601dc..2f4cb18 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __NEURUN_GRAPH_INDEX_H__
 #define __NEURUN_GRAPH_INDEX_H__
 
+#include <functional>
 #include <stdint.h>
 
 namespace neurun
@@ -42,4 +43,17 @@ private:
 } // namespace graph
 } // namespace neurun
 
+namespace std
+{
+
+template <typename T, typename Tag> struct hash<::neurun::graph::Index<T, Tag>>
+{
+  size_t operator()(const ::neurun::graph::Index<T, Tag> &index) const noexcept
+  {
+    return hash<T>()(index.value());
+  }
+};
+
+} // namespace std
+
 #endif // __NEURUN_GRAPH_INDEX_H__