[llvm-commits] [PATCH 01/20] Add DenseMapInfo for std::string
David Greene
dag at cray.com
Tue Jul 19 13:11:36 PDT 2011
Add a DenseMapInfo implementation for std::string. This is useful
when mapping pairs that include a string component.
---
include/llvm/ADT/StringExtras.h | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
diff --git oldinclude/llvm/ADT/StringExtras.h newinclude/llvm/ADT/StringExtras.h
index 5f5c041..d30e225 100644
--- oldinclude/llvm/ADT/StringExtras.h
+++ newinclude/llvm/ADT/StringExtras.h
@@ -16,6 +16,7 @@
#include "llvm/Support/DataTypes.h"
#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/StringRef.h"
#include <cctype>
#include <cstdio>
@@ -165,6 +166,24 @@ static inline unsigned HashString(StringRef Str, unsigned Result = 0) {
return Result;
}
+// Provide DenseMapInfo for strings.
+template<> struct DenseMapInfo<std::string> {
+ static inline std::string getEmptyKey() {
+ std::string Empty("<<<EMPTY KEY>>>");
+ return Empty;
+ }
+ static inline std::string getTombstoneKey() {
+ std::string Tombstone("<<<TOMBSTONE KEY>>>");
+ return Tombstone;
+ }
+ static unsigned getHashValue(const std::string& Val) {
+ return HashString(Val);
+ }
+ static bool isEqual(const std::string& LHS, const std::string& RHS) {
+ return LHS == RHS;
+ }
+};
+
} // End llvm namespace
#endif
--
1.7.6
More information about the llvm-commits
mailing list