[llvm] r297552 - [ADT] Add a DenseMapInfo<T> for shorts.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 10 18:52:48 PST 2017


Author: zturner
Date: Fri Mar 10 20:52:48 2017
New Revision: 297552

URL: http://llvm.org/viewvc/llvm-project?rev=297552&view=rev
Log:
[ADT] Add a DenseMapInfo<T> for shorts.

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

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=297552&r1=297551&r2=297552&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/DenseMapInfo.h (original)
+++ llvm/trunk/include/llvm/ADT/DenseMapInfo.h Fri Mar 10 20:52:48 2017
@@ -60,6 +60,16 @@ template<> struct DenseMapInfo<char> {
   }
 };
 
+// Provide DenseMapInfo for unsigned shorts.
+template <> struct DenseMapInfo<unsigned short> {
+  static inline unsigned short getEmptyKey() { return 0xFFFF; }
+  static inline unsigned short getTombstoneKey() { return 0xFFFF - 1; }
+  static unsigned getHashValue(const unsigned short &Val) { return Val * 37U; }
+  static bool isEqual(const unsigned short &LHS, const unsigned short &RHS) {
+    return LHS == RHS;
+  }
+};
+
 // Provide DenseMapInfo for unsigned ints.
 template<> struct DenseMapInfo<unsigned> {
   static inline unsigned getEmptyKey() { return ~0U; }
@@ -95,6 +105,14 @@ template<> struct DenseMapInfo<unsigned
   }
 };
 
+// Provide DenseMapInfo for shorts.
+template <> struct DenseMapInfo<short> {
+  static inline short getEmptyKey() { return 0x7FFF; }
+  static inline short getTombstoneKey() { return -0x7FFF - 1; }
+  static unsigned getHashValue(const short &Val) { return Val * 37U; }
+  static bool isEqual(const short &LHS, const short &RHS) { return LHS == RHS; }
+};
+
 // Provide DenseMapInfo for ints.
 template<> struct DenseMapInfo<int> {
   static inline int getEmptyKey() { return 0x7fffffff; }




More information about the llvm-commits mailing list