aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/lib/hash
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2016-10-27 08:10:54 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-10-27 09:21:12 -0700
commit80aec93166dadb2dc30250e1251ab3eb006c2d53 (patch)
treec34632f2f255eda56214559ff7d7d54878a6a6c9 /tensorflow/core/lib/hash
parente43eaf662db492c909e6cab8c954178b75f7b63d (diff)
Added new tensorflow::gtl::FlatMap and tensorflow::gtl::FlatSet classes.
Mostly drop-in replacements for std::unordered_map and std::unordered_set, but much faster (does not do an allocation per entry, and represents entries in groups of 8 in a flat array, which is much more cache efficient). Benchmarks not included in this cl show about 3X to 5X performance improvements over the std::unordered_{set,map} for many kinds of common maps e.g. std::unordered_mapmap<int64, int64> or std::unordered_map<string, int64>. Change: 137401863
Diffstat (limited to 'tensorflow/core/lib/hash')
-rw-r--r--tensorflow/core/lib/hash/hash.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/tensorflow/core/lib/hash/hash.h b/tensorflow/core/lib/hash/hash.h
index 3c71e7d6cc..4e64c90d62 100644
--- a/tensorflow/core/lib/hash/hash.h
+++ b/tensorflow/core/lib/hash/hash.h
@@ -42,6 +42,24 @@ inline uint64 Hash64Combine(uint64 a, uint64 b) {
return a ^ (b + 0x9e3779b97f4a7800ULL + (a << 10) + (a >> 4));
}
+// Convenience Hash functors
+struct HashInt64 {
+ size_t operator()(int64 x) const { return static_cast<size_t>(x); }
+};
+struct HashStr {
+ size_t operator()(const string& s) const {
+ return static_cast<size_t>(Hash64(s));
+ }
+};
+template <typename PTR>
+struct HashPtr {
+ size_t operator()(const PTR p) const {
+ // Hash pointers as integers, but bring more entropy to the lower bits.
+ size_t k = static_cast<size_t>(reinterpret_cast<uintptr_t>(p));
+ return k + (k >> 6);
+ }
+};
+
} // namespace tensorflow
#endif // TENSORFLOW_LIB_HASH_HASH_H_