[llvm] r335125 - [ADT] Allow llvm::hash_code as DenseMap key.

Sam McCall via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 20 06:56:25 PDT 2018


Author: sammccall
Date: Wed Jun 20 06:56:25 2018
New Revision: 335125

URL: http://llvm.org/viewvc/llvm-project?rev=335125&view=rev
Log:
[ADT] Allow llvm::hash_code as DenseMap key.

Summary:
This is useful when hash collisions are unlikely and acceptable, e.g. in clangd
completion ranking.

Reviewers: ioeric

Subscribers: ilya-biryukov, llvm-commits

Differential Revision: https://reviews.llvm.org/D48361

Modified:
    llvm/trunk/include/llvm/ADT/DenseMapInfo.h

Modified: llvm/trunk/include/llvm/ADT/DenseMapInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/DenseMapInfo.h?rev=335125&r1=335124&r2=335125&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/DenseMapInfo.h (original)
+++ llvm/trunk/include/llvm/ADT/DenseMapInfo.h Wed Jun 20 06:56:25 2018
@@ -262,6 +262,13 @@ template <typename T> struct DenseMapInf
   }
 };
 
+template <> struct DenseMapInfo<hash_code> {
+  static inline hash_code getEmptyKey() { return hash_code(-1); }
+  static inline hash_code getTombstoneKey() { return hash_code(-2); }
+  static unsigned getHashValue(hash_code val) { return val; }
+  static bool isEqual(hash_code LHS, hash_code RHS) { return LHS == RHS; }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_ADT_DENSEMAPINFO_H




More information about the llvm-commits mailing list