[PATCH] D48361: [ADT] Allow llvm::hash_code as DenseMap key.

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 20 04:49:38 PDT 2018


sammccall created this revision.
sammccall added a reviewer: ioeric.
Herald added subscribers: llvm-commits, ilya-biryukov.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D48361

Files:
  include/llvm/ADT/DenseMapInfo.h


Index: include/llvm/ADT/DenseMapInfo.h
===================================================================
--- include/llvm/ADT/DenseMapInfo.h
+++ include/llvm/ADT/DenseMapInfo.h
@@ -262,6 +262,13 @@
   }
 };
 
+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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48361.152059.patch
Type: text/x-patch
Size: 602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180620/56b32d8c/attachment.bin>


More information about the llvm-commits mailing list